|
| 1 | +name: CI |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - master |
| 6 | + pull_request: |
| 7 | + |
| 8 | +concurrency: |
| 9 | + # Make sure that new pushes cancel running jobs |
| 10 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +env: |
| 14 | + CARGO_TERM_COLOR: always |
| 15 | + RUSTDOCFLAGS: -Dwarnings |
| 16 | + RUSTFLAGS: -Dwarnings |
| 17 | + RUST_BACKTRACE: full |
| 18 | + BENCHMARK_RUSTC: nightly-2025-01-16 # Pin the toolchain for reproducable results |
| 19 | + |
| 20 | +jobs: |
| 21 | + test: |
| 22 | + name: Build and test |
| 23 | + timeout-minutes: 60 |
| 24 | + strategy: |
| 25 | + fail-fast: false |
| 26 | + matrix: |
| 27 | + include: |
| 28 | + - target: aarch64-apple-darwin |
| 29 | + os: macos-15 |
| 30 | + # FIXME: pinned due to https://github.com/llvm/llvm-project/issues/127804 |
| 31 | + channel: nightly-2025-02-07 |
| 32 | + - target: aarch64-unknown-linux-gnu |
| 33 | + os: ubuntu-24.04-arm |
| 34 | + # FIXME: pinned due to https://github.com/llvm/llvm-project/issues/127804 |
| 35 | + channel: nightly-2025-02-07 |
| 36 | + - target: aarch64-pc-windows-msvc |
| 37 | + os: windows-2025 |
| 38 | + build_only: 1 # Can't run on x86 hosts |
| 39 | + - target: arm-unknown-linux-gnueabi |
| 40 | + os: ubuntu-24.04 |
| 41 | + - target: arm-unknown-linux-gnueabihf |
| 42 | + os: ubuntu-24.04 |
| 43 | + - target: armv7-unknown-linux-gnueabihf |
| 44 | + os: ubuntu-24.04 |
| 45 | + - target: i586-unknown-linux-gnu |
| 46 | + os: ubuntu-24.04 |
| 47 | + - target: i686-unknown-linux-gnu |
| 48 | + os: ubuntu-24.04 |
| 49 | + - target: loongarch64-unknown-linux-gnu |
| 50 | + os: ubuntu-24.04 |
| 51 | + - target: powerpc-unknown-linux-gnu |
| 52 | + os: ubuntu-24.04 |
| 53 | + - target: powerpc64-unknown-linux-gnu |
| 54 | + os: ubuntu-24.04 |
| 55 | + - target: powerpc64le-unknown-linux-gnu |
| 56 | + os: ubuntu-24.04 |
| 57 | + - target: riscv64gc-unknown-linux-gnu |
| 58 | + os: ubuntu-24.04 |
| 59 | + - target: thumbv6m-none-eabi |
| 60 | + os: ubuntu-24.04 |
| 61 | + - target: thumbv7em-none-eabi |
| 62 | + os: ubuntu-24.04 |
| 63 | + - target: thumbv7em-none-eabihf |
| 64 | + os: ubuntu-24.04 |
| 65 | + - target: thumbv7m-none-eabi |
| 66 | + os: ubuntu-24.04 |
| 67 | + - target: x86_64-unknown-linux-gnu |
| 68 | + os: ubuntu-24.04 |
| 69 | + - target: x86_64-apple-darwin |
| 70 | + os: macos-13 |
| 71 | + - target: wasm32-unknown-unknown |
| 72 | + os: ubuntu-24.04 |
| 73 | + build_only: 1 |
| 74 | + - target: i686-pc-windows-msvc |
| 75 | + os: windows-2025 |
| 76 | + - target: x86_64-pc-windows-msvc |
| 77 | + os: windows-2025 |
| 78 | + - target: i686-pc-windows-gnu |
| 79 | + os: windows-2025 |
| 80 | + # FIXME: pinned due to https://github.com/rust-lang/rust/issues/136795 |
| 81 | + channel: nightly-2025-02-07-i686-gnu |
| 82 | + - target: x86_64-pc-windows-gnu |
| 83 | + os: windows-2025 |
| 84 | + channel: nightly-x86_64-gnu |
| 85 | + runs-on: ${{ matrix.os }} |
| 86 | + env: |
| 87 | + BUILD_ONLY: ${{ matrix.build_only }} |
| 88 | + steps: |
| 89 | + - name: Print runner information |
| 90 | + run: uname -a |
| 91 | + - uses: actions/checkout@v4 |
| 92 | + with: |
| 93 | + submodules: true |
| 94 | + - name: Install Rust (rustup) |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + channel="nightly" |
| 98 | + # Account for channels that have required components (MinGW) |
| 99 | + [ -n "${{ matrix.channel }}" ] && channel="${{ matrix.channel }}" |
| 100 | + rustup update "$channel" --no-self-update |
| 101 | + rustup default "$channel" |
| 102 | + rustup target add "${{ matrix.target }}" |
| 103 | + rustup component add clippy llvm-tools-preview |
| 104 | + - uses: taiki-e/install-action@nextest |
| 105 | + - uses: Swatinem/rust-cache@v2 |
| 106 | + with: |
| 107 | + key: ${{ matrix.target }} |
| 108 | + |
| 109 | + - name: Verify API list |
| 110 | + if: matrix.os == 'ubuntu-24.04' |
| 111 | + run: python3 etc/update-api-list.py --check |
| 112 | + |
| 113 | + # Non-linux tests just use our raw script |
| 114 | + - name: Run locally |
| 115 | + if: matrix.os != 'ubuntu-24.04' || contains(matrix.target, 'wasm') |
| 116 | + shell: bash |
| 117 | + run: ./ci/run.sh ${{ matrix.target }} |
| 118 | + |
| 119 | + # Otherwise we use our docker containers to run builds |
| 120 | + - name: Run in Docker |
| 121 | + if: matrix.os == 'ubuntu-24.04' && !contains(matrix.target, 'wasm') |
| 122 | + run: | |
| 123 | + rustup target add x86_64-unknown-linux-musl |
| 124 | + cargo generate-lockfile && ./ci/run-docker.sh ${{ matrix.target }} |
| 125 | +
|
| 126 | + - name: Print test logs if available |
| 127 | + if: always() |
| 128 | + run: if [ -f "target/test-log.txt" ]; then cat target/test-log.txt; fi |
| 129 | + shell: bash |
| 130 | + |
| 131 | + clippy: |
| 132 | + name: Clippy |
| 133 | + runs-on: ubuntu-24.04 |
| 134 | + timeout-minutes: 10 |
| 135 | + steps: |
| 136 | + - uses: actions/checkout@master |
| 137 | + with: |
| 138 | + submodules: true |
| 139 | + - name: Install Rust |
| 140 | + run: | |
| 141 | + rustup update nightly --no-self-update |
| 142 | + rustup default nightly |
| 143 | + rustup component add clippy |
| 144 | + - uses: Swatinem/rust-cache@v2 |
| 145 | + - run: cargo clippy --all --all-features --all-targets |
| 146 | + |
| 147 | + builtins: |
| 148 | + name: Check use with compiler-builtins |
| 149 | + runs-on: ubuntu-24.04 |
| 150 | + timeout-minutes: 10 |
| 151 | + steps: |
| 152 | + - uses: actions/checkout@master |
| 153 | + - name: Install Rust |
| 154 | + run: rustup update nightly --no-self-update && rustup default nightly |
| 155 | + - uses: Swatinem/rust-cache@v2 |
| 156 | + - run: cargo check --manifest-path crates/compiler-builtins-smoke-test/Cargo.toml |
| 157 | + - run: cargo test --manifest-path crates/compiler-builtins-smoke-test/Cargo.toml |
| 158 | + |
| 159 | + benchmarks: |
| 160 | + name: Benchmarks |
| 161 | + runs-on: ubuntu-24.04 |
| 162 | + timeout-minutes: 20 |
| 163 | + steps: |
| 164 | + - uses: actions/checkout@master |
| 165 | + with: |
| 166 | + submodules: true |
| 167 | + - uses: taiki-e/install-action@cargo-binstall |
| 168 | + |
| 169 | + - name: Set up dependencies |
| 170 | + run: | |
| 171 | + sudo apt update |
| 172 | + sudo apt install -y valgrind gdb libc6-dbg # Needed for iai-callgrind |
| 173 | + rustup update "$BENCHMARK_RUSTC" --no-self-update |
| 174 | + rustup default "$BENCHMARK_RUSTC" |
| 175 | + # Install the version of iai-callgrind-runner that is specified in Cargo.toml |
| 176 | + iai_version="$(cargo metadata --format-version=1 --features icount | |
| 177 | + jq -r '.packages[] | select(.name == "iai-callgrind").version')" |
| 178 | + cargo binstall -y iai-callgrind-runner --version "$iai_version" |
| 179 | + sudo apt-get install valgrind |
| 180 | +
|
| 181 | + - uses: Swatinem/rust-cache@v2 |
| 182 | + |
| 183 | + - name: Run icount benchmarks |
| 184 | + env: |
| 185 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 186 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 187 | + run: ./ci/bench-icount.sh |
| 188 | + |
| 189 | + - name: Upload the benchmark baseline |
| 190 | + uses: actions/upload-artifact@v4 |
| 191 | + with: |
| 192 | + name: ${{ env.BASELINE_NAME }} |
| 193 | + path: ${{ env.BASELINE_NAME }}.tar.xz |
| 194 | + |
| 195 | + - name: Run wall time benchmarks |
| 196 | + run: | |
| 197 | + # Always use the same seed for benchmarks. Ideally we should switch to a |
| 198 | + # non-random generator. |
| 199 | + export LIBM_SEED=benchesbenchesbenchesbencheswoo! |
| 200 | + cargo bench --all --features short-benchmarks,build-musl,force-soft-floats |
| 201 | +
|
| 202 | + - name: Print test logs if available |
| 203 | + if: always() |
| 204 | + run: if [ -f "target/test-log.txt" ]; then cat target/test-log.txt; fi |
| 205 | + shell: bash |
| 206 | + |
| 207 | + msrv: |
| 208 | + name: Check MSRV |
| 209 | + runs-on: ubuntu-24.04 |
| 210 | + timeout-minutes: 10 |
| 211 | + env: |
| 212 | + RUSTFLAGS: # No need to check warnings on old MSRV, unset `-Dwarnings` |
| 213 | + steps: |
| 214 | + - uses: actions/checkout@master |
| 215 | + - name: Install Rust |
| 216 | + run: | |
| 217 | + msrv="$(perl -ne 'print if s/rust-version\s*=\s*"(.*)"/\1/g' libm/Cargo.toml)" |
| 218 | + echo "MSRV: $msrv" |
| 219 | + rustup update "$msrv" --no-self-update && rustup default "$msrv" |
| 220 | + - uses: Swatinem/rust-cache@v2 |
| 221 | + - run: | |
| 222 | + # FIXME(msrv): Remove the workspace Cargo.toml so 1.63 cargo doesn't see |
| 223 | + # `edition = "2024"` and get spooked. |
| 224 | + rm Cargo.toml |
| 225 | + cargo build --manifest-path libm/Cargo.toml |
| 226 | +
|
| 227 | + rustfmt: |
| 228 | + name: Rustfmt |
| 229 | + runs-on: ubuntu-24.04 |
| 230 | + timeout-minutes: 10 |
| 231 | + steps: |
| 232 | + - uses: actions/checkout@master |
| 233 | + - name: Install Rust |
| 234 | + run: | |
| 235 | + rustup update nightly --no-self-update |
| 236 | + rustup default nightly |
| 237 | + rustup component add rustfmt |
| 238 | + - run: cargo fmt -- --check |
| 239 | + |
| 240 | + # Determine which extensive tests should be run based on changed files. |
| 241 | + calculate_extensive_matrix: |
| 242 | + name: Calculate job matrix |
| 243 | + runs-on: ubuntu-24.04 |
| 244 | + timeout-minutes: 10 |
| 245 | + env: |
| 246 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 247 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 248 | + outputs: |
| 249 | + matrix: ${{ steps.script.outputs.matrix }} |
| 250 | + steps: |
| 251 | + - uses: actions/checkout@v4 |
| 252 | + with: |
| 253 | + fetch-depth: 100 |
| 254 | + - name: Fetch pull request ref |
| 255 | + run: git fetch origin "$GITHUB_REF:$GITHUB_REF" |
| 256 | + if: github.event_name == 'pull_request' |
| 257 | + - run: python3 ci/ci-util.py generate-matrix >> "$GITHUB_OUTPUT" |
| 258 | + id: script |
| 259 | + |
| 260 | + extensive: |
| 261 | + name: Extensive tests for ${{ matrix.ty }} |
| 262 | + needs: |
| 263 | + # Wait on `clippy` so we have some confidence that the crate will build |
| 264 | + - clippy |
| 265 | + - calculate_extensive_matrix |
| 266 | + runs-on: ubuntu-24.04 |
| 267 | + timeout-minutes: 240 # 4 hours |
| 268 | + strategy: |
| 269 | + matrix: |
| 270 | + # Use the output from `calculate_extensive_matrix` to calculate the matrix |
| 271 | + # FIXME: it would be better to run all jobs (i.e. all types) but mark those that |
| 272 | + # didn't change as skipped, rather than completely excluding the job. However, |
| 273 | + # this is not currently possible https://github.com/actions/runner/issues/1985. |
| 274 | + include: ${{ fromJSON(needs.calculate_extensive_matrix.outputs.matrix).matrix }} |
| 275 | + env: |
| 276 | + TO_TEST: ${{ matrix.to_test }} |
| 277 | + steps: |
| 278 | + - uses: actions/checkout@v4 |
| 279 | + with: |
| 280 | + submodules: true |
| 281 | + - name: Install Rust |
| 282 | + run: | |
| 283 | + rustup update nightly --no-self-update |
| 284 | + rustup default nightly |
| 285 | + - uses: Swatinem/rust-cache@v2 |
| 286 | + - name: Run extensive tests |
| 287 | + run: | |
| 288 | + echo "Tests to run: '$TO_TEST'" |
| 289 | + if [ -z "$TO_TEST" ]; then |
| 290 | + echo "No tests to run, exiting." |
| 291 | + exit |
| 292 | + fi |
| 293 | +
|
| 294 | + set -x |
| 295 | +
|
| 296 | + # Run the non-extensive tests first to catch any easy failures |
| 297 | + cargo t --profile release-checked -- "$TO_TEST" |
| 298 | +
|
| 299 | + LIBM_EXTENSIVE_TESTS="$TO_TEST" cargo t \ |
| 300 | + --features build-mpfr,unstable,force-soft-floats \ |
| 301 | + --profile release-checked \ |
| 302 | + -- extensive |
| 303 | + - name: Print test logs if available |
| 304 | + run: if [ -f "target/test-log.txt" ]; then cat target/test-log.txt; fi |
| 305 | + shell: bash |
| 306 | + |
| 307 | + success: |
| 308 | + needs: |
| 309 | + - test |
| 310 | + - builtins |
| 311 | + - benchmarks |
| 312 | + - msrv |
| 313 | + - rustfmt |
| 314 | + - extensive |
| 315 | + runs-on: ubuntu-24.04 |
| 316 | + timeout-minutes: 10 |
| 317 | + # GitHub branch protection is exceedingly silly and treats "jobs skipped because a dependency |
| 318 | + # failed" as success. So we have to do some contortions to ensure the job fails if any of its |
| 319 | + # dependencies fails. |
| 320 | + if: always() # make sure this is never "skipped" |
| 321 | + steps: |
| 322 | + # Manually check the status of all dependencies. `if: failure()` does not work. |
| 323 | + - name: check if any dependency failed |
| 324 | + run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}' |
0 commit comments