Merge pull request #1026 from messense/strip

feat(cli): add `--strip` option for removing symbols
This commit is contained in:
LongYinan 2022-01-13 17:40:54 +08:00 committed by GitHub
commit 5d9a444e40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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}` : ''