@@ -19,6 +19,26 @@ const vendorPath = path.resolve(import.meta.dirname, "..", "vendor");
1919const opensslPatchPath = path . join ( vendorPath , "patches" , "openssl" ) ;
2020const extractPath = path . join ( vendorPath , "openssl" ) ;
2121
22+ const convertArch = ( archStr ) => {
23+ const convertedArch = {
24+ 'ia32' : 'x86' ,
25+ 'x86' : 'x86' ,
26+ 'x64' : 'x64' ,
27+ 'arm64' : 'arm64'
28+ } [ archStr ] ;
29+
30+ if ( ! convertedArch ) {
31+ throw new Error ( 'unsupported architecture' ) ;
32+ }
33+
34+ return convertedArch ;
35+ }
36+
37+ const hostArch = convertArch ( process . arch ) ;
38+ const targetArch = process . env . npm_config_arch
39+ ? convertArch ( process . env . npm_config_arch )
40+ : hostArch ;
41+
2242const pathsToIncludeForPackage = [
2343 "include" , "lib"
2444] ;
@@ -82,8 +102,10 @@ const buildDarwin = async (buildCwd, macOsDeploymentTarget) => {
82102 throw new Error ( "Expected macOsDeploymentTarget to be specified" ) ;
83103 }
84104
105+ const buildConfig = targetArch === "x64" ? "darwin64-x86_64-cc" : "darwin64-arm64-cc" ;
106+
85107 const configureArgs = [
86- process . arch === "x64" ? "darwin64-x86_64-cc" : "darwin64-arm64-cc" ,
108+ buildConfig ,
87109 // speed up ecdh on little-endian platforms with 128bit int support
88110 "enable-ec_nistp_64_gcc_128" ,
89111 // compile static libraries
@@ -107,7 +129,7 @@ const buildDarwin = async (buildCwd, macOsDeploymentTarget) => {
107129
108130 await applyOpenSSLPatches ( buildCwd , "darwin" ) ;
109131
110- // only build the libraries, not the tests/ fuzzer or apps
132+ // only build the libraries, not the fuzzer or apps
111133 await execPromise ( "make build_libs" , {
112134 cwd : buildCwd
113135 } , { pipeOutput : true } ) ;
@@ -123,8 +145,10 @@ const buildDarwin = async (buildCwd, macOsDeploymentTarget) => {
123145} ;
124146
125147const buildLinux = async ( buildCwd ) => {
148+ const buildConfig = targetArch === "x64" ? "linux-x86_64" : "linux-aarch64" ;
149+
126150 const configureArgs = [
127- "linux-x86_64" ,
151+ buildConfig ,
128152 // Electron(at least on centos7) imports the libcups library at runtime, which has a
129153 // dependency on the system libssl/libcrypto which causes symbol conflicts and segfaults.
130154 // To fix this we need to hide all the openssl symbols to prevent them from being overridden
@@ -146,7 +170,7 @@ const buildLinux = async (buildCwd) => {
146170
147171 await applyOpenSSLPatches ( buildCwd , "linux" ) ;
148172
149- // only build the libraries, not the tests/ fuzzer or apps
173+ // only build the libraries, not the fuzzer or apps
150174 await execPromise ( "make build_libs" , {
151175 cwd : buildCwd
152176 } , { pipeOutput : true } ) ;
@@ -232,6 +256,11 @@ const buildWin32 = async (buildCwd, vsBuildArch) => {
232256 vcTarget = "VC-WIN32" ;
233257 break ;
234258 }
259+
260+ case "arm64" : {
261+ vcTarget = "VC-WIN64-ARM" ;
262+ break ;
263+ }
235264
236265 default : {
237266 throw new Error ( `Unknown vsBuildArch: ${ vsBuildArch } ` ) ;
@@ -382,15 +411,8 @@ const downloadOpenSSLIfNecessary = async ({
382411 console . log ( "Download finished." ) ;
383412}
384413
385- export const getOpenSSLPackageName = ( ) => {
386- let arch = process . arch ;
387- if ( process . platform === "win32" && (
388- process . arch === "ia32" || process . env . NODEGIT_VS_BUILD_ARCH === "x86"
389- ) ) {
390- arch = "x86" ;
391- }
392-
393- return `openssl-${ OPENSSL_VERSION } -${ process . platform } -${ arch } .tar.gz` ;
414+ const getOpenSSLPackageName = ( ) => {
415+ return `openssl-${ OPENSSL_VERSION } -${ process . platform } -${ targetArch } .tar.gz` ;
394416}
395417
396418export const getOpenSSLPackagePath = ( ) => path . join ( import . meta. dirname , getOpenSSLPackageName ( ) ) ;
@@ -450,18 +472,10 @@ const acquireOpenSSL = async () => {
450472 }
451473 }
452474
453- let vsBuildArch ;
454- if ( process . platform === "win32" ) {
455- vsBuildArch = process . env . NODEGIT_VS_BUILD_ARCH || ( process . arch === "x64" ? "x64" : "x86" ) ;
456- if ( ! [ "x64" , "x86" ] . includes ( vsBuildArch ) ) {
457- throw new Error ( `Invalid vsBuildArch: ${ vsBuildArch } ` ) ;
458- }
459- }
460-
461475 await buildOpenSSLIfNecessary ( {
462476 openSSLVersion : OPENSSL_VERSION ,
463477 macOsDeploymentTarget,
464- vsBuildArch
478+ vsBuildArch : process . platform === "win32" ? targetArch : undefined
465479 } ) ;
466480 if ( process . env . NODEGIT_OPENSSL_BUILD_PACKAGE ) {
467481 await buildPackage ( ) ;
0 commit comments