Skip to content

Commit 7d20cd0

Browse files
committed
fix: fix the MacOS Arm flags
1 parent 9a86a1e commit 7d20cd0

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

script/build.ts

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ function main() {
1919
const src_dir = `zeromq-${zmq_version}`
2020
const tarball = `zeromq-${zmq_version}.tar.gz`
2121

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

2425
let build_options: string = ""
2526

@@ -32,10 +33,12 @@ function main() {
3233
}
3334
}
3435

35-
build_options += handleArch()
36+
build_options += archCMakeOptions()
3637

3738
if (process.platform === "darwin") {
38-
process.env.MACOSX_DEPLOYMENT_TARGET = "10.15"
39+
const MACOSX_DEPLOYMENT_TARGET = "10.15"
40+
process.env.MACOSX_DEPLOYMENT_TARGET = MACOSX_DEPLOYMENT_TARGET
41+
build_options += ` -DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}`
3942
}
4043

4144
mkdir("-p", libzmq_build_prefix)
@@ -86,27 +89,40 @@ function main() {
8689

8790
main()
8891

89-
function handleArch() {
90-
if (process.platform !== "win32") {
91-
// https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_PLATFORM.html
92-
// CMAKE_GENERATOR_PLATFORM only supported on Windows
93-
return ""
94-
}
95-
92+
function archCMakeOptions() {
9693
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions
9794
const arch = (process.env.ARCH || process.arch).toLowerCase()
98-
let CMAKE_GENERATOR_PLATFORM: string
99-
switch (arch) {
100-
case "x86":
101-
case "ia32": {
102-
CMAKE_GENERATOR_PLATFORM = "win32"
103-
break
95+
96+
if (process.platform === "win32") {
97+
// CMAKE_GENERATOR_PLATFORM only supported on Windows
98+
// https://cmake.org/cmake/help/latest/variable/CMAKE_GENERATOR_PLATFORM.html
99+
100+
switch (arch) {
101+
case "x86":
102+
case "ia32": {
103+
return " -DCMAKE_GENERATOR_PLATFORM=win32"
104+
}
105+
default: {
106+
return ` -DCMAKE_GENERATOR_PLATFORM=${arch.toUpperCase()}`
107+
}
104108
}
105-
default: {
106-
CMAKE_GENERATOR_PLATFORM = arch.toUpperCase()
107-
break
109+
}
110+
111+
if (process.platform === "darwin") {
112+
// handle MacOS Arm
113+
switch (arch) {
114+
case "x64":
115+
case "x86_64": {
116+
return ""
117+
}
118+
case "arm64": {
119+
return ` -DCMAKE_OSX_ARCHITECTURES=${arch}`
120+
}
121+
default: {
122+
return ""
123+
}
108124
}
109125
}
110126

111-
return ` -DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}`
127+
return ""
112128
}

script/prebuild.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ main().catch(e => {
77
async function main() {
88
console.log("Building distribution binary...")
99

10-
const prebuildArch = getNodearch(process.env.ARCH ?? process.arch)
10+
const prebuildArch = getNodearch()
1111

1212
if (typeof process.env.TRIPLE === "string") {
1313
const TRIPLE = process.env.TRIPLE
@@ -39,9 +39,18 @@ async function main() {
3939
})
4040
}
4141

42-
function getNodearch(arch: string): string {
43-
if (arch === "x86") {
44-
return "ia32"
42+
function getNodearch(): string {
43+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions
44+
const arch = process.env.ARCH || process.arch
45+
switch (arch) {
46+
case "x86": {
47+
return "ia32"
48+
}
49+
case "x86_64": {
50+
return "x64"
51+
}
52+
default: {
53+
return arch
54+
}
4555
}
46-
return arch
4756
}

0 commit comments

Comments
 (0)