mirror of
https://github.com/bitwarden/clients.git
synced 2026-11-16 07:03:29 +00:00
* [PM-38767] Adopt cargo-run-bin for binary tool version pinning in desktop_native
Align desktop_native's Rust tooling with bitwarden/sdk-internal.
Pin the desktop_native workspace's binary cargo tools (cargo-deny, cargo-sort,
cargo-udeps, cargo-llvm-cov, cargo-xwin) in [workspace.metadata.bin] and run
them via cargo-run-bin (`cargo bin <tool>`), bootstrapped once with
`cargo install cargo-run-bin --locked`. Replaces the cargo-tool-versions file
and the ad-hoc per-tool `cargo install` calls in CI and build.js. A
check-no-binstall guard enforces source-only installs (VULN-613).
Includes the PM-24643 improvement: a unified lint runner (--fix / --only) that
mirrors CI, exposed as `npm run lint:rust`. The lint.yml rust job is now a
per-check x OS matrix with per-check .bin caching and a stable `Rust lint`
aggregator job.
Pin the nightly toolchain the same way the SDK does, via a non-standard
`nightly-channel` key in rust-toolchain.toml. The shared Renovate preset this
repo already extends (github>bitwarden/renovate-config) matches that key in any
rust-toolchain.toml and updates it from a custom rust-nightly datasource, so no
renovate.json5 change is needed. This closes a real gap rather than a cosmetic
one: rustfmt.toml enables unstable options (wrap_comments, group_imports,
imports_granularity) whose output changes between nightlies, so a rolling local
nightly could format code that CI's pinned nightly then rejects. Both the stable
and nightly toolchains are now read from that one file by CI, prepare-env-rust,
lint-rust and the pre-commit hooks, so a Renovate bump can no longer leave a
stale literal behind in a workflow.
Dev/CI scripts are portable Node rather than the duplicated bash + PowerShell
pair, and rather than the SDK's bash equivalents: our Rust lint matrix includes
macos-14, so the SDK's `grep -oP` toolchain extraction and its Linux-only
component suffix can't be reused.
- scripts/prepare-env-rust.mjs (was prepare-env-unix-rust.sh + -windows-rust.ps1)
- scripts/lint-rust.mjs (the unified runner)
- scripts/check-no-binstall.mjs (binstall guard)
- scripts/rust-toolchain.mjs (reads channel / nightly-channel)
The cargo-deny (0.20.0) and cargo-xwin (0.23.0) bumps that landed on main while
this branch was open are carried into [workspace.metadata.bin].
NOTE: branch protection required-status-check names change with the matrix, from
`Run Rust lint on <os>` (3 checks) to `Rust <check> (<os>)` (15 checks); point
them at the new `Rust lint` aggregator job instead.
* [PM-38767] Keep cargo-xwin on PATH for the napi cross-build
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. Dropping the global `cargo install cargo-xwin` therefore broke
Windows cross-builds from macOS/Linux -- a path CI never exercises, since each
platform builds natively on its own runner.
Reinstate the global install, but read its version from [workspace.metadata.bin]
via a small pinnedBinVersion() helper, so the two call sites share one pin.
Also drop the cargo-xwin precheck in appx-cross-build.ps1: it carried its own
copy of 0.23.0 (covered by neither Renovate custom manager) and hard-errored
before `npm run build-native` could perform the install that satisfies it.
Fix a stale comment in Cargo.toml that pointed at the SDK's scripts/lint.sh
instead of this repo's scripts/lint-rust.mjs.
* [PM-38767] Fail the toolchain-resolve step when the reader errors
Match bitwarden/sdk-internal's shape for the resolve step. Its intermediate shell
variable is load-bearing, not stylistic: under `bash -e` an assignment adopts the
command substitution's exit status, so a failing reader fails the step. Inlining
`$(...)` into `echo` makes the status `tee`'s, which is always 0, so the step went
green while writing an empty toolchain -- dtolnay/rust-toolchain would then have
silently resolved something other than the pin, the exact drift this PR removes.
Also rename the step outputs to RUST_TOOLCHAIN / RUST_NIGHTLY_TOOLCHAIN to match
the SDK and the env var already consumed by lint-rust.mjs. The remaining
divergence, reading via Node instead of `grep -oP`, stays: this job also runs on
macos-14, whose BSD grep has no -P.
* [PM-38767] Correct the cargo-xwin subcommand-token rationale
The instruction was right but the reason was wrong. The `xwin` token is omitted
not because clap fails to strip it, but because cargo-run-bin supplies it: the
raw binary accepts both `cargo-xwin build` and `cargo-xwin xwin build`, while
`cargo bin cargo-xwin xwin build` becomes `xwin xwin` and fails with
"error: unrecognized subcommand 'xwin'".
Verified by cross-compiling for real on macOS with the exact form build.js uses:
cargo bin cargo-xwin build --bin desktop_proxy --target=x86_64-pc-windows-msvc
produces target/x86_64-pc-windows-msvc/debug/desktop_proxy.exe, a PE32+ MS
Windows executable.
* [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.
* [PM-38767] Drop the now-unused cargo-run-bin bootstrap from build.js
Fallout from 11b9a8e090: once cargoBuild() switched from `cargo bin cargo-xwin`
to dispatching `cargo xwin`, nothing reachable from build.js invoked `cargo bin`
any more, so every Windows cross-build paid for a from-source
`cargo install cargo-run-bin` whose output was never used.
Remove it, and fold the "reached two different ways" comment back to one now that
both call sites reach cargo-xwin via PATH.
build.js consequently pins no cargo-run-bin version, so drop it from the Renovate
custom manager's fileMatch, along with the JS-array matchString whose only match
in the repo was that line (prepare-env-rust.mjs uses the CARGO_RUN_BIN_VERSION
const form, which has its own pattern). Verified the manager still matches
lint.yml, test.yml, prepare-env-rust.mjs and the devcontainer script, and no
longer matches build.js.
* [PM-38767] Address review: drop the comment about the absent cargo-xwin precheck
The neighbouring makemsix and osslsigncode prechecks exist because nothing
installs those tools for you; cargo-xwin needs no check because build-native
installs it. Documenting the absence of a check we never wrote is noise.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
84 lines
3.1 KiB
JavaScript
84 lines
3.1 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
// Verifies that cargo-run-bin will NOT use cargo-binstall to fetch tool binaries.
|
|
//
|
|
// cargo-run-bin uses binstall when EITHER:
|
|
// 1. A `binstall` alias is defined in .cargo/config.toml at the project root, OR
|
|
// 2. `cargo-binstall` is available on PATH.
|
|
//
|
|
// We require source installs from crates.io so the tools we run match the source
|
|
// we audit. See VULN-613 for the dependency review of cargo-run-bin and the
|
|
// explicit caveat against enabling binstall.
|
|
//
|
|
// Returns true if neither path would trigger binstall. A repo-defined binstall
|
|
// alias always fails. In CI (GITHUB_ACTIONS=true) `cargo-binstall` on PATH also
|
|
// fails; locally it only warns -- devs may have binstall installed on their own
|
|
// machines and we don't try to police that. When run directly, exits 1 on failure.
|
|
|
|
import { execFileSync } from "node:child_process";
|
|
import { existsSync, readFileSync } from "node:fs";
|
|
import { dirname, resolve } from "node:path";
|
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const DESKTOP_NATIVE = resolve(__dirname, "../apps/desktop/desktop_native");
|
|
|
|
function hasCommand(cmd) {
|
|
try {
|
|
if (process.platform === "win32") {
|
|
execFileSync("where", [cmd], { stdio: "ignore" });
|
|
} else {
|
|
// `command -v` is a portable POSIX shell builtin.
|
|
execFileSync("sh", ["-c", `command -v ${cmd}`], { stdio: "ignore" });
|
|
}
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export function checkNoBinstall() {
|
|
const config = resolve(DESKTOP_NATIVE, ".cargo/config.toml");
|
|
let ok = true;
|
|
|
|
// Match both inline form (`binstall = "..."`) and table form (`[alias.binstall]`).
|
|
if (
|
|
existsSync(config) &&
|
|
/^\s*(binstall\s*=|\[alias\.binstall\])/m.test(readFileSync(config, "utf8"))
|
|
) {
|
|
console.error("ERROR: .cargo/config.toml defines a 'binstall' alias.");
|
|
console.error(" cargo-run-bin would use cargo-binstall to fetch pre-built tool binaries");
|
|
console.error(
|
|
" from third-party mirrors (QuickInstall) instead of building from crates.io",
|
|
);
|
|
console.error(" sources. Remove the alias. See VULN-613 for context.");
|
|
ok = false;
|
|
}
|
|
|
|
if (hasCommand("cargo-binstall")) {
|
|
const msg =
|
|
"cargo-binstall is on PATH; cargo-run-bin will use it to fetch pre-built tool binaries";
|
|
if (process.env.GITHUB_ACTIONS === "true") {
|
|
console.error(`ERROR: ${msg}.`);
|
|
console.error(
|
|
" CI must build tools from source. Do not install cargo-binstall on the runner.",
|
|
);
|
|
console.error(" See VULN-613 for context.");
|
|
ok = false;
|
|
} else {
|
|
console.error(`WARN: ${msg} (your local machine).`);
|
|
console.error(
|
|
" CI builds tools from source, but your local 'cargo bin' invocations will use binstall.",
|
|
);
|
|
}
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
// Run standalone (e.g. from CI) when invoked directly. argv[1] is undefined under
|
|
// `node -e`, where nothing was invoked directly, so guard before resolving it.
|
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
process.exit(checkNoBinstall() ? 0 : 1);
|
|
}
|