1
- //@ts -check
1
+ // @ts -check
2
+
2
3
import util from 'node:util' ;
3
4
import process from 'node:process' ;
4
5
import fs from 'node:fs/promises' ;
@@ -22,6 +23,7 @@ async function parseArguments() {
22
23
const options = {
23
24
gitURL : { short : 'u' , type : 'string' , default : 'https://github.com/mongodb/libmongocrypt.git' } ,
24
25
libVersion : { short : 'l' , type : 'string' , default : pkg [ 'mongodb:libmongocrypt' ] } ,
26
+ 'allow-only-x64-darwin' : { type : 'boolean' , default : false } ,
25
27
clean : { short : 'c' , type : 'boolean' , default : false } ,
26
28
build : { short : 'b' , type : 'boolean' , default : false } ,
27
29
fastDownload : { type : 'boolean' , default : false } , // Potentially incorrect download, only for the brave and impatient
@@ -46,6 +48,7 @@ async function parseArguments() {
46
48
fastDownload : args . values . fastDownload ,
47
49
clean : args . values . clean ,
48
50
build : args . values . build ,
51
+ allowOnlyX64Darwin : args . values [ 'allow-only-x64-darwin' ] ,
49
52
pkg
50
53
} ;
51
54
}
@@ -125,14 +128,14 @@ export async function buildLibMongoCrypt(libmongocryptRoot, nodeDepsRoot) {
125
128
? toFlags ( { Thost : 'x64' , A : 'x64' , DENABLE_WINDOWS_STATIC_RUNTIME : 'ON' } )
126
129
: [ ] ;
127
130
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
130
133
? toFlags ( { DCMAKE_OSX_DEPLOYMENT_TARGET : '10.12' } )
131
134
: [ ] ;
132
135
133
136
await run (
134
137
'cmake' ,
135
- [ ...CMAKE_FLAGS , ...WINDOWS_CMAKE_FLAGS , ...MACOS_CMAKE_FLAGS , libmongocryptRoot ] ,
138
+ [ ...CMAKE_FLAGS , ...WINDOWS_CMAKE_FLAGS , ...DARWIN_CMAKE_FLAGS , libmongocryptRoot ] ,
136
139
{ cwd : nodeBuildRoot }
137
140
) ;
138
141
await run ( 'cmake' , [ '--build' , '.' , '--target' , 'install' , '--config' , 'RelWithDebInfo' ] , {
@@ -272,16 +275,25 @@ async function main() {
272
275
273
276
if ( process . platform === 'darwin' ) {
274
277
// 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
+ }
285
297
}
286
298
}
287
299
0 commit comments