Skip to content

Commit bb2090b

Browse files
cursoragentBob Corbin
andcommitted
Keep rustc on the sanitized packaging PATH.
Native desktop failed after the window suite: applicationNotices spawns rustc --version --verbose, but applyPackagingPath only kept target/, Node, and /usr/bin. Add CARGO_HOME, ~/.cargo/bin, and any safe PATH directory that already has rustc/cargo. Still reject /usr/local/bin and Hermes. Co-authored-by: Bob Corbin <ShadowfetchLinux@users.noreply.github.com>
1 parent 54f7db1 commit bb2090b

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

‎scripts/native-packaging-env.mjs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,45 @@ export function isUnsafePackagingDir(dir) {
5656
);
5757
}
5858

59+
function dirContains(dir, name) {
60+
try {
61+
statSync(path.join(dir, name));
62+
return true;
63+
} catch {
64+
return false;
65+
}
66+
}
67+
68+
// rustc/cargo live on the caller PATH (rustup ~/.cargo/bin, CARGO_HOME).
69+
// linuxdeploy still must not see /usr/local/bin or Hermes; keep only the
70+
// toolchain directories themselves when they pass the same safety checks.
71+
function rustToolchainDirs() {
72+
const candidates = [];
73+
if (process.env.CARGO_HOME) {
74+
candidates.push(path.join(process.env.CARGO_HOME, "bin"));
75+
}
76+
if (process.env.HOME) {
77+
candidates.push(path.join(process.env.HOME, ".cargo", "bin"));
78+
}
79+
for (const dir of (process.env.PATH || "").split(path.delimiter)) {
80+
if (!dir) continue;
81+
const resolved = resolveExistingDir(dir);
82+
if (
83+
resolved &&
84+
(dirContains(resolved, "rustc") || dirContains(resolved, "cargo"))
85+
) {
86+
candidates.push(resolved);
87+
}
88+
}
89+
return candidates;
90+
}
91+
5992
export function packagingDirs(root, options = {}) {
6093
const execDir = options.execDir ?? path.dirname(process.execPath);
6194
const extras = [
6295
path.join(root, "tools/rust-dev/extracted/usr/bin"),
6396
path.join(root, "..", "tools/rust-dev/extracted/usr/bin"),
97+
...rustToolchainDirs(),
6498
path.join(root, "target/release"),
6599
path.join(root, "target/debug"),
66100
path.join(root, "target/.tauri"),

‎scripts/test-native-packaging-env.mjs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ test("packaging PATH is constructed, not inherited", () => {
3838
assert.doesNotMatch(joined, /\.hermes/);
3939
const rustDev = path.resolve(root, "../tools/rust-dev/extracted/usr/bin");
4040
if (existsSync(rustDev)) assert.ok(dirs.includes(rustDev));
41+
const rustcDir = dirs.find((dir) => existsSync(path.join(dir, "rustc")));
42+
assert.ok(
43+
rustcDir,
44+
"sanitized PATH must still find rustc for dependency notices",
45+
);
46+
assert.notEqual(path.resolve(rustcDir), "/usr/local/bin");
4147
const tauriTools = path.join(root, "target/.tauri");
4248
if (existsSync(tauriTools)) assert.ok(dirs.includes(tauriTools));
4349
});
@@ -64,6 +70,10 @@ test("applyPackagingPath overwrites a dirty process PATH", () => {
6470
assert.doesNotMatch(next, /(^|:)\/usr\/local\/bin(:|$)/);
6571
assert.match(next, /(^|:)\/usr\/bin(:|$)/);
6672
assert.notEqual(next, dirtyPath);
73+
assert.ok(
74+
next.split(path.delimiter).some((dir) => existsSync(path.join(dir, "rustc"))),
75+
"dirty caller PATH must not drop rustc",
76+
);
6777
} finally {
6878
process.env.PATH = previous;
6979
}

0 commit comments

Comments
 (0)