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