cross-rs / cross

“Zero setup” cross compilation and “cross testing” of Rust crates
Apache License 2.0
6.49k stars 365 forks source link

Incorrect warning about invalid CARGO_TARGET_arch_RUSTFLAGS being unused #1327

Closed Wilfred closed 1 year ago

Wilfred commented 1 year ago

Checklist

Describe your issue

When configuring RUSTFLAGS with cross, I get a warning about the flag being ignored, but it does seem to be respected.

$ CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGs='-C link-arg=-s' cross build --release --target x86_64-unknown-linux-musl
warning: Environment variables are expected to use uppercase letters and underscores, the variable `CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGs` will be ignored and have no effect

I believe this is the correct flag according to https://github.com/cross-rs/cross/wiki/Configuration#cargo-configuration, and I do seem to be getting a binary with static linking.

What target(s) are you cross-compiling for?

No response

Which operating system is the host (e.g computer cross is on) running?

What architecture is the host?

What container engine is cross using?

cross version

cross 0.2.5

Example

$ cargo init --bin helloworld
$ cd helloworld

$ CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGs='-C link-arg=-s' cross build --release --target x86_64-unknown-linux-musl
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
warning: Environment variables are expected to use uppercase letters and underscores, the variable `CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGs` will be ignored and have no effect
warning: Environment variables are expected to use uppercase letters and underscores, the variable `CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGs` will be ignored and have no effect
warning: Environment variables are expected to use uppercase letters and underscores, the variable `CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGs` will be ignored and have no effect
    Finished release [optimized] target(s) in 0.08s

$ ldd target/x86_64-unknown-linux-musl/release/helloworld
    statically linked

Additional information / notes

No response

taiki-e commented 1 year ago

CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGs

The problem is the last s is not upper case. You have to use CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS.

I do seem to be getting a binary with static linking.

x86_64-unknown-linux-musl uses static linking by default.

Wilfred commented 1 year ago

User error, thanks for the pointers!