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

Commit 3f9d441

Browse files
authored
Merge pull request #300 from tgross35/test-refactoring
Test more targets against a custom-built musl libm
2 parents 1c2c6a0 + e1af316 commit 3f9d441

File tree

32 files changed

+3007
-44
lines changed

32 files changed

+3007
-44
lines changed

libm/.github/workflows/main.yml

+94-27
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,103 @@ name: CI
22
on: [push, pull_request]
33

44
env:
5+
CARGO_TERM_VERBOSE: true
56
RUSTDOCFLAGS: -Dwarnings
67
RUSTFLAGS: -Dwarnings
8+
RUST_BACKTRACE: full
79

810
jobs:
9-
docker:
11+
test:
1012
name: Docker
11-
runs-on: ubuntu-latest
13+
timeout-minutes: 20
1214
strategy:
15+
fail-fast: false
1316
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
17+
include:
18+
- target: aarch64-apple-darwin
19+
os: macos-latest
20+
- target: aarch64-unknown-linux-gnu
21+
os: ubuntu-latest
22+
- target: aarch64-pc-windows-msvc
23+
os: windows-latest
24+
build_only: 1 # Can't run on x86 hosts
25+
- target: arm-unknown-linux-gnueabi
26+
os: ubuntu-latest
27+
- target: arm-unknown-linux-gnueabihf
28+
os: ubuntu-latest
29+
- target: armv7-unknown-linux-gnueabihf
30+
os: ubuntu-latest
31+
- target: i586-unknown-linux-gnu
32+
os: ubuntu-latest
33+
- target: i686-unknown-linux-gnu
34+
os: ubuntu-latest
35+
- target: powerpc-unknown-linux-gnu
36+
os: ubuntu-latest
37+
- target: powerpc64-unknown-linux-gnu
38+
os: ubuntu-latest
39+
- target: powerpc64le-unknown-linux-gnu
40+
os: ubuntu-latest
41+
- target: riscv64gc-unknown-linux-gnu
42+
os: ubuntu-latest
43+
- target: thumbv6m-none-eabi
44+
os: ubuntu-latest
45+
- target: thumbv7em-none-eabi
46+
os: ubuntu-latest
47+
- target: thumbv7em-none-eabihf
48+
os: ubuntu-latest
49+
- target: thumbv7m-none-eabi
50+
os: ubuntu-latest
51+
- target: x86_64-unknown-linux-gnu
52+
os: ubuntu-latest
53+
- target: x86_64-apple-darwin
54+
os: macos-13
55+
- target: i686-pc-windows-msvc
56+
os: windows-latest
57+
- target: x86_64-pc-windows-msvc
58+
os: windows-latest
59+
- target: i686-pc-windows-gnu
60+
os: windows-latest
61+
channel: nightly-i686-gnu
62+
- target: x86_64-pc-windows-gnu
63+
os: windows-latest
64+
channel: nightly-x86_64-gnu
65+
runs-on: ${{ matrix.os }}
66+
env:
67+
BUILD_ONLY: ${{ matrix.build_only }}
2968
steps:
30-
- uses: actions/checkout@master
31-
- name: Install Rust
32-
run: rustup update nightly --no-self-update && 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 }}
69+
- name: Print runner information
70+
run: uname -a
71+
- uses: actions/checkout@v4
72+
- name: Install Rust (rustup)
73+
shell: bash
74+
run: |
75+
channel="nightly"
76+
# Account for channels that have required components (MinGW)
77+
[ -n "${{ matrix.channel }}" ] && channel="${{ matrix.channel }}"
78+
rustup update "$channel" --no-self-update
79+
rustup default "$channel"
80+
rustup target add ${{ matrix.target }}
81+
rustup component add llvm-tools-preview
82+
- uses: Swatinem/rust-cache@v2
83+
with:
84+
key: ${{ matrix.target }}
85+
86+
- name: Download musl source
87+
run: ./ci/download-musl.sh
88+
shell: bash
89+
90+
# Non-linux tests just use our raw script
91+
- name: Run locally
92+
if: matrix.os != 'ubuntu-latest'
93+
shell: bash
94+
run: ./ci/run.sh ${{ matrix.target }}
95+
96+
# Otherwise we use our docker containers to run builds
97+
- name: Run in Docker
98+
if: matrix.os == 'ubuntu-latest'
99+
run: |
100+
rustup target add x86_64-unknown-linux-musl
101+
cargo generate-lockfile && ./ci/run-docker.sh ${{ matrix.target }}
37102
38103
wasm:
39104
name: WebAssembly
@@ -45,7 +110,7 @@ jobs:
45110
- run: rustup target add wasm32-unknown-unknown
46111
- run: cargo build --target wasm32-unknown-unknown
47112

