From dbdf29e991c0cb0bbaec55456af64b6c5bb435ff Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 15 Nov 2022 20:55:54 -0800 Subject: [PATCH] fix: fix the MacOS Arm flags --- script/build.ts | 49 +++++++++++++++++++++++++++++----------------- script/prebuild.ts | 19 +++++++++++++----- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/script/build.ts b/script/build.ts index dddee80d..b0bc647f 100644 --- a/script/build.ts +++ b/script/build.ts @@ -32,7 +32,7 @@ function main() { } } - build_options += handleArch() + build_options += archCMakeOptions() if (process.platform === "darwin") { process.env.MACOSX_DEPLOYMENT_TARGET = "10.15" @@ -86,27 +86,40 @@ function main() { main() -function handleArch() { - if (process.platform !== "win32") { - // https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_PLATFORM.html - // CMAKE_GENERATOR_PLATFORM only supported on Windows - return "" - } - +function archCMakeOptions() { // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions const arch = (process.env.ARCH || process.arch).toLowerCase() - let CMAKE_GENERATOR_PLATFORM: string - switch (arch) { - case "x86": - case "ia32": { - CMAKE_GENERATOR_PLATFORM = "win32" - break + + if (process.platform === "win32") { + // CMAKE_GENERATOR_PLATFORM only supported on Windows + // https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_PLATFORM.html + + switch (arch) { + case "x86": + case "ia32": { + return " -DCMAKE_GENERATOR_PLATFORM=win32" + } + default: { + return ` -DCMAKE_GENERATOR_PLATFORM=${arch.toUpperCase()}` + } } - default: { - CMAKE_GENERATOR_PLATFORM = arch.toUpperCase() - break + } + + if (process.platform === "darwin") { + // handle MacOS Arm + switch (arch) { + case "x64": + case "x86_64": { + return "" + } + case "arm64": { + return ` CMAKE_OSX_ARCHITECTURES=${arch}` + } + default: { + return "" + } } } - return ` -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}` + return "" } diff --git a/script/prebuild.ts b/script/prebuild.ts index 5ec8c8ec..82116e85 100644 --- a/script/prebuild.ts +++ b/script/prebuild.ts @@ -7,7 +7,7 @@ main().catch(e => { async function main() { console.log("Building distribution binary...") - const prebuildArch = getNodearch(process.env.ARCH ?? process.arch) + const prebuildArch = getNodearch() if (typeof process.env.TRIPLE === "string") { const TRIPLE = process.env.TRIPLE @@ -39,9 +39,18 @@ async function main() { }) } -function getNodearch(arch: string): string { - if (arch === "x86") { - return "ia32" +function getNodearch(): string { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions + const arch = process.env.ARCH || process.arch + switch (arch) { + case "x86": { + return "ia32" + } + case "x86_64": { + return "x64" + } + default: { + return arch + } } - return arch }