Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

build: tweak Node configure flags #160

Merged
merged 5 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
AR: /usr/bin/aarch64-linux-gnu-ar
NM: /usr/bin/aarch64-linux-gnu-nm
READELF: /usr/bin/aarch64-linux-gnu-readelf
STRIP: /usr/bin/aarch64-linux-gnu-strip
CC_host: /usr/bin/gcc
CXX_host: /usr/bin/g++
AR_host: /usr/bin/ar
Expand Down
73 changes: 51 additions & 22 deletions lib/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,37 @@ function getMajor(nodeVersion: string) {
return Number(version) | 0;
}

function getConfigureArgs(major: number): string[] {
const args: string[] = [];

// first of all v8_inspector introduces the use
// of `prime_rehash_policy` symbol that requires
// GLIBCXX_3.4.18 on some systems
// also we don't support any kind of debugging
// against packaged apps, hence v8_inspector is useless
args.push('--without-inspector');

// https://github.com/mhart/alpine-node/blob/base-7.4.0/Dockerfile#L33
if (hostPlatform === 'alpine') {
args.push('--without-snapshot');
}

// Link Time Optimization
if (major >= 12) {
if (hostPlatform === 'linux' || hostPlatform === 'alpine') {
args.push('--enable-lto');
}
}

// DTrace
args.push('--without-dtrace');

// bundled npm package manager
args.push('--without-npm');

return args;
}

async function gitClone(nodeVersion: string) {
log.info('Cloning Node.js repository from GitHub...');

Expand Down Expand Up @@ -77,14 +108,27 @@ async function applyPatches(nodeVersion: string) {

async function compileOnWindows(nodeVersion: string, targetArch: string) {
const args = [];
args.push('/c', 'vcbuild.bat', targetArch, 'noetw');
args.push('/c', 'vcbuild.bat', targetArch);
const major = getMajor(nodeVersion);

// Event Tracing for Windows
args.push('noetw');

// Performance counters on Windows
if (major <= 10) {
args.push('nosign', 'noperfctr');
args.push('noperfctr');
}

spawnSync('cmd', args, { cwd: nodePath, stdio: 'inherit' });
// Link Time Code Generation
if (major >= 12) {
args.push('ltcg');
}

spawnSync('cmd', args, {
cwd: nodePath,
env: { ...process.env, config_flags: getConfigureArgs(major).join(' ') },
stdio: 'inherit',
});

if (major <= 10) {
return path.join(nodePath, 'Release/node.exe');
Expand Down Expand Up @@ -117,21 +161,7 @@ async function compileOnUnix(nodeVersion: string, targetArch: string) {
args.push('--cross-compiling');
}

// first of all v8_inspector introduces the use
// of `prime_rehash_policy` symbol that requires
// GLIBCXX_3.4.18 on some systems
// also we don't support any kind of debugging
// against packaged apps, hence v8_inspector is useless
const major = getMajor(nodeVersion);

if (major >= 6) {
args.push('--without-inspector');
}

// https://github.com/mhart/alpine-node/blob/base-7.4.0/Dockerfile#L33
if (hostPlatform === 'alpine') {
args.push('--without-snapshot');
}
args.concat(getConfigureArgs(getMajor(nodeVersion)));

// TODO same for windows?
spawnSync('./configure', args, { cwd: nodePath, stdio: 'inherit' });
Expand All @@ -147,10 +177,9 @@ async function compileOnUnix(nodeVersion: string, targetArch: string) {

const output = path.join(nodePath, 'out/Release/node');

// https://github.com/mhart/alpine-node/blob/base-7.4.0/Dockerfile#L36
if (hostPlatform === 'alpine') {
spawnSync('paxctl', ['-cm', output], { stdio: 'inherit' });
}
spawnSync(process.env.STRIP || 'strip', [output], {
stdio: 'inherit',
});

return output;
}
Expand Down