Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test more targets against a custom-built musl libm #300

Merged
merged 14 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 94 additions & 27 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,103 @@ name: CI
on: [push, pull_request]

env:
CARGO_TERM_VERBOSE: true
RUSTDOCFLAGS: -Dwarnings
RUSTFLAGS: -Dwarnings
RUST_BACKTRACE: full

jobs:
docker:
test:
name: Docker
runs-on: ubuntu-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
target:
- aarch64-unknown-linux-gnu
- arm-unknown-linux-gnueabi
- arm-unknown-linux-gnueabihf
- armv7-unknown-linux-gnueabihf
# - i686-unknown-linux-gnu
# MIPS targets disabled since they are dropped to tier 3.
# See /~https://github.com/rust-lang/compiler-team/issues/648
#- mips-unknown-linux-gnu
#- mips64-unknown-linux-gnuabi64
#- mips64el-unknown-linux-gnuabi64
- powerpc-unknown-linux-gnu
- powerpc64-unknown-linux-gnu
- powerpc64le-unknown-linux-gnu
- x86_64-unknown-linux-gnu
include:
- target: aarch64-apple-darwin
os: macos-latest
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
- target: aarch64-pc-windows-msvc
os: windows-latest
build_only: 1 # Can't run on x86 hosts
- target: arm-unknown-linux-gnueabi
os: ubuntu-latest
- target: arm-unknown-linux-gnueabihf
os: ubuntu-latest
- target: armv7-unknown-linux-gnueabihf
os: ubuntu-latest
- target: i586-unknown-linux-gnu
os: ubuntu-latest
- target: i686-unknown-linux-gnu
os: ubuntu-latest
- target: powerpc-unknown-linux-gnu
os: ubuntu-latest
- target: powerpc64-unknown-linux-gnu
os: ubuntu-latest
- target: powerpc64le-unknown-linux-gnu
os: ubuntu-latest
- target: riscv64gc-unknown-linux-gnu
os: ubuntu-latest
- target: thumbv6m-none-eabi
os: ubuntu-latest
- target: thumbv7em-none-eabi
os: ubuntu-latest
- target: thumbv7em-none-eabihf
os: ubuntu-latest
- target: thumbv7m-none-eabi
os: ubuntu-latest
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
- target: x86_64-apple-darwin
os: macos-13
- target: i686-pc-windows-msvc
os: windows-latest
- target: x86_64-pc-windows-msvc
os: windows-latest
- target: i686-pc-windows-gnu
os: windows-latest
channel: nightly-i686-gnu
- target: x86_64-pc-windows-gnu
os: windows-latest
channel: nightly-x86_64-gnu
runs-on: ${{ matrix.os }}
env:
BUILD_ONLY: ${{ matrix.build_only }}
steps:
- uses: actions/checkout@master
- name: Install Rust
run: rustup update nightly --no-self-update && rustup default nightly
- run: rustup target add ${{ matrix.target }}
- run: rustup target add x86_64-unknown-linux-musl
- run: cargo generate-lockfile
- run: ./ci/run-docker.sh ${{ matrix.target }}
- name: Print runner information
run: uname -a
- uses: actions/checkout@v4
- name: Install Rust (rustup)
shell: bash
run: |
channel="nightly"
# Account for channels that have required components (MinGW)
[ -n "${{ matrix.channel }}" ] && channel="${{ matrix.channel }}"
rustup update "$channel" --no-self-update
rustup default "$channel"
rustup target add ${{ matrix.target }}
rustup component add llvm-tools-preview
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}

- name: Download musl source
run: ./ci/download-musl.sh
shell: bash

# Non-linux tests just use our raw script
- name: Run locally
if: matrix.os != 'ubuntu-latest'
shell: bash
run: ./ci/run.sh ${{ matrix.target }}

