Skip to content

Commit 5941acd

Browse files
committed
Use libunwind from llvm-project submodule for musl targets
1 parent 082cf2f commit 5941acd

File tree

5 files changed

+16
-60
lines changed

5 files changed

+16
-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

+12-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ fn main() {
55
let target = env::var("TARGET").expect("TARGET was not set");
66

77
if cfg!(feature = "llvm-libunwind") &&
8-
(target.contains("linux") ||
8+
((target.contains("linux") && !target.contains("musl")) ||
99
target.contains("fuchsia")) {
1010
// Build the unwinding from libunwind C/C++ source code.
11-
#[cfg(feature = "llvm-libunwind")]
1211
llvm_libunwind::compile();
1312
} else if target.contains("linux") {
1413
if target.contains("musl") {
15-
// musl is handled in lib.rs
14+
// linking for musl is handled in lib.rs
15+
llvm_libunwind::compile();
1616
} else if !target.contains("android") {
1717
println!("cargo:rustc-link-lib=gcc_s");
1818
}
@@ -44,7 +44,6 @@ fn main() {
4444
}
4545
}
4646

47-
#[cfg(feature = "llvm-libunwind")]
4847
mod llvm_libunwind {
4948
use std::env;
5049
use std::path::Path;
@@ -96,6 +95,15 @@ mod llvm_libunwind {
9695
cfg.file(root.join("src").join(src));
9796
}
9897

98+
if target_env == "musl" {
99+
// use the same C compiler command to compile C++ code so we do not need to setup the
100+
// C++ compiler env variables on the builders
101+
cfg.cpp(false);
102+
// linking for musl is handled in lib.rs
103+
cfg.cargo_metadata(false);
104+
println!("cargo:rustc-link-search=native={}", env::var("OUT_DIR").unwrap());
105+
}
106+
99107
cfg.compile("unwind");
100108
}
101109
}

0 commit comments

Comments
 (0)