about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2025-04-20 04:40:12 +0000
committerTrevor Gross <t.gross35@gmail.com>2025-04-20 03:22:27 -0400
commit9c96f245b8e7b40d46653dcc77970a8308c3b012 (patch)
tree3fe2b75feef3efaab44f1acdfca1390df9eee642
parentd0e0134dc56b764a4f8f0a4971f737e2fbbbef21 (diff)
downloadrust-9c96f245b8e7b40d46653dcc77970a8308c3b012.tar.gz
rust-9c96f245b8e7b40d46653dcc77970a8308c3b012.zip
ci: Enable testing of `libm` crates
Update `run.sh` to start testing `libm`. Currently this is somewhat
inefficient because `builtins-test` gets run more than once on some
targets; this can be cleaned up later.
-rw-r--r--library/compiler-builtins/.github/workflows/main.yaml12
-rw-r--r--library/compiler-builtins/Cargo.toml35
-rwxr-xr-xlibrary/compiler-builtins/ci/run.sh167
-rwxr-xr-xlibrary/compiler-builtins/etc/libm/ci/run-docker.sh56
-rwxr-xr-xlibrary/compiler-builtins/etc/libm/ci/run.sh130
-rw-r--r--library/compiler-builtins/libm-test/Cargo.toml3
6 files changed, 176 insertions, 227 deletions
diff --git a/library/compiler-builtins/.github/workflows/main.yaml b/library/compiler-builtins/.github/workflows/main.yaml
index 8f8ac033a13..95ed6a855f3 100644
--- a/library/compiler-builtins/.github/workflows/main.yaml
+++ b/library/compiler-builtins/.github/workflows/main.yaml
@@ -97,6 +97,7 @@ jobs:
         rustup default "$channel"
         rustup target add "${{ matrix.target }}"
         rustup component add llvm-tools-preview
+    - uses: taiki-e/install-action@nextest
     - uses: Swatinem/rust-cache@v2
       with:
         key: ${{ matrix.target }}
@@ -107,7 +108,7 @@ jobs:
         path: /tmp/.buildx-cache
         key: ${{ matrix.target }}-buildx-${{ github.sha }}
         restore-keys: ${{ matrix.target }}-buildx-
-        
+
     - name: Cache compiler-rt
       id: cache-compiler-rt
       uses: actions/cache@v4
@@ -121,6 +122,10 @@ jobs:
     - run: echo "RUST_COMPILER_RT_ROOT=$(realpath ./compiler-rt)" >> "$GITHUB_ENV"
       shell: bash
 
+    - name: Verify API list
+      if: matrix.os == 'ubuntu-24.04'
+      run: python3 etc/update-api-list.py --check
+
     # Non-linux tests just use our raw script
     - name: Run locally
       if: matrix.os != 'ubuntu-24.04'
@@ -136,6 +141,11 @@ jobs:
       if: matrix.os == 'ubuntu-24.04'
       run: cargo generate-lockfile && ./ci/run-docker.sh ${{ matrix.target }}
 
+    - name: Print test logs if available
+      if: always()
+      run: if [ -f "target/test-log.txt" ]; then cat target/test-log.txt; fi
+      shell: bash
+
     # Workaround to keep Docker cache smaller
     # https://github.com/docker/build-push-action/issues/252
     # https://github.com/moby/buildkit/issues/1896
diff --git a/library/compiler-builtins/Cargo.toml b/library/compiler-builtins/Cargo.toml
index 194a2cdc2f7..c3737a042f5 100644
--- a/library/compiler-builtins/Cargo.toml
+++ b/library/compiler-builtins/Cargo.toml
@@ -31,22 +31,19 @@ panic = "abort"
 [profile.dev]
 panic = "abort"
 
