Skip to content

Commit 38d64f2

Browse files
committed
Default to dynamically linking OpenSSL on Linux
Statically link if NODEGIT_OPENSSL_STATIC_LINK=1
1 parent 39e7621 commit 38d64f2

5 files changed

Lines changed: 39 additions & 9 deletions

File tree

generate/templates/templates/binding.gyp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"is_electron%": "<!(node ./utils/isBuildingForElectron.js <(node_root_dir))",
44
"is_IBMi%": "<!(node -p \"os.platform() == 'aix' && os.type() == 'OS400' ? 1 : 0\")",
55
"electron_openssl_root%": "<!(node ./utils/getElectronOpenSSLRoot.js <(module_root_dir))",
6+
"electron_openssl_static%": "<!(node -p \"process.platform !== 'linux' || process.env.NODEGIT_OPENSSL_STATIC_LINK === '1' ? 1 : 0\")",
67
"macOS_deployment_target": "10.11"
78
},
89

@@ -175,15 +176,21 @@
175176
"-std=c++14"
176177
],
177178
"conditions": [
178-
["<(is_electron) == 1", {
179+
["<(is_electron) == 1 and <(electron_openssl_static) == 1", {
179180
"include_dirs": [
180181
"<(electron_openssl_root)/include"
181182
],
182183
"libraries": [
183-
# this order is signifcant on centos7 apparently...
184+
# this order is significant on centos7 apparently...
184185
"<(electron_openssl_root)/lib/libssl.a",
185186
"<(electron_openssl_root)/lib/libcrypto.a"
186187
]
188+
}],
189+
["<(is_electron) == 1 and <(electron_openssl_static) != 1", {
190+
"libraries": [
191+
"-lcrypto",
192+
"-lssl"
193+
]
187194
}]
188195
],
189196
}],

guides/install/from-source/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ npm install nodegit --msvs_version=2013
6565
```
6666

6767
### Electron and OpenSSL ###
68-
A local version of OpenSSL is required when building for Electron on Windows and macOS. This is due to Electron using BoringSSL, as we are not able to link to it like we are OpenSSL in Node.
68+
A local version of OpenSSL is required when building for Electron on Windows and macOS. This is due to Electron using BoringSSL, as we are not able to link to it like we are OpenSSL in Node. Additionally, OpenSSL can be statically linked on Linux by setting the `NODEGIT_OPENSSL_STATIC_LINK` environment variable to `1`.
6969

7070
`acquireOpenSSL.js` will attempt to download and build OpenSSL locally. On macOS, this should Just Work(tm). On Windows, things are a little trickier.
7171

utils/acquireOpenSSL.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ const makeOnStreamDownloadProgress = () => {
196196
};
197197

198198
const buildOpenSSLIfNecessary = async (openSSLVersion, macOsDeploymentTarget) => {
199+
if (process.platform !== "darwin" && process.platform !== "win32" && process.platform !== 'linux') {
200+
console.log(`Skipping OpenSSL build, not required on ${process.platform}`);
201+
return;
202+
}
203+
204+
if (process.platform === 'linux' && process.env.NODEGIT_OPENSSL_STATIC_LINK !== '1') {
205+
console.log(`Skipping OpenSSL build, NODEGIT_OPENSSL_STATIC_LINK !== 1`);
206+
return;
207+
}
208+
199209
await removeOpenSSLIfOudated(openSSLVersion);
200210

201211
try {
@@ -225,7 +235,7 @@ const buildOpenSSLIfNecessary = async (openSSLVersion, macOsDeploymentTarget) =>
225235

226236
if (process.platform === "darwin") {
227237
await buildDarwin(buildCwd, macOsDeploymentTarget);
228-
} else if (process.platform === "linux") {
238+
} else if (process.platform === "linux" && process.env.NODEGIT_OPENSSL_STATIC_LINK === '1') {
229239
await buildLinux(buildCwd);
230240
} else if (process.platform === "win32") {
231241
await buildWin32(buildCwd);
@@ -237,6 +247,16 @@ const buildOpenSSLIfNecessary = async (openSSLVersion, macOsDeploymentTarget) =>
237247
}
238248

239249
const downloadOpenSSLIfNecessary = async (downloadBinUrl, maybeDownloadSha256) => {
250+
if (process.platform !== "darwin" && process.platform !== "win32" && process.platform !== 'linux') {
251+
console.log(`Skipping OpenSSL download, not required on ${process.platform}`);
252+
return;
253+
}
254+
255+
if (process.platform === 'linux' && process.env.NODEGIT_OPENSSL_STATIC_LINK !== '1') {
256+
console.log(`Skipping OpenSSL download, NODEGIT_OPENSSL_STATIC_LINK !== 1`);
257+
return;
258+
}
259+
240260
try {
241261
await fs.stat(extractPath);
242262
console.log("Skipping OpenSSL download, dir exists");

utils/configureLibssh2.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ module.exports = function retrieveExternalDependencies() {
2525
newEnv[key] = process.env[key];
2626
});
2727

28-
let cpArgs = `--with-libssl-prefix=${opensslVendorDirectory}`;
28+
let cpArgs = process.env.NODEGIT_OPENSSL_STATIC_LINK === '1'
29+
? ` --with-libssl-prefix=${opensslVendorDirectory}`
30+
: '';
2931
cp.exec(
30-
`${libssh2ConfigureScript} ${cpArgs}`,
32+
`${libssh2ConfigureScript}${cpArgs}`,
3133
{
3234
cwd: libssh2VendorDirectory,
3335
env: newEnv

vendor/libgit2.gyp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"is_clang%": 0,
1212
"is_IBMi%": "<!(node -p \"os.platform() == 'aix' && os.type() == 'OS400' ? 1 : 0\")",
1313
"electron_openssl_root%": "<!(node ../utils/getElectronOpenSSLRoot.js <(module_root_dir))",
14+
"electron_openssl_static%": "<!(node -p \"process.platform !== 'linux' || process.env.NODEGIT_OPENSSL_STATIC_LINK === '1' ? 1 : 0\")",
1415
},
1516
"targets": [
1617
{
@@ -362,7 +363,7 @@
362363
}],
363364
["OS=='mac' or OS=='linux' or OS.endswith('bsd') or <(is_IBMi) == 1", {
364365
"conditions": [
365-
["<(is_electron) == 1", {
366+
["<(is_electron) == 1 and <(electron_openssl_static) == 1", {
366367
"include_dirs": [
367368
"<(electron_openssl_root)/include"
368369
]
@@ -622,7 +623,7 @@
622623
"conditions": [
623624
["OS=='mac' or OS=='linux' or OS.endswith('bsd') or <(is_IBMi) == 1", {
624625
"conditions": [
625-
["<(is_electron) == 1", {
626+
["<(is_electron) == 1 and <(electron_openssl_static) == 1", {
626627
"include_dirs": [
627628
"<(electron_openssl_root)/include"
628629
]
@@ -702,7 +703,7 @@
702703
}],
703704
["OS=='linux'", {
704705
"conditions": [
705-
["<(is_electron) == 1", {
706+
["<(is_electron) == 1 and <(electron_openssl_static) == 1", {
706707
"include_dirs": ["<(electron_openssl_root)/include"]
707708
}]
708709
],

0 commit comments

Comments
 (0)