Skip to content

Commit ad00c9a

Browse files
committed
natively compile for arm64
1 parent 9bc5b39 commit ad00c9a

File tree

3 files changed

+54
-29
lines changed

3 files changed

+54
-29
lines changed

lifecycleScripts/install.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ module.exports = function install() {
3030

3131
return new Promise(function(resolve, reject) {
3232
const gypPath = path.join(__dirname, "..", "node_modules", "node-gyp", "bin", "node-gyp.js");
33-
var spawnedNodePreGyp = spawn(nodePreGyp, args, {
33+
34+
const nodePreGypPath = path.resolve(path.join(__dirname, "..", "node_modules", "@mapbox", "node-pre-gyp", "bin", nodePreGyp));
35+
var spawnedNodePreGyp = spawn(nodePreGypPath, args, {
3436
env: {
3537
...process.env,
3638
npm_config_node_gyp: gypPath

utils/acquireOpenSSL.mjs

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@ const vendorPath = path.resolve(import.meta.dirname, "..", "vendor");
1919
const opensslPatchPath = path.join(vendorPath, "patches", "openssl");
2020
const 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+
2242
const 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

125147
const 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

396418
export 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();

vendor/libgit2.gyp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,22 @@
315315
# Workaround of a strange bug:
316316
# TargetMachine + static_library + x64 = nothing.
317317
"conditions": [
318-
["target_arch=='x64'", {
319-
"VCLibrarianTool": {
320-
"AdditionalOptions": [
321-
"/MACHINE:X64",
322-
],
318+
[
319+
"target_arch=='x64'", {
320+
"VCLibrarianTool": {
321+
"AdditionalOptions": [
322+
"/MACHINE:X64",
323+
],
324+
},
325+
},
326+
"target_arch=='arm64'", {
327+
"VCLibrarianTool": {
328+
"AdditionalOptions": [
329+
"/MACHINE:ARM64",
330+
],
331+
},
323332
},
324-
}, {
333+
{
325334
"VCLibrarianTool": {
326335
"AdditionalOptions": [
327336
"/MACHINE:x86",

0 commit comments

Comments
 (0)