openSUSE-Rust / cargo-packaging

Cargo Packaging macros
Mozilla Public License 2.0
5 stars 6 forks source link

How to use additional RUSTFLAGS? #8

Closed kastl-ars closed 4 months ago

kastl-ars commented 4 months ago

Hi William,

for packaging the nix-installer I need to pass an additional RUSTFLAG to the build. Is there any documentation on how to do that?

Simply exporting the variable before the builds does not work, as the macro seems to simply overwrite it.

Thanks in advance, Johannes

%build
export RUSTFLAGS="--cfg tokio_unstable"
%{cargo_build}
[    4s] + cd nix-installer-v0.20.1
[    4s] + export 'RUSTFLAGS=--cfg tokio_unstable'
[    4s] + RUSTFLAGS='--cfg tokio_unstable'
[    4s] + unset LIBSSH2_SYS_USE_PKG_CONFIG
[    4s] + '[' -z '' ']'
[    4s] + CARGO_AUDITABLE=auditable
[    4s] + CARGO_FEATURE_VENDORED=1
[    4s] + RUSTFLAGS=' -Clink-arg=-Wl,-z,relro,-z,now -C debuginfo=2 -C incremental=false -C strip=none'
[    4s] + /usr/bin/cargo auditable build -j12 --offline --release
kastl-ars commented 4 months ago

Hah, just had a look into the code (again..) and noticed RUSTFLAGS="%{?__rustflags} %{?build_rustflags}".

So, setting the __rustflags macro seems to do the trick:

%define __rustflags --cfg tokio_unstable
[...]
[    3s] + CARGO_FEATURE_VENDORED=1
[    3s] + RUSTFLAGS='--cfg tokio_unstable -Clink-arg=-Wl,-z,relro,-z,now -C debuginfo=2 -C incremental=false -C strip=none'
[    3s] + /usr/bin/cargo auditable build -j12 --offline --release

Could this be documented somewhere? README.md, the wiki?

Firstyear commented 4 months ago

Done, updated both readme and wiki.

kastl-ars commented 4 months ago

Done, updated both readme and wiki.

Thanks a lot, @Firstyear