Skip to content

Commit 90bb388

Browse files
committed
Create a script for acquiring OpenSSL distributions based on OS/platform
1 parent bc7fd43 commit 90bb388

File tree

6 files changed

+187
-44
lines changed

6 files changed

+187
-44
lines changed

generate/templates/templates/binding.gyp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@
6161
"conditions": [
6262
["node_root_dir.split('/')[-1].startswith('iojs')", {
6363
"include_dirs": [
64-
"/usr/local/opt/openssl@1.1/include"
64+
"vendor/openssl/include"
6565
],
6666
"libraries": [
67-
"/usr/local/opt/openssl@1.1/lib/libcrypto.a",
68-
"/usr/local/opt/openssl@1.1/lib/libssl.a"
67+
"<(module_root_dir)/vendor/openssl/lib/libcrypto.a",
68+
"<(module_root_dir)/vendor/openssl/lib/libssl.a"
6969
]
7070
}]
7171
],
@@ -86,20 +86,10 @@
8686
"OS=='win'", {
8787
"conditions": [
8888
["node_root_dir.split('\\\\')[-1].startswith('iojs')", {
89-
"conditions": [
90-
["target_arch == 'x64'", {
91-
"include_dirs": ["vendor/win/openssl/include64"],
92-
"libraries": [
93-
"<(module_root_dir)/vendor/win/openssl/lib64/libcryptoMT.lib",
94-
"<(module_root_dir)/vendor/win/openssl/lib64/libsslMT.lib"
95-
]
96-
}, {
97-
"include_dirs": ["vendor/win/openssl/include"],
98-
"libraries": [
99-
"<(module_root_dir)/vendor/win/openssl/lib/libcryptoMT.lib",
100-
"<(module_root_dir)/vendor/win/openssl/lib/libsslMT.lib"
101-
]
102-
}]
89+
"include_dirs": ["vendor/openssl/include"],
90+
"libraries": [
91+
"<(module_root_dir)/vendor/openssl/lib/libcrypto.lib",
92+
"<(module_root_dir)/vendor/openssl/lib/libssl.lib"
10393
]
10494
}]
10595
],

lifecycleScripts/configureLibssh2.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@ var rooted = function (dir) {
66
return escapedPathForShell;
77
};
88

9-
var isWin64 = function() {
10-
return process.platform === "win32" && (
11-
process.arch === "x64" ||
12-
process.env.hasOwnProperty("PROCESSOR_ARCHITEW6432")
13-
);
14-
};
15-
169
module.exports = function retrieveExternalDependencies() {
1710
if (process.platform === "win32") {
1811
return Promise.resolve("");
@@ -23,22 +16,18 @@ module.exports = function retrieveExternalDependencies() {
2316
var opensslDir;
2417

2518
if (process.platform === "darwin") {
26-
opensslDir = "/usr/local/opt/openssl@1.1";
27-
} else if (process.platform === "win32") {
28-
opensslDir = path.join(process.cwd(), "vendor", "win", "openssl");
19+
opensslDir = "vendor/openssl";
2920
}
3021

3122
var newEnv = {};
3223
Object.keys(process.env).forEach(function(key) {
3324
newEnv[key] = process.env[key];
3425
});
3526

36-
const includeDirName = isWin64() ? "include64" : "include";
37-
3827
var maybeLibsslPrefix = "";
3928
if (opensslDir) {
4029
newEnv.CPPFLAGS = newEnv.CPPFLAGS || "";
41-
newEnv.CPPFLAGS += " -I" + path.join(opensslDir, includeDirName);
30+
newEnv.CPPFLAGS += " -I" + path.join(opensslDir, "include");
4231
newEnv.CPPFLAGS = newEnv.CPPFLAGS.trim();
4332
maybeLibsslPrefix = ` --with-libssl-prefix=${opensslDir}`;
4433
}

package-lock.json

Lines changed: 83 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"mocha": "^5.2.0",
6161
"ramda": "^0.25.0",
6262
"request-promise-native": "^1.0.5",
63+
"tar-fs": "^1.16.3",
6364
"walk": "^2.3.9"
6465
},
6566
"vendorDependencies": {

utils/acquireOpenSSL.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
const fs = require('fs');
2+
const fse = require('fs-extra');
3+
const path = require('path');
4+
const R = require('ramda');
5+
const request = require('request-promise-native');
6+
const stream = require('stream');
7+
const tar = require('tar-fs');
8+
const zlib = require('zlib');
9+
10+
const vendorPath = path.resolve('..', 'vendor');
11+
const distrosFilePath = path.join(vendorPath, 'openssl_distributions.json');
12+
const extractPath = path.join(vendorPath, 'openssl');
13+
14+
const getOSName = () => {
15+
if (process.platform === 'win32') {
16+
if (process.arch === "x64" || process.env.hasOwnProperty("PROCESSOR_ARCHITEW6432")) {
17+
return 'win64';
18+
} else {
19+
return 'win32';
20+
}
21+
} else if (process.platform === 'darwin') {
22+
return 'macOS';
23+
} else {
24+
// We only discover distros for Mac and Windows. We don't care about any other OS.
25+
return 'unknown';
26+
}
27+
}
28+
29+
const getCompilerVersion = () => {
30+
// TODO: Get actual compiler version. For now, just assume latest compiler for distros in openssl_distributions.js
31+
const osName = getOSName();
32+
if (osName === 'win32' || osName === 'win64') {
33+
return 'vs15';
34+
} else if (osName === 'macOS') {
35+
return 'clang-9';
36+
} else {
37+
// We only discover distros for Mac and Windows. We don't care about any other OS.
38+
return 'unknown';
39+
}
40+
}
41+
42+
const getIsDebug = () => true // TODO: Determine if we are GYPing in Debug
43+
44+
const getMatchingDistributionName = () =>
45+
`${getOSName()}-${getCompilerVersion()}-static${getIsDebug() ? '-debug' : ''}`;
46+
47+
const getDistributionsConfig = () =>
48+
fse.readFile(distrosFilePath, 'utf8')
49+
.then(JSON.parse)
50+
51+
const getDistrbutionURLFromConfig = (config) => {
52+
const distName = getMatchingDistributionName();
53+
const distURL = R.propOr(null, distName, config);
54+
55+
if (!distURL) {
56+
return Promise.reject(new Error('No matching distribution for this operating system'));
57+
}
58+
return Promise.resolve(distURL);
59+
}
60+
61+
const fetchFileFromURL = (distUrl) => request({
62+
method: 'GET',
63+
uri: distUrl,
64+
encoding: null,
65+
gzip: true
66+
});
67+
68+
const extractFile = (body) => new Promise((resolve, reject) => {
69+
const streamableBody = new stream.Readable();
70+
streamableBody.push(body);
71+
streamableBody.push(null);
72+
streamableBody
73+
.pipe(zlib.createGunzip())
74+
.on('error', reject)
75+
.pipe(tar.extract(extractPath))
76+
.on('error', reject)
77+
.on('close', resolve);
78+
});
79+
80+
const acquireOpenSSL = () =>
81+
getDistributionsConfig()
82+
.then(getDistrbutionURLFromConfig)
83+
.then(fetchFileFromURL)
84+
.then(extractFile)
85+
.catch((e) => {
86+
console.error(e);
87+
process.exit(1);
88+
});
89+
90+
acquireOpenSSL();

vendor/libgit2.gyp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,7 @@
363363
},
364364
}],
365365
["node_root_dir.split('\\\\')[-1].startswith('iojs')", {
366-
"conditions": [
367-
["target_arch=='x64'", {
368-
"include_dirs": ["win/openssl/include64"]
369-
}, {
370-
"include_dirs": ["win/openssl/include"]
371-
}]
372-
]
366+
"include_dirs": ["openssl/include"]
373367
}]
374368
],
375369
},
@@ -542,18 +536,14 @@
542536
"conditions": [
543537
["OS=='mac' and node_root_dir.split('/')[-1].startswith('iojs')", {
544538
"include_dirs": [
545-
"/usr/local/opt/openssl@1.1/include"
539+
"openssl/include"
546540
]
547541
}],
548542
["OS=='win'", {
549543
"conditions": [
550544
["node_root_dir.split('\\\\')[-1].startswith('iojs')", {
551-
"conditions": [
552-
["target_arch=='x64'", {
553-
"include_dirs": ["win/openssl/include64"]
554-
}, {
555-
"include_dirs": ["win/openssl/include"]
556-
}]
545+
"include_dirs": [
546+
"openssl/include"
557547
]
558548
}, {
559549
"defines": [

0 commit comments

Comments
 (0)