1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-14 23:33:31 +00:00
Files
browser/apps/desktop/desktop_native/build.js
2024-07-08 15:26:47 +02:00

57 lines
1.8 KiB
JavaScript

/* 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";
function buildNapiModule(target) {
const targetArg = target ? `--target ${target}` : "";
return child_process.execSync(`npm run build --release -- ${targetArg}`, { stdio: 'inherit', cwd: path.join(__dirname, "napi") });
}
function buildProxyBin(target) {
const targetArg = target ? `--target ${target}` : "";
return child_process.execSync(`cargo build --bin desktop_proxy --release ${targetArg}`, {stdio: 'inherit', cwd: path.join(__dirname, "proxy")});
}
if (!crossPlatform) {
buildNapiModule();
buildProxyBin();
return;
}
let targets = [];
switch (process.platform) {
case "win32":
targets = ["i686-pc-windows-msvc", "x86_64-pc-windows-msvc", "aarch64-pc-windows-msvc"];
break;
case "darwin":
targets = ["x86_64-apple-darwin", "aarch64-apple-darwin"];
break;
default:
targets = ['x86_64-unknown-linux-musl'];
process.env["PKG_CONFIG_ALLOW_CROSS"] = "1";
process.env["PKG_CONFIG_ALL_STATIC"] = "1";
break;
}
targets.forEach(target => {
buildNapiModule(target);
buildProxyBin(target);
});
if (process.platform === "darwin") {
fs.mkdirSync(path.join(__dirname, "target", "darwin-universal"), { recursive: true });
let command = `lipo -create -output ${path.join(__dirname, "target", "darwin-universal", "desktop_proxy")} `;
targets.forEach(target => {
command += `${path.join(__dirname, "target", target, "release", "desktop_proxy")} `;
});
child_process.execSync(command, { stdio: 'inherit', cwd: __dirname});
}