Merge pull request #1027 from messense/fix-rustflags

fix(cli): properly handle RUSTFLAGS env var
This commit is contained in:
LongYinan 2022-01-14 11:27:12 +08:00 committed by GitHub
commit 70bd987251
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -211,19 +211,21 @@ export class BuildCommand extends Command {
})
}
let rustflags = process.env.RUSTFLAGS ?? ''
const rustflags = process.env.RUSTFLAGS
? process.env.RUSTFLAGS.split(' ')
: []
if (triple.raw.includes('musl')) {
if (!rustflags.includes('target-feature=-crt-static')) {
rustflags += '-C target-feature=-crt-static'
rustflags.push('-C target-feature=-crt-static')
}
}
if (this.isStrip && !rustflags.includes('-C link-arg=-s')) {
rustflags += '-C link-arg=-s'
rustflags.push('-C link-arg=-s')
}
if (rustflags.length > 0) {
additionalEnv['RUSTFLAGS'] = rustflags
additionalEnv['RUSTFLAGS'] = rustflags.join(' ')
}
if (this.useZig) {