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.
This commit is contained in:
John Ericson 2022-11-30 11:39:13 -05:00
parent dc08caa8a3
commit fde3b57055
2 changed files with 9 additions and 2 deletions

View File

@ -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

View File

@ -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