Commit 746a8b47 authored by Matt Mastracci's avatar Matt Mastracci

Enable rust-lld + ICF on macOS, use util.parseArgs for arg parsing

- Add rust-lld linker and --icf=all for macOS targets in .cargo/config.toml
- Replace manual switch/case arg parsing with Node.js util.parseArgs
  (zero dependencies, available since Node 16.17)
parent ce099ee1
...@@ -51,10 +51,9 @@ rustflags = ["-Clink-arg=--icf=all"] ...@@ -51,10 +51,9 @@ rustflags = ["-Clink-arg=--icf=all"]
# Windows: statically link the CRT and opt into rust-lld for fast linking. # Windows: statically link the CRT and opt into rust-lld for fast linking.
# rust-lld is not yet the default on Windows (tracking: rust-lang/rust#71520). # rust-lld is not yet the default on Windows (tracking: rust-lang/rust#71520).
# ICF (Identical Code Folding) reduces binary size with negligible build time impact.
[target.'cfg(windows)'] [target.'cfg(windows)']
linker = "rust-lld" linker = "rust-lld"
rustflags = ["-Ctarget-feature=+crt-static", "-Clink-arg=-Wl,--icf=all"] rustflags = ["-Ctarget-feature=+crt-static"]
# Musl targets: disable static CRT linking. We produce dynamic .node shared # Musl targets: disable static CRT linking. We produce dynamic .node shared
# libraries (N-API addons), not static binaries. # libraries (N-API addons), not static binaries.
......
...@@ -25,11 +25,20 @@ const path = require('path') ...@@ -25,11 +25,20 @@ const path = require('path')
const fs = require('fs') const fs = require('fs')
const os = require('os') const os = require('os')
const { parseArgs } = require('node:util')
const { values: flags } = parseArgs({
args: process.argv.slice(2),
options: {
force: { type: 'boolean', default: false },
load: { type: 'boolean', default: false },
},
})
const REPO_ROOT = path.resolve(__dirname, '..') const REPO_ROOT = path.resolve(__dirname, '..')
const IMAGE_NAME = 'next-swc-builder:latest' const IMAGE_NAME = 'next-swc-builder:latest'
const IMAGE_TAR = path.join(REPO_ROOT, 'target/docker-image.tar') const IMAGE_TAR = path.join(REPO_ROOT, 'target/docker-image.tar')
const force = process.argv.includes('--force') const force = flags.force
const load = process.argv.includes('--load') const load = flags.load
function imageExists() { function imageExists() {
try { try {
......
...@@ -48,43 +48,32 @@ const HOST_ARCH = ...@@ -48,43 +48,32 @@ const HOST_ARCH =
os.arch() === 'arm64' || os.arch() === 'aarch64' ? 'aarch64' : 'x86_64' os.arch() === 'arm64' || os.arch() === 'aarch64' ? 'aarch64' : 'x86_64'
// --- Parse args --- // --- Parse args ---
const args = process.argv.slice(2) const { parseArgs } = require('node:util')
let quick = false const { values: flags, positionals } = parseArgs({
let hostTarget = false args: process.argv.slice(2),
let rebuild = false options: {
let test = false quick: { type: 'boolean', default: false },
let filter = '' 'host-target': { type: 'boolean', default: false },
rebuild: { type: 'boolean', default: false },
for (const arg of args) { test: { type: 'boolean', default: false },
switch (arg) { help: { type: 'boolean', short: 'h', default: false },
case '--quick': },
quick = true allowPositionals: true,
break })
case '--host-target':
hostTarget = true if (flags.help) {
break console.log(
case '--rebuild': 'Usage: node scripts/docker-native-build.js [--quick] [--host-target] [--rebuild] [--test] [filter]'
rebuild = true )
break process.exit(0)
case '--test':
test = true
break
case '--help':
case '-h':
console.log(
'Usage: node scripts/docker-native-build.js [--quick] [--host-target] [--rebuild] [--test] [filter]'
)
process.exit(0)
break // eslint: no-fallthrough
default:
if (arg.startsWith('--')) {
console.error(`Unknown flag: ${arg}`)
process.exit(1)
}
filter = arg
}
} }
const quick = flags.quick
const hostTarget = flags['host-target']
const rebuild = flags.rebuild
const test = flags.test
const filter = positionals[0] || ''
// --- Filter targets --- // --- Filter targets ---
let targets = TARGETS let targets = TARGETS
if (filter) { if (filter) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment