Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linkage and C++ support for musl targets. #1063

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need a check for C++ support since it's for a shared C runtime. The C++ runtime will always be static, and we've tested that above.

# 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