Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 40 additions & 20 deletions .github/workflows/build-desktop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,42 @@ jobs:
NODE_VERSION=${NODE_NVMRC/v/''}
echo "node_version=$NODE_VERSION" >> $GITHUB_OUTPUT

linux-desktop-native:
Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is using the build.js script in desktop_native, it doesn't have a release argument. It will ignore it and build on debug mode unless you pass the cross-platform arg. Should be fairly easy to add support for it though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down Expand Up @@ -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
Expand Down
86 changes: 50 additions & 36 deletions apps/desktop/desktop_native/build.js
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}`),
);
});