feat: Support cross-compiling to aarch64 (#40)

#19
This commit is contained in:
Pylogmon
2023-11-30 22:46:09 +08:00
committed by GitHub
parent 306c3bea21
commit 653c7d4430
3 changed files with 89 additions and 12 deletions

View File

@@ -11,10 +11,6 @@ const cwd = process.cwd();
const TEMP_DIR = path.join(cwd, "node_modules/.verge");
const FORCE = process.argv.includes("--force");
const SIDECAR_HOST = execSync("rustc -vV")
.toString()
.match(/(?<=host: ).+(?=\s*)/g)[0];
/* ======= clash =======
const CLASH_STORAGE_PREFIX = "https://release.dreamacro.workers.dev/";
const CLASH_URL_PREFIX =
@@ -42,6 +38,7 @@ const META_URL_PREFIX = `https://github.com/wonfen/Clash.Meta/releases/download/
const META_MAP = {
"win32-x64": "clash.meta-win-amd64",
"win32-arm64": "clash.meta-win-arm64",
"darwin-x64": "clash.meta-darwin-amd64",
"darwin-arm64": "clash.meta-darwin-arm64",
"linux-x64": "clash.meta-linux-amd64",
@@ -51,8 +48,33 @@ const META_MAP = {
/*
* check available
*/
const PLATFORM_MAP = {
"x86_64-pc-windows-msvc": "win32",
"aarch64-pc-windows-msvc": "win32",
"x86_64-apple-darwin": "darwin",
"aarch64-apple-darwin": "darwin",
"x86_64-unknown-linux-gnu": "linux",
"aarch64-unknown-linux-gnu": "linux",
};
const ARCH_MAP = {
"x86_64-pc-windows-msvc": "x64",
"aarch64-pc-windows-msvc": "arm64",
"x86_64-apple-darwin": "x64",
"aarch64-apple-darwin": "arm64",
"x86_64-unknown-linux-gnu": "x64",
"aarch64-unknown-linux-gnu": "arm64",
};
const { platform, arch } = process;
const target = process.argv.slice(2)[0];
const { platform, arch } = target
? { platform: PLATFORM_MAP[target], arch: ARCH_MAP[target] }
: process;
const SIDECAR_HOST = target
? target
: execSync("rustc -vV")
.toString()
.match(/(?<=host: ).+(?=\s*)/g)[0];
/*
if (!CLASH_MAP[`${platform}-${arch}`]) {
throw new Error(`clash unsupported platform "${platform}-${arch}"`);