Skip to content

Commit

Permalink
fix: fix the MacOS Arm flags
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Nov 16, 2022
1 parent 9a86a1e commit dbdf29e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 23 deletions.
49 changes: 31 additions & 18 deletions script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function main() {
}
}

build_options += handleArch()
build_options += archCMakeOptions()

if (process.platform === "darwin") {
process.env.MACOSX_DEPLOYMENT_TARGET = "10.15"
Expand Down Expand Up @@ -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 ""
}
19 changes: 14 additions & 5 deletions script/prebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit dbdf29e

Please sign in to comment.