Skip to content

Commit

Permalink
Merge #1063
Browse files Browse the repository at this point in the history
1063: Fix linkage and C++ support for musl targets. r=Emilgardis a=Alexhuszagh

Change behavior to use static-pie linkage by default (consistent with Alpine's behavior for pure Rust packages as well as those with external C dependencies), and fix musl targets with C++ dependencies by forcing static-pie linkage to standard libraries.

Closes #902.

Co-authored-by: Alex Huszagh <[email protected]>
  • Loading branch information
bors[bot] and Alexhuszagh authored Oct 25, 2022
2 parents d5c08da + e1eef60 commit 2c9843f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 1 deletion.
13 changes: 13 additions & 0 deletions .changes/1063.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"type": "changed",
"description": "changed musl targets to use static-pie linkage by default, consistent with Alpine.",
"breaking": true
},
{
"type": "fixed",
"description": "fixed C++ support for musl targets.",
"issues": [902],
"breaking": true
}
]
15 changes: 15 additions & 0 deletions ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,21 @@ main() {

rm -rf "${td}"
fi

# special tests for a shared C runtime, since we disable the shared c++ runtime
# https://github.com/cross-rs/cross/issues/902
if [[ "${TARGET}" == *-linux-musl* ]]; then
td=$(mkcargotemp -d)

pushd "${td}"
cargo init --bin --name hello .
retry cargo fetch
RUSTFLAGS="-C target-feature=-crt-static" \
"${CROSS[@]}" build --target "${TARGET}" ${CROSS_FLAGS}
popd

rm -rf "${td}"
fi
}

cross_run() {
Expand Down
4 changes: 4 additions & 0 deletions docker/musl-symlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ main() {
fi
done

# ensure we statically link libstdc++, so avoid segfaults with c++
# https://github.com/cross-rs/cross/issues/902
rm "${sysroot}"/lib/libstdc++.so* || true

echo "${sysroot}/lib" >> "/etc/ld-musl-${arch}.path"

rm -rf "${0}"
Expand Down
9 changes: 8 additions & 1 deletion docker/musl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,20 @@ main() {
# Don't depend on the mirrors of sabotage linux that musl-cross-make uses.
local linux_headers_site=https://ci-mirrors.rust-lang.org/rustc/sabotage-linux-tarballs

# alpine GCC is built with `--enable-default-pie`, so we want to
# ensure we use that. we want support for shared runtimes except for
# libstdc++, however, the only way to do that is to simply remove
# the shared libraries later. on alpine, binaries use static-pie
# linked, so our behavior has maximum portability, and is consistent
# with popular musl distros.
hide_output make install "-j$(nproc)" \
GCC_VER=9.2.0 \
MUSL_VER=1.1.24 \
BINUTILS_VER=2.33.1 \
DL_CMD='curl --retry 3 -sSfL -C - -o' \
LINUX_HEADERS_SITE=$linux_headers_site \
LINUX_HEADERS_SITE="${linux_headers_site}" \
OUTPUT=/usr/local/ \
"GCC_CONFIG += --enable-default-pie" \
"${@}"

purge_packages
Expand Down
3 changes: 3 additions & 0 deletions targets.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ deploy = true
[[target]]
target = "x86_64-unknown-linux-musl"
os = "ubuntu-latest"
cpp = true
dylib = true
std = true
run = true
runners = "native qemu-user"
deploy = true

[[target]]
Expand Down

0 comments on commit 2c9843f

Please sign in to comment.