@yao-pkg/pkg-fetch 3.6.0 → 3.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib-es5/build.js CHANGED
@@ -1,90 +1,35 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
- return new (P || (P = Promise))(function (resolve, reject) {
16
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
- step((generator = generator.apply(thisArg, _arguments || [])).next());
20
- });
21
- };
22
- var __generator = (this && this.__generator) || function (thisArg, body) {
23
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
- function verb(n) { return function (v) { return step([n, v]); }; }
26
- function step(op) {
27
- if (f) throw new TypeError("Generator is already executing.");
28
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
- if (y = 0, t) op = [op[0] & 2, t.value];
31
- switch (op[0]) {
32
- case 0: case 1: t = op; break;
33
- case 4: _.label++; return { value: op[1], done: false };
34
- case 5: _.label++; y = op[1]; op = [0]; continue;
35
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
- default:
37
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
- if (t[2]) _.ops.pop();
42
- _.trys.pop(); continue;
43
- }
44
- op = body.call(thisArg, _);
45
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
- }
48
- };
49
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
- if (ar || !(i in from)) {
52
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
- ar[i] = from[i];
54
- }
55
- }
56
- return to.concat(ar || Array.prototype.slice.call(from));
57
- };
58
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
59
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
60
4
  };
61
5
  Object.defineProperty(exports, "__esModule", { value: true });
62
6
  exports.prepBuildPath = exports.fetchExtractApply = void 0;
63
- var zlib_1 = require("zlib");
64
- var crypto_1 = __importDefault(require("crypto"));
65
- var fs_extra_1 = __importDefault(require("fs-extra"));
66
- var os_1 = __importDefault(require("os"));
67
- var path_1 = __importDefault(require("path"));
68
- var stream_1 = require("stream");
69
- var util_1 = require("util");
70
- var tar_fs_1 = __importDefault(require("tar-fs"));
71
- var places_1 = require("./places");
72
- var utils_1 = require("./utils");
73
- var system_1 = require("./system");
74
- var log_1 = require("./log");
75
- var patches_json_1 = __importDefault(require("../patches/patches.json"));
76
- var buildPath = path_1.default.resolve(process.env.PKG_BUILD_PATH ||
77
- path_1.default.join(os_1.default.tmpdir(), "pkg.".concat(crypto_1.default.randomBytes(12).toString('hex'))));
78
- var nodePath = path_1.default.join(buildPath, 'node');
79
- var patchesPath = path_1.default.resolve(__dirname, '../patches');
80
- var nodeRepo = 'https://nodejs.org/dist';
81
- var nodeArchivePath = path_1.default.join(places_1.cachePath, 'node');
7
+ const zlib_1 = require("zlib");
8
+ const crypto_1 = __importDefault(require("crypto"));
9
+ const fs_1 = require("fs");
10
+ const promises_1 = require("fs/promises");
11
+ const os_1 = __importDefault(require("os"));
12
+ const path_1 = __importDefault(require("path"));
13
+ const stream_1 = require("stream");
14
+ const util_1 = require("util");
15
+ const tar_fs_1 = __importDefault(require("tar-fs"));
16
+ const places_1 = require("./places");
17
+ const utils_1 = require("./utils");
18
+ const system_1 = require("./system");
19
+ const log_1 = require("./log");
20
+ const patches_json_1 = __importDefault(require("../patches/patches.json"));
21
+ const buildPath = path_1.default.resolve(process.env.PKG_BUILD_PATH ||
22
+ path_1.default.join(os_1.default.tmpdir(), `pkg.${crypto_1.default.randomBytes(12).toString('hex')}`));
23
+ const nodePath = path_1.default.join(buildPath, 'node');
24
+ const patchesPath = path_1.default.resolve(__dirname, '../patches');
25
+ const nodeRepo = 'https://nodejs.org/dist';
26
+ const nodeArchivePath = path_1.default.join(places_1.cachePath, 'node');
82
27
  function getMajor(nodeVersion) {
83
- var _a = nodeVersion.match(/^v?(\d+)/) || ['', 0], version = _a[1];
28
+ const [, version] = nodeVersion.match(/^v?(\d+)/) || ['', 0];
84
29
  return Number(version) | 0;
85
30
  }
