diff --git a/lib/bin.js b/lib/bin.js index 2bfe4d6d..84492d7e 100755 --- a/lib/bin.js +++ b/lib/bin.js @@ -6,7 +6,7 @@ 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(); @@ -14,8 +14,9 @@ async function main () { 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); } diff --git a/lib/build.js b/lib/build.js index 46d1c237..f8ef8228 100644 --- a/lib/build.js +++ b/lib/build.js @@ -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]; @@ -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'); @@ -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); diff --git a/lib/index.js b/lib/index.js index 792dc885..e497afd7 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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'); @@ -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)); } @@ -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; } diff --git a/readme.md b/readme.md index ed6d3a7f..28d824b5 100644 --- a/readme.md +++ b/readme.md @@ -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`