diff --git a/.github/workflows/build-desktop.yml b/.github/workflows/build-desktop.yml index 2a59dc28fc9c..1c821d3604b5 100644 --- a/.github/workflows/build-desktop.yml +++ b/.github/workflows/build-desktop.yml @@ -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 + - 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 diff --git a/apps/desktop/desktop_native/build.js b/apps/desktop/desktop_native/build.js index f2f012bf0880..c8d8636c4340 100644 --- a/apps/desktop/desktop_native/build.js +++ b/apps/desktop/desktop_native/build.js @@ -1,28 +1,38 @@ -/* 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] @@ -30,39 +40,43 @@ if (!crossPlatform) { // 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}`), + ); });