Skip to content

Commit b769117

Browse files
committed
chore: fix building on intel macs
1 parent ea1f4a6 commit b769117

File tree

2 files changed

+39
-22
lines changed

2 files changed

+39
-22
lines changed

Diff for: .github/scripts/libmongocrypt.mjs

+26-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
//@ts-check
1+
// @ts-check
2+
23
import util from 'node:util';
34
import process from 'node:process';
45
import fs from 'node:fs/promises';
@@ -22,6 +23,7 @@ async function parseArguments() {
2223
const options = {
2324
gitURL: { short: 'u', type: 'string', default: 'https://github.com/mongodb/libmongocrypt.git' },
2425
libVersion: { short: 'l', type: 'string', default: pkg['mongodb:libmongocrypt'] },
26+
'allow-only-x64-darwin': { type: 'boolean', default: false },
2527
clean: { short: 'c', type: 'boolean', default: false },
2628
build: { short: 'b', type: 'boolean', default: false },
2729
fastDownload: { type: 'boolean', default: false }, // Potentially incorrect download, only for the brave and impatient
@@ -46,6 +48,7 @@ async function parseArguments() {
4648
fastDownload: args.values.fastDownload,
4749
clean: args.values.clean,
4850
build: args.values.build,
51+
allowOnlyX64Darwin: args.values['allow-only-x64-darwin'],
4952
pkg
5053
};
5154
}
@@ -125,14 +128,14 @@ export async function buildLibMongoCrypt(libmongocryptRoot, nodeDepsRoot) {
125128
? toFlags({ Thost: 'x64', A: 'x64', DENABLE_WINDOWS_STATIC_RUNTIME: 'ON' })
126129
: [];
127130

128-
const MACOS_CMAKE_FLAGS =
129-
process.platform === 'darwin' // The minimum macos target version we want for
131+
const DARWIN_CMAKE_FLAGS =
132+
process.platform === 'darwin' // The minimum darwin target version we want for
130133
? toFlags({ DCMAKE_OSX_DEPLOYMENT_TARGET: '10.12' })
131134
: [];
132135

133136
await run(
134137
'cmake',
135-
[...CMAKE_FLAGS, ...WINDOWS_CMAKE_FLAGS, ...MACOS_CMAKE_FLAGS, libmongocryptRoot],
138+
[...CMAKE_FLAGS, ...WINDOWS_CMAKE_FLAGS, ...DARWIN_CMAKE_FLAGS, libmongocryptRoot],
136139
{ cwd: nodeBuildRoot }
137140
);
138141
await run('cmake', ['--build', '.', '--target', 'install', '--config', 'RelWithDebInfo'], {
@@ -272,16 +275,25 @@ async function main() {
272275

273276
if (process.platform === 'darwin') {
274277
// The "arm64" build is actually a universal binary
275-
await fs.copyFile(
276-
resolveRoot(
277-
'prebuilds',
278-
`mongodb-client-encryption-v${pkg.version}-napi-v4-darwin-arm64.tar.gz`
279-
),
280-
resolveRoot(
281-
'prebuilds',
282-
`mongodb-client-encryption-v${pkg.version}-napi-v4-darwin-x64.tar.gz`
283-
)
284-
);
278+
try {
279+
await fs.copyFile(
280+
resolveRoot(
281+
'prebuilds',
282+
`mongodb-client-encryption-v${pkg.version}-napi-v4-darwin-arm64.tar.gz`
283+
),
284+
resolveRoot(
285+
'prebuilds',
286+
`mongodb-client-encryption-v${pkg.version}-napi-v4-darwin-x64.tar.gz`
287+
)
288+
);
289+
} catch {
290+
if (process.arch === 'x64') {
291+
// The user of this script is building on an x64/intel/amd64 darwin which cannot build a universal bundle
292+
// By default we exit with failure because we do not want to release an intel only build
293+
console.error('Intel Darwin cannot build a universal bundle');
294+
process.exitCode = args.allowOnlyX64Darwin ? 0 : 1;
295+
}
296+
}
285297
}
286298
}
287299

Diff for: binding.gyp

+13-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"<!(node -p \"require('node-addon-api').include_dir\")",
66
],
77
'variables': {
8+
'ARCH': '<(host_arch)',
89
'variables': {
910
'build_type%': "dynamic",
1011
},
@@ -24,14 +25,6 @@
2425
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
2526
'CLANG_CXX_LIBRARY': 'libc++',
2627
'MACOSX_DEPLOYMENT_TARGET': '10.12',
27-
"OTHER_CFLAGS": [
28-
"-arch x86_64",
29-
"-arch arm64"
30-
],
31-
"OTHER_LDFLAGS": [
32-
"-arch x86_64",
33-
"-arch arm64"
34-
]
3528
},
3629
'cflags!': [ '-fno-exceptions' ],
3730
'cflags_cc!': [ '-fno-exceptions' ],
@@ -45,6 +38,18 @@
4538
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
4639
}
4740
}],
41+
['OS=="mac" and ARCH=="arm64"', {
42+
'xcode_settings': {
43+
"OTHER_CFLAGS": [
44+
"-arch x86_64",
45+
"-arch arm64"
46+
],
47+
"OTHER_LDFLAGS": [
48+
"-arch x86_64",
49+
"-arch arm64"
50+
]
51+
}
52+
}],
4853
['build_type=="dynamic"', {
4954
'link_settings': {
5055
'libraries': [

0 commit comments

Comments
 (0)