48-
cb:
113+
builtins:
49114
name: "The compiler-builtins crate works"
50115
runs-on: ubuntu-latest
51116
steps:
@@ -61,6 +126,8 @@ jobs:
61126
- uses: actions/checkout@master
62127
- name: Install Rust
63128
run: rustup update nightly --no-self-update && rustup default nightly
129+
- name: Download musl source
130+
run: ./ci/download-musl.sh
64131
- run: cargo bench --all
65132

66133
msrv:
@@ -92,9 +159,9 @@ jobs:
92159

93160
success:
94161
needs:
95-
- docker
162+
- test
96163
- wasm
97-
- cb
164+
- builtins
98165
- benchmarks
99166
- msrv
100167
- rustfmt

libm/.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

libm/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,17 @@ unstable = []
2424
force-soft-floats = []
2525

2626
[workspace]
27+
resolver = "2"
2728
members = [
2829
"crates/compiler-builtins-smoke-test",
2930
"crates/libm-bench",
31+
"crates/libm-macros",
3032
"crates/libm-test",
33+
"crates/musl-math-sys",
3134
]
3235
default-members = [
3336
".",
37+
"crates/libm-macros",
3438
"crates/libm-test",
3539
]
3640

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM ubuntu:24.04
2+
3+
RUN apt-get update && \
4+
apt-get install -y --no-install-recommends \
5+
gcc-multilib libc6-dev ca-certificates
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ubuntu:24.04
2+
3+
RUN apt-get update && \
4+
apt-get install -y --no-install-recommends \
5+
gcc libc6-dev qemu-user-static ca-certificates \
6+
gcc-riscv64-linux-gnu libc6-dev-riscv64-cross \
7+
qemu-system-riscv64
8+
9+
ENV TOOLCHAIN_PREFIX=riscv64-linux-gnu-
10+
ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER="$TOOLCHAIN_PREFIX"gcc \
11+
CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUNNER=qemu-riscv64-static \
12+
AR_riscv64gc_unknown_linux_gnu="$TOOLCHAIN_PREFIX"ar \
13+
CC_riscv64gc_unknown_linux_gnu="$TOOLCHAIN_PREFIX"gcc \
14+
QEMU_LD_PREFIX=/usr/riscv64-linux-gnu \
15+
RUST_TEST_THREADS=1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ARG IMAGE=ubuntu:24.04
2+
FROM $IMAGE
3+
4+
RUN apt-get update && \
5+
apt-get install -y --no-install-recommends \
6+
gcc libc6-dev ca-certificates \
7+
gcc-arm-none-eabi \
8+
libnewlib-arm-none-eabi
9+
ENV BUILD_ONLY=1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ARG IMAGE=ubuntu:24.04
2+
FROM $IMAGE
3+
4+
RUN apt-get update && \
5+
apt-get install -y --no-install-recommends \
6+
gcc libc6-dev ca-certificates \
7+
gcc-arm-none-eabi \
8+
libnewlib-arm-none-eabi
9+
ENV BUILD_ONLY=1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ARG IMAGE=ubuntu:24.04
2+
FROM $IMAGE
3+
4+
RUN apt-get update && \
5+
apt-get install -y --no-install-recommends \
6+
gcc libc6-dev ca-certificates \
7+
gcc-arm-none-eabi \
8+
libnewlib-arm-none-eabi
9+
ENV BUILD_ONLY=1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
ARG IMAGE=ubuntu:24.04
2+
FROM $IMAGE
3+
4+
RUN apt-get update && \
5+
apt-get install -y --no-install-recommends \
6+
gcc libc6-dev ca-certificates \
7+
gcc-arm-none-eabi \
8+
libnewlib-arm-none-eabi
9+
ENV BUILD_ONLY=1

