Skip to content

Commit

Permalink
feat(cli): add --strip option for removing symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Jan 13, 2022
1 parent 1768cf6 commit 887bdb9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cli/src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -207,14 +211,21 @@ export class BuildCommand extends Command {
})
}

let rustflags = process.env.RUSTFLAGS ?? ''
if (triple.raw.includes('musl')) {
let rustflags = process.env.RUSTFLAGS ?? ''
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}` : ''
Expand Down

0 comments on commit 887bdb9

Please sign in to comment.