buildRustCrate: add support for cargo::rustc-cdylib-link-arg

This commit is contained in:
Ahmad Sattar 2024-06-28 10:20:41 +02:00
parent 69bee9866a
commit 1cf6e5eaa1
3 changed files with 13 additions and 1 deletions

View File

@ -14,6 +14,7 @@
, crateLicenseFile
, crateLinks
, crateName
, crateType
, crateReadme
, crateRenames
, crateRepository
@ -209,6 +210,11 @@ in ''
EXTRA_LINK_LIBS=$(sed -n "s/^cargo::\{0,1\}rustc-link-lib=\(.*\)/\1/p" target/build/${crateName}.opt | tr '\n' ' ')
EXTRA_LINK_SEARCH=$(sed -n "s/^cargo::\{0,1\}rustc-link-search=\(.*\)/\1/p" target/build/${crateName}.opt | tr '\n' ' ' | sort -u)
${lib.optionalString (lib.elem "cdylib" crateType) ''
CRATE_TYPE_IS_CDYLIB="true"
EXTRA_CDYLIB_LINK_ARGS=$(sed -n "s/^cargo::\{0,1\}rustc-cdylib-link-arg=\(.*\)/-C link-arg=\1/p" target/build/${crateName}.opt | tr '\n' ' ')
''}
# We want to read part of every line that has cargo:rustc-env= prefix and
# export it as environment variables. This turns out tricky if the lines
# have spaces: we can't wrap the command in double quotes as that captures

View File

@ -345,7 +345,7 @@ crate_: lib.makeOverridable
configurePhase = configureCrate {
inherit crateName buildDependencies completeDeps completeBuildDeps crateDescription
inherit crateName crateType buildDependencies completeDeps completeBuildDeps crateDescription
crateFeatures crateRenames libName build workspace_member release libPath crateVersion crateLinks
extraLinkFlags extraRustcOptsForBuildRs
crateLicense crateLicenseFile crateReadme crateRepository crateRustVersion

View File

@ -114,6 +114,12 @@ setup_link_paths() {
tr '\n' ' ' < target/link > target/link_
LINK=$(cat target/link_)
fi
# Add "rustc-cdylib-link-arg" as linker arguments
# https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-cdylib-link-arg
if [[ -n "$CRATE_TYPE_IS_CDYLIB" ]]; then
EXTRA_BUILD+=" $EXTRA_CDYLIB_LINK_ARGS"
fi
}
search_for_bin_path() {