-# FIXME(libm): these profiles are needed for testing
-# # The default release profile is unchanged.
-
-# # Release mode with debug assertions
-# [profile.release-checked]
-# inherits = "release"
-# debug-assertions = true
-# overflow-checks = true
-
-# # Release with maximum optimizations, which is very slow to build. This is also
-# # what is needed to check `no-panic`.
-# [profile.release-opt]
-# inherits = "release"
-# codegen-units = 1
-# lto = "fat"
-
-# [profile.bench]
-# # Required for iai-callgrind
-# debug = true
+# Release mode with debug assertions
+[profile.release-checked]
+inherits = "release"
+debug-assertions = true
+overflow-checks = true
+
+# Release with maximum optimizations, which is very slow to build. This is also
+# what is needed to check `no-panic`.
+[profile.release-opt]
+inherits = "release"
+codegen-units = 1
+lto = "fat"
+
+[profile.bench]
+# Required for iai-callgrind
+debug = true
diff --git a/library/compiler-builtins/ci/run.sh b/library/compiler-builtins/ci/run.sh
index bce90d48d50..730079be789 100755
--- a/library/compiler-builtins/ci/run.sh
+++ b/library/compiler-builtins/ci/run.sh
@@ -13,6 +13,11 @@ if [ -z "$target" ]; then
     target="$host_target"
 fi
 
+if [[ "$target" = *"wasm"* ]]; then
+    # Enable the random backend
+    export RUSTFLAGS="${RUSTFLAGS:-} --cfg getrandom_backend=\"wasm_js\""
+fi
+
 if [ "${USING_CONTAINER_RUSTC:-}" = 1 ]; then
     # Install nonstandard components if we have control of the environment
     rustup target list --installed |
@@ -22,27 +27,27 @@ fi
 
 # Test our implementation
 if [ "${BUILD_ONLY:-}" = "1" ]; then
-    echo "nothing to do for no_std"
+    echo "no tests to run for build-only targets"
 else
-    run="cargo test --package builtins-test --no-fail-fast --target $target"
-    $run
-    $run --release
-    $run --features c
-    $run --features c --release
-    $run --features no-asm
-    $run --features no-asm --release
-    $run --features no-f16-f128
-    $run --features no-f16-f128 --release
-    $run --benches
-    $run --benches --release
-fi
+    test_builtins=(cargo test --package builtins-test --no-fail-fast --target "$target")
+    "${test_builtins[@]}"
+    "${test_builtins[@]}" --release
+    "${test_builtins[@]}" --features c
+    "${test_builtins[@]}" --features c --release
+    "${test_builtins[@]}" --features no-asm
+    "${test_builtins[@]}" --features no-asm --release
+    "${test_builtins[@]}" --features no-f16-f128
+    "${test_builtins[@]}" --features no-f16-f128 --release
+    "${test_builtins[@]}" --benches
+    "${test_builtins[@]}" --benches --release
 
