[PM-38767] Address review: drop duplicate cargo-xwin build, last toolchain literal

cargoBuild() now dispatches `cargo xwin build ...` instead of `cargo bin
cargo-xwin build ...`. installTarget() already installs the version pinned in
[workspace.metadata.bin] globally, because the napi CLI spawns `cargo xwin`
itself and we can't redirect that, so the `cargo bin` route was building a second
copy of the same pinned version for no extra guarantee. It also removes a
security wrinkle: `cargo install --version --locked` is source-only, whereas
`cargo bin` falls through to cargo-binstall's prebuilt binaries when binstall is
on PATH (VULN-613).

test.yml no longer hardcodes `toolchain: 1.96.0`; it resolves from
rust-toolchain.toml like lint.yml, so that was the last place a stale literal
could survive a Renovate bump.

lint-rust.mjs now rejects `--only` with no value instead of silently running
every check.

Add root-level `lint:rust` / `lint:rust:fix` aliases: the runner lives in the
repo root's scripts/ and CI invokes it from there, so requiring a cd into
apps/desktop was surprising.

Verified by cross-compiling for real on macOS through the new dispatch form:
  cargo xwin build --bin desktop_proxy --target=x86_64-pc-windows-msvc
produces a PE32+ MS Windows executable.
This commit is contained in:
Andreas Coroiu
2026-08-05 14:56:01 +02:00
parent 53360f7c95
commit 11b9a8e090
4 changed files with 38 additions and 13 deletions

View File

@@ -229,10 +229,19 @@ jobs:
with:
persist-credentials: false
# Resolved from desktop_native/rust-toolchain.toml, the single source of
# truth, so a Renovate bump can't leave a stale literal here. Assigned before
# echoing so a failure in the reader fails the step; see lint.yml.
- name: Resolve Rust toolchain
id: toolchain
run: |
RUST_TOOLCHAIN="$(node scripts/rust-toolchain.mjs)"
echo "RUST_TOOLCHAIN=${RUST_TOOLCHAIN}" | tee -a "${GITHUB_OUTPUT}"
- name: Install rust
uses: dtolnay/rust-toolchain@4cda84d5c5c54efe2404f9d843567869ab1699d4 # stable
with:
toolchain: 1.96.0
toolchain: ${{ steps.toolchain.outputs.RUST_TOOLCHAIN }}
components: llvm-tools
- name: Cache cargo registry

View File

@@ -74,14 +74,17 @@ function cargoBuild(bin, target, release) {
const targetArg = target ? `--target=${target}` : "";
const releaseArg = release ? "--release" : "";
const args = ["build", "--bin", bin, releaseArg, targetArg]
// Use cross-compilation helper if necessary. cargo-xwin is pinned in
// Cargo.toml under [workspace.metadata.bin] and run via cargo-run-bin, so
// `cargo xwin build ...` becomes `cargo bin cargo-xwin build ...`: the `xwin`
// cargo-subcommand token is omitted because cargo-run-bin supplies it itself.
// Passing it explicitly yields `xwin xwin` and fails with
// "error: unrecognized subcommand 'xwin'".
// Use cross-compilation helper if necessary. Dispatch through cargo rather than
// `cargo bin cargo-xwin`: installTarget() has already installed the version
// pinned in [workspace.metadata.bin] globally, because buildNapiModule() needs
// cargo-xwin on PATH anyway (see the comment there). Reusing it avoids a second
// build of the same pinned version, and `cargo install --version --locked` is
// source-only, which `cargo bin` is not when cargo-binstall is on PATH.
//
// NOTE: this relies on installTarget() running first, which every path that can
// reach a Windows target does (both the `--target=` and `cross-platform` flows).
if (effectivePlatform(target) === "win32" && process.platform !== "win32") {
args.unshift("bin", "cargo-xwin")
args.unshift("xwin")
}
runCommand("cargo", args.filter(s => s != ''))
@@ -142,11 +145,10 @@ function installTarget(target) {
// pinned in Cargo.toml under [workspace.metadata.bin].
if (target.includes('windows') && process.platform !== 'win32') {
runCommand("cargo", ["install", "cargo-run-bin", "--locked", "--version", "1.7.4"]);
// cargoBuild() reaches cargo-xwin through `cargo bin`, but buildNapiModule()
// hands off to the napi CLI, which spawns `cargo xwin` as a PATH
// cargo-subcommand we can't redirect. So cargo-xwin also has to be installed
// globally -- at the same pinned version, read from [workspace.metadata.bin],
// so the two call sites can't drift apart.
// cargo-xwin has to be on PATH: buildNapiModule() hands off to the napi CLI,
// which spawns `cargo xwin` itself, and cargoBuild() dispatches the same way.
// Install the version pinned in [workspace.metadata.bin] so this stays the
// single source of truth for it.
runCommand("cargo", ["install", "--version", pinnedBinVersion("cargo-xwin"), "--locked", "cargo-xwin"]);
// install tools needed for packaging Appx, only supported on macOS for now.
if (process.platform === "darwin") {

View File

@@ -17,6 +17,8 @@
"lint": "eslint . --cache --cache-strategy content && prettier --check .",
"lint:fix": "eslint . --cache --cache-strategy content --fix",
"lint:clear": "rimraf .eslintcache",
"lint:rust": "node scripts/lint-rust.mjs",
"lint:rust:fix": "node scripts/lint-rust.mjs --fix",
"prettier": "prettier --cache --write .",
"test": "jest",
"test:watch": "jest --clearCache && jest --watch",

View File

@@ -38,9 +38,21 @@ for (let i = 0; i < argv.length; i++) {
if (arg === "--fix") {
fix = true;
} else if (arg === "--only") {
// Reject a missing value rather than falling back to "" (which would silently
// run every check when the caller asked for one).
only = argv[++i] ?? "";
if (!only) {
console.error("--only requires a check name");
console.error(`Available: ${CHECKS.join(" ")}`);
process.exit(2);
}
} else if (arg.startsWith("--only=")) {
only = arg.slice("--only=".length);
if (!only) {
console.error("--only requires a check name");
console.error(`Available: ${CHECKS.join(" ")}`);
process.exit(2);
}
} else if (arg === "-h" || arg === "--help") {
printHelp();
process.exit(0);