-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Build desktop-native in alpine container #12499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
0f3adf4
4dee450
445c85e
fc9264d
bf5308e
06c9cf5
abc9214
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -138,6 +138,42 @@ jobs: | |
| NODE_VERSION=${NODE_NVMRC/v/''} | ||
| echo "node_version=$NODE_VERSION" >> $GITHUB_OUTPUT | ||
|
|
||
| linux-desktop-native: | ||
| name: Desktop Native Linux Build | ||
| runs-on: ubuntu-24.04 | ||
| container: | ||
| image: alpine:3.20 | ||
| needs: setup | ||
| defaults: | ||
| run: | ||
| needs: linux-desktop-native | ||
| steps: | ||
| - name: Check out repo | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
| - name: Set up environment | ||
| run: | | ||
| apk add --no-cache \ | ||
| build-base \ | ||
| rustup \ | ||
| npm | ||
| echo 1 | rustup-init --default-toolchain stable --target x86_64-unknown-linux-musl | ||
| - name: NPM install | ||
| run: cd ../../../ && npm install | ||
| - name: Build Native Module | ||
| env: | ||
| PKG_CONFIG_ALL_STATIC: true | ||
| TARGET: musl | ||
| run: | | ||
| source $HOME/.cargo/env | ||
| node build.js release | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is using the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had added support, but it got lost when moving the changes from my testing branch on my personal repo to this; will re-add :) |
||
| - name: Upload Native Module | ||
| uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 | ||
| with: | ||
| name: desktop_napi-linux-x86_64-unknown-linux-musl | ||
| path: apps/desktop/desktop_native/napi/desktop_napi.linux-x64-musl.node | ||
|
|
||
| linux: | ||
| name: Linux Build | ||
| # Note, before updating the ubuntu version of the workflow, ensure the snap base image | ||
|
|
@@ -206,27 +242,11 @@ jobs: | |
| ls -l ../ | ||
| npm link ../sdk-internal | ||
|
|
||
| - name: Cache Native Module | ||
| uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2 | ||
| id: cache | ||
| - name: Download napi module | ||
| uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 | ||
| with: | ||
| path: | | ||
| apps/desktop/desktop_native/napi/*.node | ||
| apps/desktop/desktop_native/dist/* | ||
| ${{ env.RUNNER_TEMP }}/.cargo/registry | ||
| ${{ env.RUNNER_TEMP }}/.cargo/git | ||
| key: rust-${{ runner.os }}-${{ hashFiles('apps/desktop/desktop_native/**/*') }} | ||
|
|
||
| - name: Build Native Module | ||
| if: steps.cache.outputs.cache-hit != 'true' | ||
| working-directory: apps/desktop/desktop_native | ||
| env: | ||
| PKG_CONFIG_ALLOW_CROSS: true | ||
| PKG_CONFIG_ALL_STATIC: true | ||
| TARGET: musl | ||
| run: | | ||
| rustup target add x86_64-unknown-linux-musl | ||
| node build.js cross-platform | ||
| name: desktop_napi-linux-x86_64-unknown-linux-musl | ||
| path: apps/desktop/desktop_native/napi/desktop_napi.linux-x64-musl.node | ||
|
|
||
| - name: Build application | ||
| run: npm run dist:lin | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,68 +1,82 @@ | ||
| /* eslint-disable @typescript-eslint/no-var-requires */ | ||
| const child_process = require("child_process"); | ||
| const fs = require("fs"); | ||
| const path = require("path"); | ||
| const process = require("process"); | ||
|
|
||
| let crossPlatform = process.argv.length > 2 && process.argv[2] === "cross-platform"; | ||
| // contains | ||
| let crossPlatform = "cross-platform" in process.argv; | ||
| let release = "release" in process.argv; | ||
| if (crossPlatform) { | ||
| release = true; | ||
| } | ||
|
|
||
| function buildNapiModule(target, release = true) { | ||
| const targetArg = target ? `--target ${target}` : ""; | ||
| const releaseArg = release ? "--release" : ""; | ||
| return child_process.execSync(`npm run build -- ${releaseArg} ${targetArg}`, { stdio: 'inherit', cwd: path.join(__dirname, "napi") }); | ||
| function buildNapiModule(target, release) { | ||
| const targetArg = target ? `--target ${target}` : ""; | ||
| const releaseArg = release ? "--release" : ""; | ||
| return child_process.execSync(`npm run build -- ${releaseArg} ${targetArg}`, { | ||
| stdio: "inherit", | ||
| cwd: path.join(__dirname, "napi"), | ||
| }); | ||
| } | ||
|
|
||
| function buildProxyBin(target, release = true) { | ||
| const targetArg = target ? `--target ${target}` : ""; | ||
| const releaseArg = release ? "--release" : ""; | ||
| return child_process.execSync(`cargo build --bin desktop_proxy ${releaseArg} ${targetArg}`, {stdio: 'inherit', cwd: path.join(__dirname, "proxy")}); | ||
| function buildProxyBin(target, release) { | ||
| const targetArg = target ? `--target ${target}` : ""; | ||
| const releaseArg = release ? "--release" : ""; | ||
| return child_process.execSync(`cargo build --bin desktop_proxy ${releaseArg} ${targetArg}`, { | ||
| stdio: "inherit", | ||
| cwd: path.join(__dirname, "proxy"), | ||
| }); | ||
| } | ||
|
|
||
| if (!crossPlatform) { | ||
| console.log("Building native modules in debug mode for the native architecture"); | ||
| buildNapiModule(false, false); | ||
| buildProxyBin(false, false); | ||
| return; | ||
| console.log("Building native modules in debug mode for the native architecture"); | ||
| buildNapiModule(false, release); | ||
| buildProxyBin(false, release); | ||
| return; | ||
| } | ||
|
|
||
| // Note that targets contains pairs of [rust target, node arch] | ||
| // We do this to move the output binaries to a location that can | ||
| // be easily accessed from electron-builder using ${os} and ${arch} | ||
| let targets = []; | ||
| switch (process.platform) { | ||
| case "win32": | ||
| targets = [ | ||
| ["i686-pc-windows-msvc", 'ia32'], | ||
| ["x86_64-pc-windows-msvc", 'x64'], | ||
| ["aarch64-pc-windows-msvc", 'arm64'] | ||
| ]; | ||
| case "win32": | ||
| targets = [ | ||
| ["i686-pc-windows-msvc", "ia32"], | ||
| ["x86_64-pc-windows-msvc", "x64"], | ||
| ["aarch64-pc-windows-msvc", "arm64"], | ||
| ]; | ||
| break; | ||
|
|
||
| case "darwin": | ||
| targets = [ | ||
| ["x86_64-apple-darwin", 'x64'], | ||
| ["aarch64-apple-darwin", 'arm64'] | ||
| ]; | ||
| case "darwin": | ||
| targets = [ | ||
| ["x86_64-apple-darwin", "x64"], | ||
| ["aarch64-apple-darwin", "arm64"], | ||
| ]; | ||
| break; | ||
|
|
||
| default: | ||
| targets = [ | ||
| ['x86_64-unknown-linux-musl', 'x64'] | ||
| ]; | ||
| default: | ||
| targets = [["x86_64-unknown-linux-musl", "x64"]]; | ||
|
|
||
| process.env["PKG_CONFIG_ALLOW_CROSS"] = "1"; | ||
| process.env["PKG_CONFIG_ALL_STATIC"] = "1"; | ||
| process.env["PKG_CONFIG_ALLOW_CROSS"] = "1"; | ||
| process.env["PKG_CONFIG_ALL_STATIC"] = "1"; | ||
| break; | ||
| } | ||
|
|
||
| console.log("Cross building native modules for the targets: ", targets.map(([target, _]) => target).join(", ")); | ||
| console.log( | ||
| "Cross building native modules for the targets: ", | ||
| targets.map(([target, _]) => target).join(", "), | ||
| ); | ||
|
|
||
| fs.mkdirSync(path.join(__dirname, "dist"), { recursive: true }); | ||
|
|
||
| targets.forEach(([target, nodeArch]) => { | ||
| buildNapiModule(target); | ||
| buildProxyBin(target); | ||
| buildNapiModule(target, release); | ||
| buildProxyBin(target, release); | ||
|
|
||
| const ext = process.platform === "win32" ? ".exe" : ""; | ||
| fs.copyFileSync(path.join(__dirname, "target", target, "release", `desktop_proxy${ext}`), path.join(__dirname, "dist", `desktop_proxy.${process.platform}-${nodeArch}${ext}`)); | ||
| const ext = process.platform === "win32" ? ".exe" : ""; | ||
| fs.copyFileSync( | ||
| path.join(__dirname, "target", target, "release", `desktop_proxy${ext}`), | ||
| path.join(__dirname, "dist", `desktop_proxy.${process.platform}-${nodeArch}${ext}`), | ||
| ); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed this new job doesn't have a cache step, do we know how long it takes to build? Not sure if it was needed before, but I'd rather not accidentally make the builds any slower hah
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
~4 minutes https://github.com/quexten/clients/actions/runs/12430521534/job/34706128211
So adding cache is worth it.