Skip to content

Commit e54b575

Browse files
committed
Use libunwind from llvm-project submodule for musl targets
1 parent 9152fe4 commit e54b575

File tree

5 files changed

+13
-60
lines changed

5 files changed

+13
-60
lines changed

src/bootstrap/sanity.rs

-4
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,6 @@ pub fn check(build: &mut Build) {
202202
panic!("couldn't find libc.a in musl dir: {}",
203203
root.join("lib").display());
204204
}
205-
if fs::metadata(root.join("lib/libunwind.a")).is_err() {
206-
panic!("couldn't find libunwind.a in musl dir: {}",
207-
root.join("lib").display());
208-
}
209205
}
210206
None => {
211207
panic!("when targeting MUSL either the rust.musl-root \

src/ci/docker/scripts/musl-toolchain.sh

-26
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,3 @@ if [ "$REPLACE_CC" = "1" ]; then
5454
ln -s $TARGET-g++ /usr/local/bin/$exec
5555
done
5656
fi
57-
58-
export CC=$TARGET-gcc
59-
export CXX=$TARGET-g++
60-
61-
LLVM=70
62-
63-
# may have been downloaded in a previous run
64-
if [ ! -d libunwind-release_$LLVM ]; then
65-
curl -L https://github.com/llvm-mirror/llvm/archive/release_$LLVM.tar.gz | tar xzf -
66-
curl -L https://github.com/llvm-mirror/libunwind/archive/release_$LLVM.tar.gz | tar xzf -
67-
fi
68-
69-
# fixme(mati865): Replace it with https://github.com/rust-lang/rust/pull/59089
70-
mkdir libunwind-build
71-
cd libunwind-build
72-
cmake ../libunwind-release_$LLVM \
73-
-DLLVM_PATH=/build/llvm-release_$LLVM \
74-
-DLIBUNWIND_ENABLE_SHARED=0 \
75-
-DCMAKE_C_COMPILER=$CC \
76-
-DCMAKE_CXX_COMPILER=$CXX \
77-
-DCMAKE_C_FLAGS="$CFLAGS" \
78-
-DCMAKE_CXX_FLAGS="$CXXFLAGS"
79-
80-
hide_output make -j$(nproc)
81-
cp lib/libunwind.a $OUTPUT/$TARGET/lib
82-
cd - && rm -rf libunwind-build

src/ci/docker/scripts/musl.sh

+2-24
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ exit 1
2020
TAG=$1
2121
shift
2222

23+
# Ancient binutils versions don't understand debug symbols produced by more recent tools.
24+
# Apparently applying `-fPIC` everywhere allows them to link successfully.
2325
export CFLAGS="-fPIC $CFLAGS"
2426

2527
MUSL=musl-1.1.22
@@ -38,27 +40,3 @@ else
3840
fi
3941
hide_output make install
4042
hide_output make clean
41-
42-
cd ..
43-
44-
LLVM=70
45-
46-
# may have been downloaded in a previous run
47-
if [ ! -d libunwind-release_$LLVM ]; then
48-
curl -L https://github.com/llvm-mirror/llvm/archive/release_$LLVM.tar.gz | tar xzf -
49-
curl -L https://github.com/llvm-mirror/libunwind/archive/release_$LLVM.tar.gz | tar xzf -
50-
fi
51-
52-
mkdir libunwind-build
53-
cd libunwind-build
54-
cmake ../libunwind-release_$LLVM \
55-
-DLLVM_PATH=/build/llvm-release_$LLVM \
56-
-DLIBUNWIND_ENABLE_SHARED=0 \
57-
-DCMAKE_C_COMPILER=$CC \
58-
-DCMAKE_CXX_COMPILER=$CXX \
59-
-DCMAKE_C_FLAGS="$CFLAGS" \
60-
-DCMAKE_CXX_FLAGS="$CXXFLAGS"
61-
62-
hide_output make -j$(nproc)
63-
cp lib/libunwind.a /musl-$TAG/lib
64-
cd ../ && rm -rf libunwind-build

src/libunwind/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ compiler_builtins = "0.1.0"
2222
cfg-if = "0.1.8"
2323

2424
[build-dependencies]
25-
cc = { optional = true, version = "1.0.1" }
25+
cc = { version = "1.0.1" }
2626

2727
[features]
28-
llvm-libunwind = ["cc"]
28+
llvm-libunwind = []

src/libunwind/build.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ fn main() {
77
// FIXME: the not(bootstrap) part is needed because of the issue addressed by #62286,
88
// and could be removed once that change is in beta.
99
if cfg!(all(not(bootstrap), feature = "llvm-libunwind")) &&
10-
(target.contains("linux") ||
10+
(target.contains("linux") && !target.contains("musl") ||
1111
target.contains("fuchsia")) {
1212
// Build the unwinding from libunwind C/C++ source code.
13-
#[cfg(all(not(bootstrap), feature = "llvm-libunwind"))]
1413
llvm_libunwind::compile();
1514
} else if target.contains("linux") {
1615
if target.contains("musl") {
17-
// musl is handled in lib.rs
16+
// linking for musl is handled in lib.rs
17+
llvm_libunwind::compile();
1818
} else if !target.contains("android") {
1919
println!("cargo:rustc-link-lib=gcc_s");
2020
}
@@ -46,7 +46,6 @@ fn main() {
4646
}
4747
}
4848

49-
#[cfg(all(not(bootstrap), feature = "llvm-libunwind"))]
5049
mod llvm_libunwind {
5150
use std::env;
5251
use std::path::Path;
@@ -98,6 +97,12 @@ mod llvm_libunwind {
9897
cfg.file(root.join("src").join(src));
9998
}
10099

100+
if target_env == "musl" {
101+
// linking for musl is handled in lib.rs
102+
cfg.cargo_metadata(false);
103+
println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap());
104+
}
105+
101106
cfg.compile("unwind");
102107
}
103108
}

0 commit comments

Comments
 (0)