Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit 9df91b3

Browse files
committed
Try building musl
Add a way to run musl symbols Mostly building Musl works Check for undef symbols Update Fix error with using relinked archives More strict archive checks Clean up warnings More tests Disable more warnings Update build Update build Update build Update syms Update syms More tests passing More tests Make libm-test a default crate Remove unneeded files Download musl in ci Fix unresolved symbols Don't fail fast UNDO let cc link to get cmd output panic with linker Set linker ld env ld env ld env Update More prefixes allowed Add another ppc symbol better test generation Multiple dispatch working Update macros Add many more tests Add sin Try to test more targets Update ci Update build scripts UPdate build printenv in ci Update ci Update ci Update ci Update ci Update ci Update ci Update ci Update ci Update ci Update ci try to fix windows defs Redefine missing symbolsg msvc flags Try inf redefine Disable on msvc change aliases change aliases x86 symbols Weak symbols on macos Weak symbols on macos work! Refactor traits Clean up tuplecall More calls! frexp More calls More calls Update tests. all passing! Update tests
1 parent e5aa09c commit 9df91b3

File tree

14 files changed

+1781
-32
lines changed

14 files changed

+1781
-32
lines changed

.github/workflows/main.yml

+75-27
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,84 @@ env:
88
jobs:
99
docker:
1010
name: Docker
11-
runs-on: ubuntu-latest
11+
timeout-minutes: 10
1212
strategy:
13+
fail-fast: false
1314
matrix:
14-
target:
15-
- aarch64-unknown-linux-gnu
16-
- arm-unknown-linux-gnueabi
17-
- arm-unknown-linux-gnueabihf
18-
- armv7-unknown-linux-gnueabihf
19-
# - i686-unknown-linux-gnu
20-
# MIPS targets disabled since they are dropped to tier 3.
21-
# See https://github.com/rust-lang/compiler-team/issues/648
22-
#- mips-unknown-linux-gnu
23-
#- mips64-unknown-linux-gnuabi64
24-
#- mips64el-unknown-linux-gnuabi64
25-
- powerpc-unknown-linux-gnu
26-
- powerpc64-unknown-linux-gnu
27-
- powerpc64le-unknown-linux-gnu
28-
- x86_64-unknown-linux-gnu
15+
include:
16+
- target: aarch64-apple-darwin
17+
os: macos-latest
18+
- target: aarch64-unknown-linux-gnu
19+
os: ubuntu-latest
20+
- target: arm-unknown-linux-gnueabi
21+
os: ubuntu-latest
22+
- target: arm-unknown-linux-gnueabihf
23+
os: ubuntu-latest
24+
- target: armv7-unknown-linux-gnueabihf
25+
os: ubuntu-latest
26+
- target: i686-unknown-linux-gnu
27+
os: ubuntu-latest
28+
- target: powerpc-unknown-linux-gnu
29+
os: ubuntu-latest
30+
- target: powerpc64-unknown-linux-gnu
31+
os: ubuntu-latest
32+
- target: powerpc64le-unknown-linux-gnu
33+
os: ubuntu-latest
34+
- target: x86_64-unknown-linux-gnu
35+
os: ubuntu-latest
36+
- target: x86_64-apple-darwin
37+
os: macos-13
38+
# - target: i686-pc-windows-msvc
39+
# os: windows-latest
40+
# - target: x86_64-pc-windows-msvc
41+
# os: windows-latest
42+
- target: i686-pc-windows-gnu
43+
os: windows-latest
44+
- target: x86_64-pc-windows-gnu
45+
os: windows-latest
46+
runs-on: ${{ matrix.os }}
2947
steps:
30-
- uses: actions/checkout@master
31-
- name: Install Rust
32-
run: rustup update nightly && rustup default nightly
33-
- run: rustup target add ${{ matrix.target }}
34-
- run: rustup target add x86_64-unknown-linux-musl
35-
- run: cargo generate-lockfile
36-
- run: ./ci/run-docker.sh ${{ matrix.target }}
48+
- name: Print runner information
49+
run: uname -a
50+
- uses: actions/checkout@v4
51+
- name: Install Rust (rustup)
52+
shell: bash
53+
run: |
54+
rustup update nightly --no-self-update
55+
rustup default nightly
56+
rustup target add ${{ matrix.target }}
57+
rustup component add llvm-tools-preview
58+
- uses: Swatinem/rust-cache@v2
59+
with:
60+
key: ${{ matrix.target }}
61+
62+
- name: Download musl source
63+
run: ./ci/download-musl.sh
64+
shell: bash
65+
66+
# Non-linux tests just use our raw script
67+
- name: Run tests locally
68+
run: ./ci/run.sh ${{ matrix.target }}
69+
if: matrix.os != 'ubuntu-latest'
70+
shell: bash
71+
72+
# Otherwise we use our docker containers to run builds
73+
- name: Run in Docker
74+
if: matrix.os == 'ubuntu-latest'
75+
run: |
76+
rustup target add x86_64-unknown-linux-musl
77+
cargo generate-lockfile && ./ci/run-docker.sh ${{ matrix.target }}
3778
3879
rustfmt:
3980
name: Rustfmt
4081
runs-on: ubuntu-latest
4182
steps:
4283
- uses: actions/checkout@master
4384
- name: Install Rust
44-
run: rustup update stable && rustup default stable && rustup component add rustfmt
85+
run: |
86+
rustup update stable --no-self-update
87+
rustup default stable
88+
rustup component add rustfmt
4589
- run: cargo fmt -- --check
4690