-if [ "${TEST_VERBATIM:-}" = "1" ]; then
-    verb_path=$(cmd.exe //C echo \\\\?\\%cd%\\builtins-test\\target2)
-    cargo build --package builtins-test \
-        --target "$target" --target-dir "$verb_path" --features c
+    if [ "${TEST_VERBATIM:-}" = "1" ]; then
+        verb_path=$(cmd.exe //C echo \\\\?\\%cd%\\builtins-test\\target2)
+        "${test_builtins[@]}" --target-dir "$verb_path" --features c
+    fi
 fi
 
+
 declare -a rlib_paths
 
 # Set the `rlib_paths` global array to a list of all compiler-builtins rlibs
@@ -61,11 +66,11 @@ rm -f "${rlib_paths[@]}"
 cargo build -p compiler_builtins --target "$target"
 cargo build -p compiler_builtins --target "$target" --release
 cargo build -p compiler_builtins --target "$target" --features c
-cargo build -p compiler_builtins --target "$target" --release --features c
+cargo build -p compiler_builtins --target "$target" --features c --release
 cargo build -p compiler_builtins --target "$target" --features no-asm
-cargo build -p compiler_builtins --target "$target" --release --features no-asm
+cargo build -p compiler_builtins --target "$target" --features no-asm --release
 cargo build -p compiler_builtins --target "$target" --features no-f16-f128
-cargo build -p compiler_builtins --target "$target" --release --features no-f16-f128
+cargo build -p compiler_builtins --target "$target" --features no-f16-f128 --release
 
 PREFIX=${target//unknown-/}-
 case "$target" in
@@ -167,4 +172,124 @@ for rlib in "${rlib_paths[@]}"; do
     fi
 done
 
-true
+# Test libm
+
+mflags=()
+
+# We enumerate features manually.
+mflags+=(--no-default-features)
+
+# Enable arch-specific routines when available.
+mflags+=(--features arch)
+
+# Always enable `unstable-float` since it expands available API but does not
+# change any implementations.
+mflags+=(--features unstable-float)
+
+# 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*) mflags+=(--exclude musl-math-sys) ;;
+    *wasm*) mflags+=(--exclude musl-math-sys) ;;
+    *thumb*) mflags+=(--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
+    *) mflags+=(--features libm-test/build-musl) ;;
+esac
+
+
+# Configure which targets test against MPFR
+case "$target" in
+    # MSVC cannot link MPFR
+    *windows-msvc*) ;;
+    # FIXME: MinGW should be able to build MPFR, but setup in CI is nontrivial.
+    *windows-gnu*) ;;
+    # Targets that aren't cross compiled in CI work fine
+    aarch64*apple*) mflags+=(--features libm-test/build-mpfr) ;;
+    aarch64*linux*) mflags+=(--features libm-test/build-mpfr) ;;
+    i586*) mflags+=(--features libm-test/build-mpfr --features gmp-mpfr-sys/force-cross) ;;
+    i686*) mflags+=(--features libm-test/build-mpfr) ;;
+    x86_64*) mflags+=(--features libm-test/build-mpfr) ;;
+esac
+
+# FIXME: `STATUS_DLL_NOT_FOUND` testing macros on CI.
+# <https://github.com/rust-lang/rust/issues/128944>
+case "$target" in
+    *windows-gnu) mflags+=(--exclude libm-macros) ;;
+esac
+
+# Make sure a simple build works
+cargo check -p libm --no-default-features --target "$target"
+
+
+if [ "${BUILD_ONLY:-}" = "1" ]; then
+    # If we are on targets that can't run tests, verify that we can build.
+    cmd=(cargo build --target "$target" --package libm)
+    "${cmd[@]}"
+    "${cmd[@]}" --features unstable-intrinsics
+
+    echo "can't run tests on $target; skipping"
+else
+    mflags+=(--workspace --target "$target")
+    cmd=(cargo test "${mflags[@]}")
+    profile_flag="--profile"
+    
+    # If nextest is available, use that
+    command -v cargo-nextest && nextest=1 || nextest=0
+    if [ "$nextest" = "1" ]; then
+        cmd=(cargo nextest run --max-fail=10)
+
+        # Workaround for https://github.com/nextest-rs/nextest/issues/2066
+        if [ -f /.dockerenv ]; then
+            cfg_file="/tmp/nextest-config.toml"
+            echo "[store]" >> "$cfg_file"
+            echo "dir = \"$CARGO_TARGET_DIR/nextest\"" >> "$cfg_file"
+            cmd+=(--config-file "$cfg_file")
+        fi
+
+        cmd+=("${mflags[@]}")
+        profile_flag="--cargo-profile"
+    fi
+
+    # Test once without intrinsics
+    "${cmd[@]}"
+
+    # Run doctests if they were excluded by nextest
+    [ "$nextest" = "1" ] && cargo test --doc --exclude compiler_builtins "${mflags[@]}"
+
+    # Exclude the macros and utile crates from the rest of the tests to save CI
+    # runtime, they shouldn't have anything feature- or opt-level-dependent.
+    cmd+=(--exclude util --exclude libm-macros)
+
+    # Test once with intrinsics enabled
+    "${cmd[@]}" --features unstable-intrinsics
+    "${cmd[@]}" --features unstable-intrinsics --benches
+
+    # Test the same in release mode, which also increases coverage. Also ensure
+    # the soft float routines are checked.
+    "${cmd[@]}" "$profile_flag" release-checked
+    "${cmd[@]}" "$profile_flag" release-checked --features force-soft-floats
+    "${cmd[@]}" "$profile_flag" release-checked --features unstable-intrinsics
+    "${cmd[@]}" "$profile_flag" release-checked --features unstable-intrinsics --benches
+
+    # Ensure that the routines do not panic.
+    # 
+    # `--tests` must be passed because no-panic is only enabled as a dev
+    # dependency. The `release-opt` profile must be used to enable LTO and a
+    # single CGU.
+    ENSURE_NO_PANIC=1 cargo build \
+        -p libm \
+        --target "$target" \
+        --no-default-features \
+        --features unstable-float \
+        --tests \
+        --profile release-opt
+fi
diff --git a/library/compiler-builtins/etc/libm/ci/run-docker.sh b/library/compiler-builtins/etc/libm/ci/run-docker.sh
deleted file mode 100755
index 6626e722685..00000000000
--- a/library/compiler-builtins/etc/libm/ci/run-docker.sh
+++ /dev/null
@@ -1,56 +0,0 @@
-#!/bin/bash
-
-# Small script to run tests for a target (or all targets) inside all the
-# respective docker images.
-
-set -euxo pipefail
-
-host_arch="$(uname -m | sed 's/arm64/aarch64/')"
-
-run() {
-    local target=$1
-
-    echo "testing target: $target"
-
-    target_arch="$(echo "$target" | cut -d'-' -f1)"
-
-    emulated=""
-    if [ "$target_arch" != "$host_arch" ]; then
-        emulated=1
-        echo "target is emulated"
-    fi
-
-    # This directory needs to exist before calling docker, otherwise docker will create it but it
-    # will be owned by root
-    mkdir -p target
-
-    set_env="HOME=/tmp PATH=\$PATH:/rust/bin:/cargo/bin"
-    docker build -t "libm-$target" "ci/docker/$target"
-    docker run \
-        --rm \
-        --user "$(id -u):$(id -g)" \
-        -e CI \
-        -e RUSTFLAGS \
-        -e CARGO_TERM_COLOR \
-        -e CARGO_HOME=/cargo \
-        -e CARGO_TARGET_DIR=/target \
-        -e "EMULATED=$emulated" \
-        -v "${HOME}/.cargo:/cargo" \
-        -v "$(pwd)/target:/target" \
-        -v "$(pwd):/checkout:ro" \
-        -v "$(rustc --print sysroot):/rust:ro" \
-        --init \
-        -w /checkout \
-        "libm-$target" \
-        sh -c "$set_env exec ci/run.sh $target"
-}
-
-if [ -z "$1" ]; then
-    echo "running tests for all targets"
-
-    for d in ci/docker/*; do
-        run $d
-    done
-else
-    run $1
-fi
diff --git a/library/compiler-builtins/etc/libm/ci/run.sh b/library/compiler-builtins/etc/libm/ci/run.sh
deleted file mode 100755
index a946d325ebd..00000000000
--- a/library/compiler-builtins/etc/libm/ci/run.sh
+++ /dev/null
@@ -1,130 +0,0 @@
-#!/bin/sh
-
-set -eux
-
-export RUST_BACKTRACE="${RUST_BACKTRACE:-full}"
-export NEXTEST_STATUS_LEVEL=all
-
-target="${1:-}"
-flags=""
-
-if [ -z "$target" ]; then
-    host_target=$(rustc -vV | awk '/^host/ { print $2 }')
-    echo "Defaulted to host target $host_target"
-    target="$host_target"
-fi
-
-# We enumerate features manually.
-flags="$flags --no-default-features"
-
-# Enable arch-specific routines when available.
-flags="$flags --features arch"
-
-# Always enable `unstable-float` since it expands available API but does not
-# change any implementations.
-flags="$flags --features unstable-float"
-
-# 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*) flags="$flags --exclude musl-math-sys" ;;
-    *wasm*) flags="$flags --exclude musl-math-sys" ;;
-    *thumb*) flags="$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
-    *) flags="$flags --features libm-test/build-musl" ;;
-esac
-
-# Configure which targets test against MPFR
-case "$target" in
-    # MSVC cannot link MPFR
-    *windows-msvc*) ;;
-    # FIXME: MinGW should be able to build MPFR, but setup in CI is nontrivial.
-    *windows-gnu*) ;;
-    # Targets that aren't cross compiled in CI work fine
-    aarch64*apple*) flags="$flags --features libm-test/build-mpfr" ;;
-    aarch64*linux*) flags="$flags --features libm-test/build-mpfr" ;;
-    i586*) flags="$flags --features libm-test/build-mpfr --features gmp-mpfr-sys/force-cross" ;;
-    i686*) flags="$flags --features libm-test/build-mpfr" ;;
-    x86_64*) flags="$flags --features libm-test/build-mpfr" ;;
-esac
-
-# FIXME: `STATUS_DLL_NOT_FOUND` testing macros on CI.
-# <https://github.com/rust-lang/rust/issues/128944>
-case "$target" in
-    *windows-gnu) flags="$flags --exclude libm-macros" ;;
-esac
-
-# Make sure we can build with overriding features.
-cargo check -p libm --no-default-features
-
-if [ "${BUILD_ONLY:-}" = "1" ]; then
-    # If we are on targets that can't run tests, verify that we can build.
-    cmd="cargo build --target $target --package libm"
-    $cmd
-    $cmd --features unstable-intrinsics
-
-    echo "can't run tests on $target; skipping"
-    exit
-fi
-
-flags="$flags --all --target $target"
-cmd="cargo test $flags"
-profile="--profile"
-
-# If nextest is available, use that
-command -v cargo-nextest && nextest=1 || nextest=0
-if [ "$nextest" = "1" ]; then
-    # Workaround for https://github.com/nextest-rs/nextest/issues/2066
-    if [ -f /.dockerenv ]; then
-        cfg_file="/tmp/nextest-config.toml"
-        echo "[store]" >> "$cfg_file"
-        echo "dir = \"$CARGO_TARGET_DIR/nextest\"" >> "$cfg_file"
-        cfg_flag="--config-file $cfg_file"
-    fi
-
-    cmd="cargo nextest run ${cfg_flag:-} --max-fail=10 $flags"
-    profile="--cargo-profile"
-fi
-
-# Test once without intrinsics
-$cmd
-
-# Run doctests if they were excluded by nextest
-[ "$nextest" = "1" ] && cargo test --doc $flags
-
-# Exclude the macros and utile crates from the rest of the tests to save CI
-# runtime, they shouldn't have anything feature- or opt-level-dependent.
-cmd="$cmd --exclude util --exclude libm-macros"
-
-# Test once with intrinsics enabled
-$cmd --features unstable-intrinsics
-$cmd --features unstable-intrinsics --benches
-
-# Test the same in release mode, which also increases coverage. Also ensure
-# the soft float routines are checked.
-$cmd "$profile" release-checked
-$cmd "$profile" release-checked --features force-soft-floats
-$cmd "$profile" release-checked --features unstable-intrinsics
-$cmd "$profile" release-checked --features unstable-intrinsics --benches
-
-# Ensure that the routines do not panic.
-# 
-# `--tests` must be passed because no-panic is only enabled as a dev
-# dependency. The `release-opt` profile must be used to enable LTO and a
-# single CGU.
-ENSURE_NO_PANIC=1 cargo build \
-     -p libm \
-    --target "$target" \
-    --no-default-features \
-    --features unstable-float \
-    --tests \
-    --profile release-opt
diff --git a/library/compiler-builtins/libm-test/Cargo.toml b/library/compiler-builtins/libm-test/Cargo.toml
index c9b3b795837..6fd49774e0c 100644
--- a/library/compiler-builtins/libm-test/Cargo.toml
+++ b/library/compiler-builtins/libm-test/Cargo.toml
@@ -41,6 +41,9 @@ rand_chacha = "0.9.0"
 rayon = "1.10.0"
 rug = { version = "1.27.0", optional = true, default-features = false, features = ["float", "integer", "std"] }
 
+[target.'cfg(target_family = "wasm")'.dependencies]
+getrandom = { version = "0.3.2", features = ["wasm_js"] }
+
 [build-dependencies]
 rand = { version = "0.9.0", optional = true }