From ca29e8051569bd99ced030434d8c005ca7413f0b Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 30 Nov 2022 11:39:13 -0500 Subject: [PATCH] buildRustCrate: Support `cargo:rustc-link-arg` and some friends from build.rs See https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-link-argfor details. We are supporting: - `cargo:rustc-link-arg` - `cargo:rustc-link-arg-bins` - `cargo:rustc-link-arg-lib` at this time. `cargo:rustc-link-arg-bin` is left as future work because the per-binary flag keeping is more difficult. (cherry picked from commit fde3b57055a370dd43041b38ef07af66c86fbc3e) --- .../build-support/rust/build-rust-crate/configure-crate.nix | 5 ++++- pkgs/build-support/rust/build-rust-crate/lib.sh | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/rust/build-rust-crate/configure-crate.nix b/pkgs/build-support/rust/build-rust-crate/configure-crate.nix index 473a91f9ce07..ea150c2fe85d 100644 --- a/pkgs/build-support/rust/build-rust-crate/configure-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/configure-crate.nix @@ -186,7 +186,10 @@ in '' set +e EXTRA_BUILD=$(sed -n "s/^cargo:rustc-flags=\(.*\)/\1/p" target/build/${crateName}.opt | tr '\n' ' ' | sort -u) EXTRA_FEATURES=$(sed -n "s/^cargo:rustc-cfg=\(.*\)/--cfg \1/p" target/build/${crateName}.opt | tr '\n' ' ') - EXTRA_LINK=$(sed -n "s/^cargo:rustc-link-lib=\(.*\)/\1/p" target/build/${crateName}.opt | tr '\n' ' ') + EXTRA_LINK_ARGS=$(sed -n "s/^cargo:rustc-link-arg=\(.*\)/-C link-arg=\1/p" target/build/${crateName}.opt | tr '\n' ' ') + EXTRA_LINK_ARGS_BINS=$(sed -n "s/^cargo:rustc-link-arg-bins=\(.*\)/-C link-arg=\1/p" target/build/${crateName}.opt | tr '\n' ' ') + EXTRA_LINK_ARGS_LIB=$(sed -n "s/^cargo:rustc-link-arg-lib=\(.*\)/-C link-arg=\1/p" target/build/${crateName}.opt | tr '\n' ' ') + EXTRA_LINK_LIBS=$(sed -n "s/^cargo:rustc-link-lib=\(.*\)/\1/p" target/build/${crateName}.opt | tr '\n' ' ') EXTRA_LINK_SEARCH=$(sed -n "s/^cargo:rustc-link-search=\(.*\)/\1/p" target/build/${crateName}.opt | tr '\n' ' ' | sort -u) # We want to read part of every line that has cargo:rustc-env= prefix and diff --git a/pkgs/build-support/rust/build-rust-crate/lib.sh b/pkgs/build-support/rust/build-rust-crate/lib.sh index 39f7d53f6f75..7f98701b5409 100644 --- a/pkgs/build-support/rust/build-rust-crate/lib.sh +++ b/pkgs/build-support/rust/build-rust-crate/lib.sh @@ -17,6 +17,8 @@ build_lib() { -L dependency=target/deps \ --cap-lints allow \ $LINK \ + $EXTRA_LINK_ARGS \ + $EXTRA_LINK_ARGS_LIB \ $LIB_RUSTC_OPTS \ $BUILD_OUT_DIR \ $EXTRA_BUILD \ @@ -47,6 +49,8 @@ build_bin() { --out-dir target/bin \ -L dependency=target/deps \ $LINK \ + $EXTRA_LINK_ARGS \ + $EXTRA_LINK_ARGS_BINS \ $EXTRA_LIB \ --cap-lints allow \ $BUILD_OUT_DIR \ @@ -94,7 +98,7 @@ setup_link_paths() { done fi done - echo "$EXTRA_LINK" | while read i; do + echo "$EXTRA_LINK_LIBS" | while read i; do if [[ ! -z "$i" ]]; then for library in $i; do echo "-l $library" >> target/link