feat(cli): add --strip option for removing symbols

This commit is contained in:
messense 2022-01-13 17:00:04 +08:00
parent 1768cf69ee
commit 887bdb9d29

View file

@ -162,6 +162,10 @@ export class BuildCommand extends Command {
)} ${chalk.green('--zig-abi-suffix=2.17')}`,
})
isStrip = Option.Boolean(`--strip`, false, {
description: `${chalk.green('Strip')} the library for minimum file size`,
})
async execute() {
const cwd = this.cargoCwd
? join(process.cwd(), this.cargoCwd)
@ -207,14 +211,21 @@ export class BuildCommand extends Command {
})
}
if (triple.raw.includes('musl')) {
let rustflags = process.env.RUSTFLAGS ?? ''
if (triple.raw.includes('musl')) {
if (!rustflags.includes('target-feature=-crt-static')) {
rustflags += '-C target-feature=-crt-static'
additionalEnv['RUSTFLAGS'] = rustflags
}
}
if (this.isStrip && !rustflags.includes('-C link-arg=-s')) {
rustflags += '-C link-arg=-s'
}
if (rustflags.length > 0) {
additionalEnv['RUSTFLAGS'] = rustflags
}
if (this.useZig) {
const zigTarget = `${ZIG_PLATFORM_TARGET_MAP[triple.raw]}${
this.zigABIVersion ? `.${this.zigABIVersion}` : ''