86
- function getConfigureArgs(major, targetPlatform) {
87
- var args = [];
31
+ function getConfigureArgs(major, targetPlatform, targetArch) {
32
+ const args = [];
88
33
  // first of all v8_inspector introduces the use
89
34
  // of `prime_rehash_policy` symbol that requires
90
35
  // GLIBCXX_3.4.18 on some systems
@@ -100,8 +45,11 @@ function getConfigureArgs(major, targetPlatform) {
100
45
  args.push('--fully-static');
101
46
  }
102
47
  // Link Time Optimization
48
+ // Skipped on macOS: LTO makes the link phase enormously slow and pushes the
49
+ // build past GitHub Actions' 6h job limit (worst on the Intel x64 runner).
50
+ // See yao-pkg/pkg-fetch#170.
103
51
  if (major >= 12) {
104
- if (system_1.hostPlatform !== 'win') {
52
+ if (system_1.hostPlatform !== 'win' && targetPlatform !== 'macos') {
105
53
  args.push('--enable-lto');
106
54
  }
107
55
  }
@@ -115,322 +63,205 @@ function getConfigureArgs(major, targetPlatform) {
115
63
  // bundled npm package manager
116
64
  args.push('--without-npm');
117
65
  // Small ICU
118
- args.push('--with-intl=small-icu');
66
+ if (system_1.hostPlatform !== 'win' || major < 24) {
67
+ args.push('--with-intl=small-icu');
68
+ }
119
69
  // Workaround for nodejs/node#39313
120
70
  // All supported macOS versions have zlib as a system library
121
71
  if (targetPlatform === 'macos') {
122
72
  args.push('--shared-zlib');
123
73
  }
74
+ // macos cross-build from arm64 to x64
75
+ if (targetPlatform === 'macos' && system_1.hostArch === 'arm64' && targetArch === 'x64') {
76
+ args.push('--dest-os=mac');
77
+ args.push('--dest-cpu=x64');
78
+ }
124
79
  return args;
125
80
  }
126
- function tarFetch(nodeVersion) {
127
- return __awaiter(this, void 0, void 0, function () {
128
- var distUrl, tarName, archivePath, hashPath, _a, _b, _c;
129
- return __generator(this, function (_d) {
130
- switch (_d.label) {
131
- case 0:
132
- log_1.log.info('Fetching Node.js source archive from nodejs.org...');
133
- distUrl = "".concat(nodeRepo, "/").concat(nodeVersion);
134
- tarName = "node-".concat(nodeVersion, ".tar.gz");
135
- archivePath = path_1.default.join(nodeArchivePath, tarName);
136
- hashPath = path_1.default.join(nodeArchivePath, "".concat(tarName, ".sha256sum"));
137
- if (fs_extra_1.default.existsSync(hashPath) && fs_extra_1.default.existsSync(archivePath)) {
138
- return [2 /*return*/];
139
- }
140
- return [4 /*yield*/, fs_extra_1.default.remove(hashPath).catch(function () { return undefined; })];
141
- case 1:
142
- _d.sent();
143
- return [4 /*yield*/, fs_extra_1.default.remove(archivePath).catch(function () { return undefined; })];
144
- case 2:
145
- _d.sent();
146
- return [4 /*yield*/, (0, utils_1.downloadUrl)("".concat(distUrl, "/SHASUMS256.txt"), hashPath)];
147
- case 3:
148
- _d.sent();
149
- _b = (_a = fs_extra_1.default).writeFile;
150
- _c = [hashPath];
151
- return [4 /*yield*/, fs_extra_1.default.readFile(hashPath, 'utf8')];
152
- case 4: return [4 /*yield*/, _b.apply(_a, _c.concat([(_d.sent())
153
- .split('\n')
154
- .filter(function (l) { return l.includes(tarName); })[0]]))];
155
- case 5:
156
- _d.sent();
157
- return [4 /*yield*/, (0, utils_1.downloadUrl)("".concat(distUrl, "/").concat(tarName), archivePath)];
158
- case 6:
159
- _d.sent();
160
- return [2 /*return*/];
161
- }
162
- });
163
- });
81
+ async function tarFetch(nodeVersion) {
82
+ log_1.log.info('Fetching Node.js source archive from nodejs.org...');
83
+ const distUrl = `${nodeRepo}/${nodeVersion}`;
84
+ const tarName = `node-${nodeVersion}.tar.gz`;
85
+ const archivePath = path_1.default.join(nodeArchivePath, tarName);
86
+ const hashPath = path_1.default.join(nodeArchivePath, `${tarName}.sha256sum`);
87
+ if ((0, fs_1.existsSync)(hashPath) && (0, fs_1.existsSync)(archivePath)) {
88
+ return;
89
+ }
90
+ await (0, promises_1.rm)(hashPath, { recursive: true, force: true }).catch(() => undefined);
91
+ await (0, promises_1.rm)(archivePath, { recursive: true, force: true }).catch(() => undefined);
92
+ await (0, utils_1.downloadUrl)(`${distUrl}/SHASUMS256.txt`, hashPath);
93
+ await (0, promises_1.writeFile)(hashPath, (await (0, promises_1.readFile)(hashPath, 'utf8'))
94
+ .split('\n')
95
+ .filter((l) => l.includes(tarName))[0]);
96
+ await (0, utils_1.downloadUrl)(`${distUrl}/${tarName}`, archivePath);
164
97
  }
165
- function tarExtract(nodeVersion, suppressTarOutput) {
166
- return __awaiter(this, void 0, void 0, function () {
167
- var tarName, expectedHash, actualHash, pipe, source, gunzip, extract;
168
- return __generator(this, function (_a) {
169
- switch (_a.label) {
170
- case 0:
171
- log_1.log.info('Extracting Node.js source archive...');
172
- tarName = "node-".concat(nodeVersion, ".tar.gz");
173
- return [4 /*yield*/, fs_extra_1.default.readFile(path_1.default.join(nodeArchivePath, "".concat(tarName, ".sha256sum")), 'utf8')];
174
- case 1:
175
- expectedHash = (_a.sent()).split(' ')[0];
176
- return [4 /*yield*/, (0, utils_1.hash)(path_1.default.join(nodeArchivePath, tarName))];
177
- case 2:
178
- actualHash = _a.sent();
179
- if (!(expectedHash !== actualHash)) return [3 /*break*/, 5];
180
- return [4 /*yield*/, fs_extra_1.default.remove(path_1.default.join(nodeArchivePath, tarName))];
181
- case 3:
182
- _a.sent();
183
- return [4 /*yield*/, fs_extra_1.default.remove(path_1.default.join(nodeArchivePath, "".concat(tarName, ".sha256sum")))];
184
- case 4:
185
- _a.sent();
186
- throw (0, log_1.wasReported)("Hash mismatch for ".concat(tarName));
187
- case 5:
188
- pipe = (0, util_1.promisify)(stream_1.pipeline);
189
- source = fs_extra_1.default.createReadStream(path_1.default.join(nodeArchivePath, tarName));
190
- gunzip = (0, zlib_1.createGunzip)();
191
- extract = tar_fs_1.default.extract(nodePath, {
192
- strip: 1,
193
- map: function (header) {
194
- if (!suppressTarOutput) {
195
- log_1.log.info(header.name);
196
- }
197
- return header;
198
- },
199
- });
200
- return [4 /*yield*/, pipe(source, gunzip, extract)];
201
- case 6:
202
- _a.sent();
203
- return [2 /*return*/];
204
- }
98
+ async function tarExtract(nodeVersion, suppressTarOutput) {
99
+ log_1.log.info('Extracting Node.js source archive...');
100
+ const tarName = `node-${nodeVersion}.tar.gz`;
101
+ const expectedHash = (await (0, promises_1.readFile)(path_1.default.join(nodeArchivePath, `${tarName}.sha256sum`), 'utf8')).split(' ')[0];
102
+ const actualHash = await (0, utils_1.hash)(path_1.default.join(nodeArchivePath, tarName));
103
+ if (expectedHash !== actualHash) {
104
+ await (0, promises_1.rm)(path_1.default.join(nodeArchivePath, tarName), {
105
+ recursive: true,
106
+ force: true,
205
107
  });
206
- });
207
- }
208
- function applyPatches(nodeVersion) {
209
- return __awaiter(this, void 0, void 0, function () {
210
- var storedPatches, storedPatch, patches, _i, patches_1, patch, patchPath, args;
211
- return __generator(this, function (_a) {
212
- switch (_a.label) {
213
- case 0:
214
- log_1.log.info('Applying patches');
215
- storedPatches = patches_json_1.default[nodeVersion];
216
- storedPatch = 'patches' in storedPatches ? storedPatches.patches : storedPatches;
217
- patches = 'sameAs' in storedPatch
218
- ? patches_json_1.default[storedPatch.sameAs]
219
- : storedPatch;
220
- _i = 0, patches_1 = patches;
221
- _a.label = 1;
222
- case 1:
223
- if (!(_i < patches_1.length)) return [3 /*break*/, 4];
224
- patch = patches_1[_i];
225
- patchPath = path_1.default.join(patchesPath, patch);
226
- args = ['-p1', '-i', patchPath];
227
- return [4 /*yield*/, (0, utils_1.spawn)('patch', args, { cwd: nodePath, stdio: 'inherit' })];
228
- case 2:
229
- _a.sent();
230
- _a.label = 3;
231
- case 3:
232
- _i++;
233
- return [3 /*break*/, 1];
234
- case 4: return [2 /*return*/];
235
- }
108
+ await (0, promises_1.rm)(path_1.default.join(nodeArchivePath, `${tarName}.sha256sum`), {
109
+ recursive: true,
110
+ force: true,
236
111
  });
237
- });
238
- }
239
- function fetchExtractApply(nodeVersion, quietExtraction) {
240
- return __awaiter(this, void 0, void 0, function () {
241
- return __generator(this, function (_a) {
242
- switch (_a.label) {
243
- case 0: return [4 /*yield*/, tarFetch(nodeVersion)];
244
- case 1:
245
- _a.sent();
246
- return [4 /*yield*/, tarExtract(nodeVersion, quietExtraction)];
247
- case 2:
248
- _a.sent();
249
- return [4 /*yield*/, applyPatches(nodeVersion)];
250
- case 3:
251
- _a.sent();
252
- return [2 /*return*/];
112
+ throw (0, log_1.wasReported)(`Hash mismatch for ${tarName}`);
113
+ }
114
+ const pipe = (0, util_1.promisify)(stream_1.pipeline);
115
+ const source = (0, fs_1.createReadStream)(path_1.default.join(nodeArchivePath, tarName));
116
+ const gunzip = (0, zlib_1.createGunzip)();
117
+ const extract = tar_fs_1.default.extract(nodePath, {
118
+ strip: 1,
119
+ map: (header) => {
120
+ if (!suppressTarOutput) {
121
+ // disabled for now - can't get cmdline flag to work with all builds
122
+ // log.info(header.name);
253
123
  }
254
- });
124
+ return header;
125
+ },
255
126
  });
127
+ await pipe(source, gunzip, extract);
128
+ }
129
+ async function applyPatches(nodeVersion) {
130
+ log_1.log.info('Applying patches');
131
+ const storedPatches = patches_json_1.default[nodeVersion];
132
+ const storedPatch = 'patches' in storedPatches ? storedPatches.patches : storedPatches;
133
+ const patches = 'sameAs' in storedPatch
134
+ ? patches_json_1.default[storedPatch.sameAs]
135
+ : storedPatch;
136
+ for (const patch of patches) {
137
+ const patchPath = path_1.default.join(patchesPath, patch);
138
+ const args = ['-p1', '-i', patchPath];
139
+ await (0, utils_1.spawn)('patch', args, { cwd: nodePath, stdio: 'inherit' });
140
+ }
141
+ }
142
+ async function fetchExtractApply(nodeVersion, quietExtraction) {
143
+ await tarFetch(nodeVersion);
144
+ await tarExtract(nodeVersion, quietExtraction);
145
+ await applyPatches(nodeVersion);
256
146
  }
257
147
  exports.fetchExtractApply = fetchExtractApply;
258
- function compileOnWindows(nodeVersion, targetArch, targetPlatform) {
259
- return __awaiter(this, void 0, void 0, function () {
260
- var args, major, config_flags;
261
- return __generator(this, function (_a) {
262
- switch (_a.label) {
263
- case 0:
264
- args = ['/c', 'vcbuild.bat', targetArch];
265
- major = getMajor(nodeVersion);
266
- config_flags = getConfigureArgs(major, targetPlatform);
267
- // The dtrace and etw support was removed in https://github.com/nodejs/node/commit/aa3a572e6bee116cde69508dc29478b40f40551a
268
- if (major <= 18) {
269
- // Event Tracing for Windows
270
- args.push('noetw');
271
- }
272
- // Performance counters on Windows
273
- if (major <= 10) {
274
- args.push('noperfctr');
275
- }
276
- // Link Time Code Generation
277
- if (major >= 12) {
278
- args.push('ltcg');
279
- }
280
- // Can't cross compile for arm64 with small-icu
281
- if (system_1.hostArch !== targetArch &&
282
- !config_flags.includes('--with-intl=full-icu')) {
283
- config_flags.push('--without-intl');
284
- }
285
- return [4 /*yield*/, (0, utils_1.spawn)('cmd', args, {
286
- cwd: nodePath,
287
- env: __assign(__assign({}, process.env), { config_flags: config_flags.join(' ') }),
288
- stdio: 'inherit',
289
- })];
290
- case 1:
291
- _a.sent();
292
- if (major <= 10) {
293
- return [2 /*return*/, path_1.default.join(nodePath, 'Release/node.exe')];
294
- }
295
- return [2 /*return*/, path_1.default.join(nodePath, 'out/Release/node.exe')];
296
- }
297
- });
148
+ async function compileOnWindows(nodeVersion, targetArch, targetPlatform) {
149
+ const args = ['/c', 'vcbuild.bat', targetArch];
150
+ const major = getMajor(nodeVersion);
151
+ const config_flags = getConfigureArgs(major, targetPlatform, targetArch);
152
+ // The dtrace and etw support was removed in https://github.com/nodejs/node/commit/aa3a572e6bee116cde69508dc29478b40f40551a
153
+ if (major <= 18) {
154
+ // Event Tracing for Windows
155
+ args.push('noetw');
156
+ }
157
+ // Performance counters on Windows
158
+ if (major <= 10) {
159
+ args.push('noperfctr');
160
+ }
161
+ // Link Time Code Generation
162
+ if (major >= 12) {
163
+ args.push('ltcg');
164
+ }
165
+ // Node24 builds on Windows crash with small-icu at icudat codegen
166
+ // workaround for now is to enable full-icu
167
+ // TODO check with newer node/tooling/gh-image versions
168
+ if (major >= 24) {
169
+ args.push('full-icu');
170
+ }
171
+ await (0, utils_1.spawn)('cmd', args, {
172
+ cwd: nodePath,
173
+ env: { ...process.env, config_flags: config_flags.join(' ') },
174
+ stdio: 'inherit',
298
175
  });
176
+ if (major <= 10) {
177
+ return path_1.default.join(nodePath, 'Release/node.exe');
178
+ }
179
+ return path_1.default.join(nodePath, 'out/Release/node.exe');
299
180
  }
300
- var _a = process.env.MAKE_JOB_COUNT, MAKE_JOB_COUNT = _a === void 0 ? os_1.default.cpus().length : _a;
301
- function compileOnUnix(nodeVersion, targetArch, targetPlatform) {
302
- return __awaiter(this, void 0, void 0, function () {
303
- var args, cpu, _a, _b, CFLAGS, _c, CXXFLAGS, output;
304
- return __generator(this, function (_d) {
305
- switch (_d.label) {
306
- case 0:
307
- args = [];
308
- cpu = {
309
- x86: 'ia32',
310
- x64: 'x64',
311
- armv6: 'arm',
312
- armv7: 'arm',
313
- arm64: 'arm64',
314
- ppc64: 'ppc64',
315
- s390x: 's390x',
316
- }[targetArch];
317
- if (cpu) {
318
- args.push('--dest-cpu', cpu);
319
- }
320
- if (targetArch === 'armv7') {
321
- _a = process.env, _b = _a.CFLAGS, CFLAGS = _b === void 0 ? '' : _b, _c = _a.CXXFLAGS, CXXFLAGS = _c === void 0 ? '' : _c;
322
- process.env.CFLAGS = "".concat(CFLAGS, " -marm -mcpu=cortex-a7");
323
- process.env.CXXFLAGS = "".concat(CXXFLAGS, " -marm -mcpu=cortex-a7");
324
- args.push('--with-arm-float-abi=hard');
325
- args.push('--with-arm-fpu=vfpv3');
326
- }
327
- if (system_1.hostArch !== targetArch) {
328
- log_1.log.warn('Cross compiling!');
329
- log_1.log.warn('You are responsible for appropriate env like CC, CC_host, etc.');
330
- args.push('--cross-compiling');
331
- }
332
- args.push.apply(args, getConfigureArgs(getMajor(nodeVersion), targetPlatform));
333
- // TODO same for windows?
334
- return [4 /*yield*/, (0, utils_1.spawn)('/bin/sh', __spreadArray(['./configure'], args, true), {
335
- cwd: nodePath,
336
- stdio: 'inherit',
337
- })];
338
- case 1:
339
- // TODO same for windows?
340
- _d.sent();
341
- return [4 /*yield*/, (0, utils_1.spawn)(system_1.hostPlatform === 'freebsd' ? 'gmake' : 'make', ['-j', String(MAKE_JOB_COUNT)], {
342
- cwd: nodePath,
343
- stdio: 'inherit',
344
- })];
345
- case 2:
346
- _d.sent();
347
- output = path_1.default.join(nodePath, 'out/Release/node');
348
- return [4 /*yield*/, (0, utils_1.spawn)(process.env.STRIP || 'strip', __spreadArray(__spreadArray([], (targetPlatform === 'macos' ? ['-x'] : []), true), [output], false), {
349
- stdio: 'inherit',
350
- })];
351
- case 3:
352
- _d.sent();
353
- if (!(targetPlatform === 'macos')) return [3 /*break*/, 5];
354
- // Newer versions of Apple Clang automatically ad-hoc sign the compiled executable.
355
- // However, for final executable to be signable, base binary MUST NOT have an existing signature.
356
- return [4 /*yield*/, (0, utils_1.spawn)('codesign', ['--remove-signature', output], {
357
- stdio: 'inherit',
358
- })];
359
- case 4:
360
- // Newer versions of Apple Clang automatically ad-hoc sign the compiled executable.
361
- // However, for final executable to be signable, base binary MUST NOT have an existing signature.
362
- _d.sent();
363
- _d.label = 5;
364
- case 5: return [2 /*return*/, output];
365
- }
366
- });
181
+ const { MAKE_JOB_COUNT = os_1.default.cpus().length } = process.env;
182
+ async function compileOnUnix(nodeVersion, targetArch, targetPlatform) {
183
+ const args = [];
184
+ const cpu = {
185
+ x86: 'ia32',
186
+ x64: 'x64',
187
+ armv6: 'arm',
188
+ armv7: 'arm',
189
+ arm64: 'arm64',
190
+ ppc64: 'ppc64',
191
+ s390x: 's390x',
192
+ }[targetArch];
193
+ if (cpu) {
194
+ args.push('--dest-cpu', cpu);
195
+ }
196
+ if (targetArch === 'armv7') {
197
+ const { CFLAGS = '', CXXFLAGS = '' } = process.env;
198
+ process.env.CFLAGS = `${CFLAGS} -marm -mcpu=cortex-a7 -mfpu=vfpv3`;
199
+ process.env.CXXFLAGS = `${CXXFLAGS} -marm -mcpu=cortex-a7 -mfpu=vfpv3`;
200
+ args.push('--with-arm-float-abi=hard');
201
+ args.push('--with-arm-fpu=vfpv3');
202
+ }
203
+ // macos cross-build from arm64 to x64
204
+ if (targetPlatform === "macos" && system_1.hostArch === 'arm64' && targetArch === 'x64') {
205
+ const { CFLAGS = '', CXXFLAGS = '', LDFLAGS = '' } = process.env;
206
+ process.env.CFLAGS = `${CFLAGS} -arch x86_64`;
207
+ process.env.CXXFLAGS = `${CXXFLAGS} -arch x86_64`;
208
+ process.env.LDFLAGS = `${LDFLAGS} -arch x86_64`;
209
+ }
210
+ if (system_1.hostArch !== targetArch) {
211
+ log_1.log.warn('Cross compiling!');
212
+ log_1.log.warn('You are responsible for appropriate env like CC, CC_host, etc.');
213
+ args.push('--cross-compiling');
214
+ }
215
+ args.push(...getConfigureArgs(getMajor(nodeVersion), targetPlatform, targetArch));
216
+ log_1.log.info("Running configure with: ", args.join(" "));
217
+ // TODO same for windows?
218
+ await (0, utils_1.spawn)('/bin/sh', ['./configure', ...args], {
219
+ cwd: nodePath,
220
+ stdio: 'inherit',
367
221
  });
368
- }
369
- function compile(nodeVersion, targetArch, targetPlatform) {
370
- return __awaiter(this, void 0, void 0, function () {
371
- var win;
372
- return __generator(this, function (_a) {
373
- log_1.log.info('Compiling Node.js from sources...');
374
- win = system_1.hostPlatform === 'win';
375
- if (win) {
376
- return [2 /*return*/, compileOnWindows(nodeVersion, targetArch, targetPlatform)];
377
- }
378
- return [2 /*return*/, compileOnUnix(nodeVersion, targetArch, targetPlatform)];
379
- });
222
+ await (0, utils_1.spawn)(system_1.hostPlatform === 'freebsd' ? 'gmake' : 'make', ['-j', String(MAKE_JOB_COUNT)], {
223
+ cwd: nodePath,
224
+ stdio: 'inherit',
380
225
  });
381
- }
382
- function prepBuildPath() {
383
- return __awaiter(this, void 0, void 0, function () {
384
- return __generator(this, function (_a) {
385
- switch (_a.label) {
386
- case 0: return [4 /*yield*/, fs_extra_1.default.remove(buildPath)];
387
- case 1:
388
- _a.sent();
389
- return [4 /*yield*/, fs_extra_1.default.mkdirp(nodePath)];
390
- case 2:
391
- _a.sent();
392
- return [4 /*yield*/, fs_extra_1.default.mkdirp(nodeArchivePath)];
393
- case 3:
394
- _a.sent();
395
- return [2 /*return*/];
396
- }
397
- });
226
+ const output = path_1.default.join(nodePath, 'out/Release/node');
227
+ await (0, utils_1.spawn)(process.env.STRIP || 'strip',
228
+ // global symbols are required for native bindings on macOS
229
+ [...(targetPlatform === 'macos' ? ['-x'] : []), output], {
230
+ stdio: 'inherit',
398
231
  });
232
+ if (targetPlatform === 'macos') {
233
+ // Newer versions of Apple Clang automatically ad-hoc sign the compiled executable.
234
+ // However, for final executable to be signable, base binary MUST NOT have an existing signature.
235
+ await (0, utils_1.spawn)('codesign', ['--remove-signature', output], {
236
+ stdio: 'inherit',
237
+ });
238
+ }
239
+ return output;
240
+ }
241
+ async function compile(nodeVersion, targetArch, targetPlatform) {
242
+ log_1.log.info('Compiling Node.js from sources...');
243
+ const win = system_1.hostPlatform === 'win';
244
+ if (win) {
245
+ return compileOnWindows(nodeVersion, targetArch, targetPlatform);
246
+ }
247
+ return compileOnUnix(nodeVersion, targetArch, targetPlatform);
248
+ }
249
+ async function prepBuildPath() {
250
+ await (0, promises_1.rm)(buildPath, { recursive: true, force: true });
251
+ await (0, promises_1.mkdir)(nodePath, { recursive: true });
252
+ await (0, promises_1.mkdir)(nodeArchivePath, { recursive: true });
399
253
  }
400
254
  exports.prepBuildPath = prepBuildPath;
401
- function build(nodeVersion, targetArch, targetPlatform, local) {
402
- return __awaiter(this, void 0, void 0, function () {
403
- var output, outputHash;
404
- return __generator(this, function (_a) {
405
- switch (_a.label) {
406
- case 0: return [4 /*yield*/, prepBuildPath()];
407
- case 1:
408
- _a.sent();
409
- return [4 /*yield*/, fetchExtractApply(nodeVersion, false)];
410
- case 2:
411
- _a.sent();
412
- return [4 /*yield*/, compile(nodeVersion, targetArch, targetPlatform)];
413
- case 3:
414
- output = _a.sent();
415
- return [4 /*yield*/, (0, utils_1.hash)(output)];
416
- case 4:
417
- outputHash = _a.sent();
418
- return [4 /*yield*/, fs_extra_1.default.mkdirp(path_1.default.dirname(local))];
419
- case 5:
420
- _a.sent();
421
- return [4 /*yield*/, fs_extra_1.default.copy(output, local)];
422
- case 6:
423
- _a.sent();
424
- return [4 /*yield*/, fs_extra_1.default.promises.writeFile("".concat(local, ".sha256sum"), "".concat(outputHash, " ").concat(path_1.default.basename(local), "\n"))];
425
- case 7:
426
- _a.sent();
427
- return [4 /*yield*/, fs_extra_1.default.remove(buildPath)];
428
- case 8:
429
- _a.sent();
430
- return [2 /*return*/];
431
- }
432
- });
433
- });
255
+ async function build(nodeVersion, targetArch, targetPlatform, local) {
256
+ await prepBuildPath();
257
+ await fetchExtractApply(nodeVersion, false);
258
+ const output = await compile(nodeVersion, targetArch, targetPlatform);
259
+ const outputHash = await (0, utils_1.hash)(output);
260
+ await (0, promises_1.mkdir)(path_1.default.dirname(local), { recursive: true });
261
+ await (0, promises_1.cp)(output, local);
262
+ await (0, promises_1.writeFile)(`${local}.sha256sum`, `${outputHash} ${path_1.default.basename(local)}
263
+ `);
264
+ await (0, promises_1.rm)(buildPath, { recursive: true, force: true });
434
265
  }
435
266
  exports.default = build;
436
267
  //# sourceMappingURL=build.js.map