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 7d20cd0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 25 deletions.
56 changes: 36 additions & 20 deletions script/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ function main() {
const src_dir = `zeromq-${zmq_version}`
const tarball = `zeromq-${zmq_version}.tar.gz`

const CMAKE_BUILD_TYPE = process.env.CMAKE_BUILD_TYPE ?? "Release"
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions
const CMAKE_BUILD_TYPE = process.env.CMAKE_BUILD_TYPE || "Release"

let build_options: string = ""

Expand All @@ -32,10 +33,12 @@ function main() {
}
}

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

if (process.platform === "darwin") {
process.env.MACOSX_DEPLOYMENT_TARGET = "10.15"
const MACOSX_DEPLOYMENT_TARGET = "10.15"
process.env.MACOSX_DEPLOYMENT_TARGET = MACOSX_DEPLOYMENT_TARGET
build_options += ` -DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}`
}

mkdir("-p", libzmq_build_prefix)
Expand Down Expand Up @@ -86,27 +89,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 ` -DCMAKE_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 7d20cd0

Please sign in to comment.