• [gentoo-dev] [PATCH 4/5] cargo.eclass: Enable dynamic linking by defaul

    From Arthur Zamarin@21:1/5 to All on Sat Mar 8 15:10:02 2025
    From: Michal Rostecki <vadorovsky@protonmail.com>

    Rust defaults to static linking (`-C target-feature=+crt-static`) on
    musl targets. We already patch dev-lang/rust to always prefer dynamic
    linking, but to ensure that behavior with dev-lang/rust-bin, set the
    opposite option (`-C target-feature=-crt-static`) in RUSTFLAGS.

    Bug: https://bugs.gentoo.org/940722
    Signed-off-by: Michal Rostecki <vadorovsky@protonmail.com>
    Closes: https://github.com/gentoo/gentoo/pull/40797
    Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
    ---
    eclass/cargo.eclass | 7 ++++++-
    1 file changed, 6 insertions(+), 1 deletion(-)

    diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
    index 909321c355b..dae2b93f24f 100644
    --- a/eclass/cargo.eclass
    +++ b/eclass/cargo.eclass
    @@ -745,10 +745,15 @@ cargo_env() {
    # The default linker is "cc" so override by setting linker to CC in the
    # RUSTFLAGS. The given linker cannot include any arguments, so split these
    # into link-args along with LDFLAGS.
    + #
    + # Rust defaults to static linking (-C target-feature=+crt-static) on musl
    + # targets. We already patch dev-lang/rust to always prefer dynamic linking,
    + # but to ensure that behavior with dev-lang/rust-bin, set the opposite option
    + # (-C target-feature=-crt-static) in RUSTFLAGS.
    local -x CARGO_BUILD_TARGET=$(rust_abi)
    local TRIPLE=${CARGO_BUILD_TARGET//-/_}
    local TRIPLE=${TRIPLE^^} LD_A=( $(tc-getCC) ${LDFLAGS} )
    - local -Ix CARGO_TARGET_"${TRIPLE}"_RUSTFLAGS+=" -C strip=none -C linker=${LD_A[0]}"
    + local -Ix CARGO_TARGET_"${T
  • From James Le Cuirot@21:1/5 to Arthur Zamarin on Sat Mar 8 17:30:01 2025
    On Sat, 2025-03-08 at 15:59 +0200, Arthur Zamarin wrote:
    From: Michal Rostecki <vadorovsky@protonmail.com>

    Rust defaults to static linking (`-C target-feature=+crt-static`) on
    musl targets. We already patch dev-lang/rust to always prefer dynamic linking, but to ensure that behavior with dev-lang/rust-bin, set the
    opposite option (`-C target-feature=-crt-static`) in RUSTFLAGS.

    Bug: https://bugs.gentoo.org/940722
    Signed-off-by: Michal Rostecki <vadorovsky@protonmail.com>
    Closes: https://github.com/gentoo/gentoo/pull/40797
    Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
    ---
    eclass/cargo.eclass | 7 ++++++-
    1 file changed, 6 insertions(+), 1 deletion(-)

    diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass
    index 909321c355b..dae2b93f24f 100644
    --- a/eclass/cargo.eclass
    +++ b/eclass/cargo.eclass
    @@ -745,10 +745,15 @@ cargo_env() {
    # The default linker is "cc" so override by setting linker to CC in the
    # RUSTFLAGS. The given linker cannot include any arguments, so split these
    # into link-args along with LDFLAGS.
    + #
    + # Rust defaults to static linking (-C target-feature=+crt-static) on musl
    + # targets. We already patch dev-lang/rust to always prefer dynamic linking,
    + # but to ensure that behavior with dev-lang/rust-bin, set the opposite option
    + # (-C target-feature=-crt-static) in RUSTFLAGS.
    local -x CARGO_BUILD_TARGET=$(rust_abi)
    local TRIPLE=${CARGO_BUILD_TARGET//-/_}
    local TRIPLE=${TRIPLE^^} LD_A=( $(tc-getCC) ${LDFLAGS} )
    - local -Ix CARGO_TARGET_"${TRIPLE}"_RUSTFLAGS+=" -C strip=none -C linker=${LD_A[0]}"
    + local -Ix CARGO_TARGET_"${TRIPLE}"_RUSTFLAGS+=" -C strip=none -C linker=${LD_A[0]} -C target-feature=-crt-static"
    [[ ${#LD_A[@]} -gt 1 ]] && local CARGO_TARGET_"${TRIPLE}"_RUSTFLAGS+="$(printf -- ' -C link-arg=%s' "${LD_A[@]:1}")"
    local CARGO_TARGET_"${TRIPLE}"_RUSTFLAGS+=" ${RUSTFLAGS}"

    I considered this when writing the above lines, but I wasn't sure if it was a good idea. If the testing has been done, then I'm glad to see it.


    -----BEGIN PGP SIGNATURE-----

    iQJFBAABCAAvFiEEPxcZ3tkwcedKm2a8EiZBXQDdMTcFAmfMbvkRHGNoZXdpQGdl bnRvby5vcmcACgkQEiZBXQDdMTcbeA//SmSe/89TUaVLNEh+oog7jIo9xlbN8WJ5 uUikPhPY1/9QYKa73TvqY2yP9P29yl2KkqANa4fldsXZvSRZfTkIJRwEEzwtgTun 5YLa2IEWU/1vgKrwadCQrZWN6stJJAeNQE5KyhgE6Itvvi5gEHPLCbBUcPykNtO6 m5I88VlqoPYKP+0vp9TwNEWPNHNCgHOHjMfdy6o8u4sIA4ppJcftjlqCFsp0HEQS ZMark5Hj0Ev2+oJbZtte92JVxOnXlw5fcLMipNi//EzAScmEMgI2opGl7OBDshhY U33mpvXbiTWDA1HIQgCCvdT6aZlFFtRaoNgZ8duNB+BUXq9Fn8o0ecUpssmy/yP9 qPNy8YqHMK2bMDPGlMBou03paktoXqtd5TLJEBomVhjZ2ahldYm6JnoS/12m+uBk kOzntWMOgf0KDJks8CNI0p78PhzL6B5XsMj79Nno5wWpmMvU00Zm+nuIce0r2rYf eujRENu3wamNJv+Jzy0PJf3xRdxZBwzcK9PMwLmpmyGhcmEyJynCteGk2iBQ5QmM cDWH/ZRJqNIqEnMpoRWfmST/doVyhc0oTrLQ56AiJOaDpai0zxdluxZxNYnEgwvV myWhkndzx0b2gNkykbVLSMVvb/gYDouYpcMIarsg7yOfN+PQsjBKg23Z1B2PozOE
    Vde8nzlVEtA=
    =7fsO
    -----END PGP SIGNATURE-----

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)