4791
wasm:
@@ -50,8 +94,10 @@ jobs:
5094
steps:
5195
- uses: actions/checkout@master
5296
- name: Install Rust
53-
run: rustup update nightly && rustup default nightly
97+
run: rustup update nightly --no-self-update && rustup default nightly
5498
- run: rustup target add wasm32-unknown-unknown
99+
- name: Download MUSL source
100+
run: ./ci/download-musl.sh
55101
- run: cargo build --target wasm32-unknown-unknown
56102

57103
cb:
@@ -60,7 +106,7 @@ jobs:
60106
steps:
61107
- uses: actions/checkout@master
62108
- name: Install Rust
63-
run: rustup update nightly && rustup default nightly
109+
run: rustup update nightly --no-self-update && rustup default nightly
64110
- run: cargo build -p cb
65111

66112
benchmarks:
@@ -69,7 +115,9 @@ jobs:
69115
steps:
70116
- uses: actions/checkout@master
71117
- name: Install Rust
72-
run: rustup update nightly && rustup default nightly
118+
run: rustup update nightly --no-self-update && rustup default nightly
119+
- name: Download MUSL source
120+
run: ./ci/download-musl.sh
73121
- run: cargo bench --all
74122

75123
success:

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
**/*.rs.bk
1+
**.bk
22
.#*
33
/bin
44
/math/src
55
/math/target
66
/target
7-
/tests
87
Cargo.lock
8+
musl/
9+
**.tar.gz

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ members = [
2727
"crates/compiler-builtins-smoke-test",
2828
"crates/libm-bench",
2929
"crates/libm-test",
30+
"crates/musl-math-sys",
3031
]
3132
default-members = [
3233
".",

ci/download-musl.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
3+
set -eux
4+
5+
fname=musl-1.2.5.tar.gz
6+
sha=a9a118bbe84d8764da0ea0d28b3ab3fae8477fc7e4085d90102b8596fc7c75e4
7+
8+
mkdir musl
9+
curl "https://musl.libc.org/releases/$fname" -O
10+
11+
echo "$(uname -s)"
12+
13+
case "$(uname -s)" in
14+
MINGW*)
15+
# Need to extract the second line because certutil does human output
16+
fsha=$(certutil -hashfile "$fname" SHA256 | sed -n '2p')
17+
[ "$sha" = "$fsha" ] || exit 1
18+
;;
19+
*)
20+
echo "$sha $fname" | shasum -a 256 --check || exit 1
21+
;;
22+
esac
23+
24+
tar -xzf "$fname" -C musl --strip-components 1
25+
rm "$fname"

ci/run.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ $cmd --release
1717
$cmd --features 'unstable'
1818
$cmd --release --features 'unstable'
1919

20-
# also run the reference tests
21-
$cmd --features 'unstable libm-test/musl-bitwise-tests'
22-
$cmd --release --features 'unstable libm-test/musl-bitwise-tests'
20+
if [ "$(uname -a)" = "Linux" ]; then
21+
# also run the reference tests
22+
$cmd --features 'unstable libm-test/musl-bitwise-tests'
23+
$cmd --release --features 'unstable libm-test/musl-bitwise-tests'
24+
fi

crates/libm-test/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,13 @@ musl-bitwise-tests = ["rand"]
1414
[dependencies]
1515
libm = { path = "../.." }
1616

17+
# We can't build musl on MSVC
18+
[target.'cfg(not(target_env = "msvc"))'.dependencies]
19+
musl-math-sys = { path = "../musl-math-sys" }
20+
21+
[dev-dependencies]
22+
rand = "0.8.5"
23+
rand_chacha = "0.3.1"
24+
1725
[build-dependencies]
1826
rand = { version = "0.8.5", optional = true }

crates/libm-test/build.rs

+44
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,52 @@
1+
use std::fmt::Write;
2+
use std::path::PathBuf;
3+
use std::{env, fs};
4+
15
fn main() {
6+
list_all_tests();
7+
emit_optimization_cfg();
8+
29
#[cfg(feature = "musl-bitwise-tests")]
310
musl_reference_tests::generate();
411
}
512

13+
/// Some tests are extremely slow. Emit a config option to
14+
fn emit_optimization_cfg() {
15+
println!("cargo::rustc-check-cfg=cfg(optimizations_enabled)");
16+
17+
let opt_level: u8 = env::var("OPT_LEVEL").unwrap().parse().unwrap();
18+
if opt_level >= 2 {
19+
println!("cargo::rustc-cfg=optimizations_enabled");
20+
}
21+
}
22+
23+
fn list_all_tests() {
24+
let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
25+
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
26+
let math_src = root_dir.join("../../src/math");
27+
28+
let mut files = fs::read_dir(math_src)
29+
.unwrap()
30+
.map(|f| f.unwrap().path())
31+
.filter(|entry| entry.is_file())
32+
.map(|f| f.file_stem().unwrap().to_str().unwrap().to_owned())
33+
.collect::<Vec<_>>();
34+
files.sort();
35+
36+
let mut s = "pub const MATH_FILES: &[&str] = &[".to_owned();
37+
for f in files {
38+
if f == "mod" {
39+
// skip mod.rs
40+
continue;
41+
}
42+
write!(s, "\"{f}\",").unwrap();
43+
}
44+
write!(s, "];").unwrap();
45+
46+
let outfile = out_dir.join("all_files.rs");
47+
fs::write(outfile, s).unwrap();
48+
}
49+
650
#[cfg(feature = "musl-bitwise-tests")]
751
mod musl_reference_tests {
852
use rand::seq::SliceRandom;

0 commit comments

Comments
 (0)