libm/ci/download-musl.sh

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

libm/ci/run-docker.sh

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ run() {
2121
-e RUSTFLAGS \
2222
-e CARGO_HOME=/cargo \
2323
-e CARGO_TARGET_DIR=/target \
24+
-e EMULATED=1 \
2425
-v "${HOME}/.cargo:/cargo" \
2526
-v "$(pwd)/target:/target" \
2627
-v "$(pwd):/checkout:ro" \

libm/ci/run.sh

+56-13
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,64 @@
22

33
set -eux
44

5-
target="$1"
5+
export RUST_BACKTRACE="${RUST_BACKTRACE:-full}"
6+
# Needed for no-panic to correct detect a lack of panics
7+
export RUSTFLAGS="${RUSTFLAGS:-} -Ccodegen-units=1"
68

7-
cmd="cargo test --all --target $target"
9+
target="${1:-}"
810

9-
# Needed for no-panic to correct detect a lack of panics
10-
export RUSTFLAGS="$RUSTFLAGS -Ccodegen-units=1"
11+
if [ -z "$target" ]; then
12+
host_target=$(rustc -vV | awk '/^host/ { print $2 }')
13+
echo "Defaulted to host target $host_target"
14+
target="$host_target"
15+
fi
16+
17+
extra_flags=""
18+
19+
# We need to specifically skip tests for musl-math-sys on systems that can't
20+
# build musl since otherwise `--all` will activate it.
21+
case "$target" in
22+
# Can't build at all on MSVC, WASM, or thumb
23+
*windows-msvc*) extra_flags="$extra_flags --exclude musl-math-sys" ;;
24+
*wasm*) extra_flags="$extra_flags --exclude musl-math-sys" ;;
25+
*thumb*) extra_flags="$extra_flags --exclude musl-math-sys" ;;
26+
27+
# We can build musl on MinGW but running tests gets a stack overflow
28+
*windows-gnu*) ;;
29+
# FIXME(#309): LE PPC crashes calling the musl version of some functions. It
30+
# seems like a qemu bug but should be investigated further at some point.
31+
# See <https://github.com/rust-lang/libm/issues/309>.
32+
*powerpc64le*) ;;
33+
34+
# Everything else gets musl enabled
35+
*) extra_flags="$extra_flags --features libm-test/build-musl" ;;
36+
esac
37+
38+
# FIXME: `STATUS_DLL_NOT_FOUND` testing macros on CI.
39+
# <https://github.com/rust-lang/rust/issues/128944>
40+
case "$target" in
41+
*windows-gnu) extra_flags="$extra_flags --exclude libm-macros" ;;
42+
esac
43+
44+
if [ "$(uname -a)" = "Linux" ]; then
45+
# also run the reference tests when we can. requires a Linux host.
46+
extra_flags="$extra_flags --features libm-test/test-musl-serialized"
47+
fi
48+
49+
if [ "${BUILD_ONLY:-}" = "1" ]; then
50+
cmd="cargo build --target $target --package libm"
51+
$cmd
52+
$cmd --features 'unstable'
1153

12-
# stable by default
13-
$cmd
14-
$cmd --release
54+
echo "can't run tests on $target"
55+
else
56+
cmd="cargo test --all --target $target $extra_flags"
1557

16-
# unstable with a feature
17-
$cmd --features 'unstable'
18-
$cmd --release --features 'unstable'
58+
# stable by default
59+
$cmd
60+
$cmd --release
1961

20-
# also run the reference tests
21-
$cmd --features 'unstable libm-test/test-musl-serialized'
22-
$cmd --release --features 'unstable libm-test/test-musl-serialized'
62+
# unstable with a feature
63+
$cmd --features 'unstable'
64+
$cmd --release --features 'unstable'
65+
fi

libm/crates/libm-macros/Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "libm-macros"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
proc-macro = true
8+
9+
[dependencies]
10+
proc-macro2 = "1.0.88"
11+
quote = "1.0.37"
12+
syn = { version = "2.0.79", features = ["full", "extra-traits", "visit-mut"] }

0 commit comments

Comments
 (0)