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

Fully static linking #72

Closed
wants to merge 4 commits into from
Closed
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
5 changes: 3 additions & 2 deletions lib/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import { need } from './index.js';

async function main () {
const argv = minimist(process.argv.slice(2), {
boolean: [ 'f', 'b' ],
boolean: [ 'f', 'b', 's' ],
string: [ 'n', 'p', 'a' ]
});
const nodeRange = argv.n || argv._.shift();
const platform = argv.p || argv._.shift();
const arch = argv.a || argv._.shift();
const forceFetch = argv.f;
const forceBuild = argv.b;
const fullyStatic = argv.s;
const local = await need({ nodeRange, platform,
arch, forceFetch, forceBuild });
arch, forceFetch, forceBuild, fullyStatic });
log.info(local);
}

Expand Down
12 changes: 7 additions & 5 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ async function compileOnWindows (nodeVersion, targetArch) {
return path.join(nodePath, 'out/Release/node.exe');
}

async function compileOnUnix (nodeVersion, targetArch) {
export async function compileOnUnix (nodeVersion, targetArch, opts = {}) {
const { fullyStatic } = opts;
const args = [];
const cpu = { x86: 'ia32', x64: 'x64',
armv6: 'arm', armv7: 'arm', arm64: 'arm64', s390x: 's390x' }[targetArch];
Expand All @@ -70,6 +71,7 @@ async function compileOnUnix (nodeVersion, targetArch) {
// also we don't support any kind of debugging
// against packaged apps, hence v8_inspector is useless
const major = nodeVersion.match(/^v?(\d+)/)[1] | 0;
if (fullyStatic === true) args.push('--fully-static');
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');
Expand All @@ -85,22 +87,22 @@ async function compileOnUnix (nodeVersion, targetArch) {
return output;
}

async function compile (nodeVersion, targetArch) {
async function compile (nodeVersion, targetArch, opts) {
log.info('Compiling Node.js from sources...');
const win = hostPlatform === 'win';
if (win) return await compileOnWindows(nodeVersion, targetArch);
return await compileOnUnix(nodeVersion, targetArch);
return await compileOnUnix(nodeVersion, targetArch, opts);
}

export default async function build (
nodeVersion, targetArch, local
nodeVersion, targetArch, local, opts
) {
await remove(buildPath);
await mkdirp(buildPath);
await gitClone();
await gitResetHard(nodeVersion);
await applyPatches(nodeVersion);
const output = await compile(nodeVersion, targetArch);
const output = await compile(nodeVersion, targetArch, opts);
await mkdirp(path.dirname(local));
await copyFile(output, local);
await remove(buildPath);
Expand Down
7 changes: 5 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { version } from '../package.json';
const cloud = new Cloud({ owner: 'zeit', repo: 'pkg-fetch' });

export async function need (opts = {}) { // eslint-disable-line complexity
let { nodeRange, platform, arch, forceFetch, forceBuild, dryRun } = opts;
let { nodeRange, platform, arch, forceFetch, forceBuild, fullyStatic, dryRun } = opts;
if (!nodeRange) throw wasReported('nodeRange not specified');
if (!platform) throw wasReported('platform not specified');
if (!arch) throw wasReported('arch not specified');
Expand Down Expand Up @@ -66,6 +66,9 @@ export async function need (opts = {}) { // eslint-disable-line complexity
if (await cloud.download(remote, fetched)) return fetched;
fetchFailed = true;
}
if (fullyStatic) {
log.info('Using "fully static" linking');
}
if (!dryRun && fetchFailed) {
log.info('Not found in GitHub releases:', JSON.stringify(remote));
}
Expand All @@ -83,7 +86,7 @@ export async function need (opts = {}) { // eslint-disable-line complexity
}

if (dryRun) return 'built';
await build(nodeVersion, arch, built);
await build(nodeVersion, arch, built, opts);
return built;
}

Expand Down
13 changes: 13 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@
Github Releases page of this project contains base binaries,
used by `pkg` to create executables. `pkg-fetch` npm package
downloads base binaries or compiles them from source.

# Usage

## Program Arguments

Argument | Description | Example Value
-------- | ----------- | -------------
f | Forces a fetch
b | Forces a build
s | Use fully static linking
n | Node range | `node10`
p | Platform | `macos`
a | Architecture | `x64`