mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-11-23 08:44:13 +01:00
Privileged helper for system proxy (#796)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4d38a482f6
commit
f7aea62c07
33 files changed
+3536
-176
No files matched your search
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Builds Yaak Proxy's privileged helper and places it where the proxy bundle's
|
||||
* `externalBin` expects it, named for the target triple. The helper is macOS only.
|
||||
*/
|
||||
|
||||
const { execFileSync } = require("node:child_process");
|
||||
const { chmodSync, copyFileSync, mkdirSync } = require("node:fs");
|
||||
const path = require("node:path");
|
||||
|
||||
if (process.platform !== "darwin") {
|
||||
console.log("The proxy helper is macOS only, so there is nothing to vendor");
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
const rootDir = path.join(__dirname, "..");
|
||||
const destDir = path.join(rootDir, "crates-tauri", "yaak-app-proxy", "vendored", "helper");
|
||||
const target = process.env.TAURI_ENV_TARGET_TRIPLE || hostTriple();
|
||||
|
||||
function hostTriple() {
|
||||
const output = execFileSync("rustc", ["-vV"]).toString();
|
||||
return output.match(/^host: (\S+)$/m)[1];
|
||||
}
|
||||
|
||||
/** Where Cargo builds, which CARGO_TARGET_DIR or a config's build.target-dir can move */
|
||||
function targetDir() {
|
||||
const args = ["metadata", "--format-version", "1", "--no-deps"];
|
||||
return JSON.parse(execFileSync("cargo", args, { cwd: rootDir })).target_directory;
|
||||
}
|
||||
|
||||
function build(triple) {
|
||||
execFileSync(
|
||||
"cargo",
|
||||
["build", "--package", "yaak-proxy-helper", "--release", "--target", triple],
|
||||
{ cwd: rootDir, stdio: "inherit" },
|
||||
);
|
||||
return path.join(targetDir(), triple, "release", "yaak-proxy-helper");
|
||||
}
|
||||
|
||||
mkdirSync(destDir, { recursive: true });
|
||||
const dest = path.join(destDir, `yaak-proxy-helper-${target}`);
|
||||
if (target === "universal-apple-darwin") {
|
||||
const arm = build("aarch64-apple-darwin");
|
||||
const intel = build("x86_64-apple-darwin");
|
||||
execFileSync("lipo", ["-create", "-output", dest, arm, intel], { stdio: "inherit" });
|
||||
} else {
|
||||
copyFileSync(build(target), dest);
|
||||
}
|
||||
chmodSync(dest, 0o755);
|
||||
console.log(`Vendored the proxy helper to ${path.relative(rootDir, dest)}`);
|
||||
Reference in new issue
Block a user