# Otherwise we use our docker containers to run builds
- name: Run in Docker
if: matrix.os == 'ubuntu-latest'
run: |
rustup target add x86_64-unknown-linux-musl
cargo generate-lockfile && ./ci/run-docker.sh ${{ matrix.target }}

wasm:
name: WebAssembly
Expand All @@ -45,7 +110,7 @@ jobs:
- run: rustup target add wasm32-unknown-unknown
- run: cargo build --target wasm32-unknown-unknown

cb:
builtins:
name: "The compiler-builtins crate works"
runs-on: ubuntu-latest
steps:
Expand All @@ -61,6 +126,8 @@ jobs:
- uses: actions/checkout@master
- name: Install Rust
run: rustup update nightly --no-self-update && rustup default nightly
- name: Download musl source
run: ./ci/download-musl.sh
- run: cargo bench --all

msrv:
Expand Down Expand Up @@ -92,9 +159,9 @@ jobs:

success:
needs:
- docker
- test
- wasm
- cb
- builtins
- benchmarks
- msrv
- rustfmt
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
**/*.rs.bk
**.bk
.#*
/bin
/math/src
/math/target
/target
/tests
Cargo.lock
musl/
**.tar.gz
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ unstable = []
force-soft-floats = []

[workspace]
resolver = "2"
members = [
"crates/compiler-builtins-smoke-test",
"crates/libm-bench",
"crates/libm-macros",
"crates/libm-test",
"crates/musl-math-sys",
]
default-members = [
".",
"crates/libm-macros",
"crates/libm-test",
]

Expand Down
5 changes: 5 additions & 0 deletions ci/docker/i586-unknown-linux-gnu/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM ubuntu:24.04

RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc-multilib libc6-dev ca-certificates
15 changes: 15 additions & 0 deletions ci/docker/riscv64gc-unknown-linux-gnu/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM ubuntu:24.04

RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc libc6-dev qemu-user-static ca-certificates \
gcc-riscv64-linux-gnu libc6-dev-riscv64-cross \
qemu-system-riscv64

ENV TOOLCHAIN_PREFIX=riscv64-linux-gnu-
ENV CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_LINKER="$TOOLCHAIN_PREFIX"gcc \
CARGO_TARGET_RISCV64GC_UNKNOWN_LINUX_GNU_RUNNER=qemu-riscv64-static \
AR_riscv64gc_unknown_linux_gnu="$TOOLCHAIN_PREFIX"ar \
CC_riscv64gc_unknown_linux_gnu="$TOOLCHAIN_PREFIX"gcc \
QEMU_LD_PREFIX=/usr/riscv64-linux-gnu \
RUST_TEST_THREADS=1
9 changes: 9 additions & 0 deletions ci/docker/thumbv6m-none-eabi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ARG IMAGE=ubuntu:24.04
FROM $IMAGE

RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc libc6-dev ca-certificates \
gcc-arm-none-eabi \
libnewlib-arm-none-eabi
ENV BUILD_ONLY=1
9 changes: 9 additions & 0 deletions ci/docker/thumbv7em-none-eabi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ARG IMAGE=ubuntu:24.04
FROM $IMAGE

RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc libc6-dev ca-certificates \
gcc-arm-none-eabi \
libnewlib-arm-none-eabi
ENV BUILD_ONLY=1
9 changes: 9 additions & 0 deletions ci/docker/thumbv7em-none-eabihf/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ARG IMAGE=ubuntu:24.04
FROM $IMAGE

RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc libc6-dev ca-certificates \
gcc-arm-none-eabi \
libnewlib-arm-none-eabi
ENV BUILD_ONLY=1
9 changes: 9 additions & 0 deletions ci/docker/thumbv7m-none-eabi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ARG IMAGE=ubuntu:24.04
FROM $IMAGE

RUN apt-get update && \
apt-get install -y --no-install-recommends \
gcc libc6-dev ca-certificates \
gcc-arm-none-eabi \
libnewlib-arm-none-eabi
ENV BUILD_ONLY=1
24 changes: 24 additions & 0 deletions ci/download-musl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
# Download the expected version of musl to a directory `musl`

set -eux

fname=musl-1.2.5.tar.gz
sha=a9a118bbe84d8764da0ea0d28b3ab3fae8477fc7e4085d90102b8596fc7c75e4

mkdir musl
curl "https://musl.libc.org/releases/$fname" -O

case "$(uname -s)" in
MINGW*)
# Need to extract the second line because certutil does human output
fsha=$(certutil -hashfile "$fname" SHA256 | sed -n '2p')
[ "$sha" = "$fsha" ] || exit 1
;;
*)
echo "$sha $fname" | shasum -a 256 --check || exit 1
;;
esac

tar -xzf "$fname" -C musl --strip-components 1
rm "$fname"
1 change: 1 addition & 0 deletions ci/run-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ run() {
-e RUSTFLAGS \
-e CARGO_HOME=/cargo \
-e CARGO_TARGET_DIR=/target \
-e EMULATED=1 \
-v "${HOME}/.cargo:/cargo" \
-v "$(pwd)/target:/target" \
-v "$(pwd):/checkout:ro" \
Expand Down
69 changes: 56 additions & 13 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,64 @@

set -eux

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

cmd="cargo test --all --target $target"
target="${1:-}"

# Needed for no-panic to correct detect a lack of panics
export RUSTFLAGS="$RUSTFLAGS -Ccodegen-units=1"
if [ -z "$target" ]; then
host_target=$(rustc -vV | awk '/^host/ { print $2 }')
echo "Defaulted to host target $host_target"
target="$host_target"
fi

extra_flags=""

# We need to specifically skip tests for musl-math-sys on systems that can't
# build musl since otherwise `--all` will activate it.
case "$target" in
# Can't build at all on MSVC, WASM, or thumb
*windows-msvc*) extra_flags="$extra_flags --exclude musl-math-sys" ;;
*wasm*) extra_flags="$extra_flags --exclude musl-math-sys" ;;
*thumb*) extra_flags="$extra_flags --exclude musl-math-sys" ;;

# We can build musl on MinGW but running tests gets a stack overflow
*windows-gnu*) ;;
# FIXME(#309): LE PPC crashes calling the musl version of some functions. It
# seems like a qemu bug but should be investigated further at some point.
# See </~https://github.com/rust-lang/libm/issues/309>.
*powerpc64le*) ;;

# Everything else gets musl enabled
*) extra_flags="$extra_flags --features libm-test/build-musl" ;;
esac

# FIXME: `STATUS_DLL_NOT_FOUND` testing macros on CI.
# </~https://github.com/rust-lang/rust/issues/128944>
case "$target" in
*windows-gnu) extra_flags="$extra_flags --exclude libm-macros" ;;
esac

if [ "$(uname -a)" = "Linux" ]; then
# also run the reference tests when we can. requires a Linux host.
extra_flags="$extra_flags --features libm-test/test-musl-serialized"
fi

if [ "${BUILD_ONLY:-}" = "1" ]; then
cmd="cargo build --target $target --package libm"
$cmd
$cmd --features 'unstable'

# stable by default
$cmd
$cmd --release
echo "can't run tests on $target"
else
cmd="cargo test --all --target $target $extra_flags"

# unstable with a feature
$cmd --features 'unstable'
$cmd --release --features 'unstable'
# stable by default
$cmd
$cmd --release

# also run the reference tests
$cmd --features 'unstable libm-test/test-musl-serialized'
$cmd --release --features 'unstable libm-test/test-musl-serialized'
# unstable with a feature
$cmd --features 'unstable'
$cmd --release --features 'unstable'
fi
12 changes: 12 additions & 0 deletions crates/libm-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "libm-macros"
version = "0.1.0"
edition = "2021"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = "1.0.88"
quote = "1.0.37"
syn = { version = "2.0.79", features = ["full", "extra-traits", "visit-mut"] }
Loading