Skip to content

Commit 2c9843f

Browse files
Merge #1063
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]>
2 parents d5c08da + e1eef60 commit 2c9843f

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

.changes/1063.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"type": "changed",
4+
"description": "changed musl targets to use static-pie linkage by default, consistent with Alpine.",
5+
"breaking": true
6+
},
7+
{
8+
"type": "fixed",
9+
"description": "fixed C++ support for musl targets.",
10+
"issues": [902],
11+
"breaking": true
12+
}
13+
]

ci/test.sh

+15
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,21 @@ main() {
182182

183183
rm -rf "${td}"
184184
fi
185+
186+
# special tests for a shared C runtime, since we disable the shared c++ runtime
187+
# https://github.com/cross-rs/cross/issues/902
188+
if [[ "${TARGET}" == *-linux-musl* ]]; then
189+
td=$(mkcargotemp -d)
190+
191+
pushd "${td}"
192+
cargo init --bin --name hello .
193+
retry cargo fetch
194+
RUSTFLAGS="-C target-feature=-crt-static" \
195+
"${CROSS[@]}" build --target "${TARGET}" ${CROSS_FLAGS}
196+
popd
197+
198+
rm -rf "${td}"
199+
fi
185200
}
186201

187202
cross_run() {

docker/musl-symlink.sh

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ main() {
4949
fi
5050
done
5151

52+
# ensure we statically link libstdc++, so avoid segfaults with c++
53+
# https://github.com/cross-rs/cross/issues/902
54+
rm "${sysroot}"/lib/libstdc++.so* || true
55+
5256
echo "${sysroot}/lib" >> "/etc/ld-musl-${arch}.path"
5357

5458
rm -rf "${0}"

docker/musl.sh

+8-1
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,20 @@ main() {
3636
# Don't depend on the mirrors of sabotage linux that musl-cross-make uses.
3737
local linux_headers_site=https://ci-mirrors.rust-lang.org/rustc/sabotage-linux-tarballs
3838

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

4855
purge_packages

targets.toml

+3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ deploy = true
2222
[[target]]
2323
target = "x86_64-unknown-linux-musl"
2424
os = "ubuntu-latest"
25+
cpp = true
26+
dylib = true
2527
std = true
2628
run = true
29+
runners = "native qemu-user"
2730
deploy = true
2831

2932
[[target]]

0 commit comments

Comments
 (0)