fix(cli): properly handle RUSTFLAGS env var

This commit is contained in:
messense 2022-01-13 21:34:59 +08:00
parent 110f2196a4
commit d84cbe88bd

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 (triple.raw.includes('musl')) {
if (!rustflags.includes('target-feature=-crt-static')) { 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')) { if (this.isStrip && !rustflags.includes('-C link-arg=-s')) {
rustflags += '-C link-arg=-s' rustflags.push('-C link-arg=-s')
} }
if (rustflags.length > 0) { if (rustflags.length > 0) {
additionalEnv['RUSTFLAGS'] = rustflags additionalEnv['RUSTFLAGS'] = rustflags.join(' ')
} }
if (this.useZig) { if (this.useZig) {