1name: CI
2
3on:
4  merge_group:
5  pull_request:
6    branches:
7      - libc-0.2
8
9env:
10  CARGO_TERM_VERBOSE: true
11  LIBC_CI: 1
12
13defaults:
14  run:
15    shell: bash
16
17jobs:
18  style_check:
19    name: Style check
20    runs-on: ubuntu-24.04
21    timeout-minutes: 10
22    steps:
23      - uses: actions/checkout@v4
24      - name: Setup Rust toolchain
25        run: ./ci/install-rust.sh
26      - name: Check style
27        run: ./ci/style.sh
28
29  # This runs `cargo build --target ...` for all T1 and T2 targets`
30  verify_build:
31    name: Verify build
32    strategy:
33      matrix:
34        toolchain: [stable, nightly, 1.63.0]
35        os: [ubuntu-24.04, macos-14, windows-2022]
36        include:
37          - toolchain: beta
38            os: ubuntu-24.04
39    runs-on: ${{ matrix.os }}
40    timeout-minutes: 25
41    env:
42      TOOLCHAIN: ${{ matrix.toolchain }}
43    steps:
44      - uses: actions/checkout@v4
45      - name: Setup Rust toolchain
46        run: ./ci/install-rust.sh
47
48      # FIXME(ci): These `du` statements are temporary for debugging cache
49      - name: Target size before restoring cache
50        run: du -sh target | sort -k 2 || true
51      - uses: Swatinem/rust-cache@v2
52        with:
53          key: ${{ matrix.os }}-${{ matrix.toolchain }}
54      - name: Target size after restoring cache
55        run: du -sh target | sort -k 2 || true
56
57      - name: Execute build.sh
58        run: ./ci/verify-build.sh
59      - name: Target size after job completion
60        run: du -sh target | sort -k 2
61
62  test_tier1:
63    name: Test tier1
64    strategy:
65      matrix:
66        include:
67          - target: i686-unknown-linux-gnu
68            docker: true
69            os: ubuntu-24.04
70          - target: x86_64-unknown-linux-gnu
71            docker: true
72            os: ubuntu-24.04
73          - target: aarch64-apple-darwin
74            os: macos-14
75          - target: x86_64-pc-windows-gnu
76            os: windows-2022
77            env:
78              ARCH_BITS: 64
79              ARCH: x86_64
80          - target: x86_64-pc-windows-msvc
81            os: windows-2022
82          # FIXME: It currently causes segfaults.
83          #- target: i686-pc-windows-gnu
84          #  env:
85          #    ARCH_BITS: 32
86          #    ARCH: i686
87          - target: i686-pc-windows-msvc
88            os: windows-2022
89    runs-on: ${{ matrix.os }}
90    timeout-minutes: 25
91    env:
92      TARGET: ${{ matrix.target }}
93    steps:
94      - uses: actions/checkout@v4
95      - name: Setup Rust toolchain
96        run: ./ci/install-rust.sh
97      - uses: Swatinem/rust-cache@v2
98        with:
99          key: ${{ matrix.target }}
100      - name: Run natively
101        if: "!matrix.docker"
102        run: ./ci/run.sh ${{ matrix.target }}
103      - name: Run in Docker
104        if: "matrix.docker"
105        run: ./ci/run-docker.sh ${{ matrix.target }}
106
107  test_tier2:
108    name: Test tier2
109    needs: [test_tier1, style_check]
110    runs-on: ubuntu-24.04
111    strategy:
112      fail-fast: true
113      max-parallel: 12
114      matrix:
115        target:
116          # FIXME(sparc): this takes much longer to run than any other job, put
117          # it first to make sure it gets a head start.
118          - sparc64-unknown-linux-gnu
119          - aarch64-linux-android
120          - aarch64-unknown-linux-gnu
121          - aarch64-unknown-linux-musl
122          - arm-linux-androideabi
123          - arm-unknown-linux-gnueabihf
124          - arm-unknown-linux-musleabihf
125          - i686-linux-android
126          - i686-unknown-linux-musl
127          - loongarch64-unknown-linux-gnu
128          - loongarch64-unknown-linux-musl
129          - powerpc-unknown-linux-gnu
130          - powerpc64-unknown-linux-gnu
131          - powerpc64le-unknown-linux-gnu
132          - riscv64gc-unknown-linux-gnu
133          - s390x-unknown-linux-gnu
134          - wasm32-unknown-emscripten
135          - wasm32-wasip1
136          - wasm32-wasip2
137          - x86_64-linux-android
138          # FIXME: Exec format error (os error 8)
139          # - x86_64-unknown-linux-gnux32
140          - x86_64-unknown-linux-musl
141          # FIXME: It seems some items in `src/unix/mod.rs`
142          # aren't defined on redox actually.
143          # - x86_64-unknown-redox
144    timeout-minutes: 25
145    env:
146      TARGET: ${{ matrix.target }}
147    steps:
148      - uses: actions/checkout@v4
149      - name: Setup Rust toolchain
150        run: ./ci/install-rust.sh
151      - uses: Swatinem/rust-cache@v2
152        with:
153          key: ${{ matrix.target }}
154      - name: Execute run-docker.sh
155        run: ./ci/run-docker.sh ${{ matrix.target }}
156
157  test_tier2_vm:
158    name: Test tier2 VM
159    needs: [test_tier1, style_check]
160    runs-on: ubuntu-latest
161    strategy:
162      fail-fast: true
163      matrix:
164        target:
165          - x86_64-pc-solaris
166    timeout-minutes: 25
167    steps:
168      - uses: actions/checkout@v4
169      - name: test on Solaris
170        uses: vmactions/solaris-vm@v1
171        with:
172          release: "11.4-gcc"
173          usesh: true
174          mem: 4096
175          copyback: false
176          prepare: |
177            set -x
178            source <(curl -s https://raw.githubusercontent.com/psumbera/solaris-rust/refs/heads/main/sh.rust-web-install)
179            rustc --version
180            uname -a
181          run: |
182            export PATH=$HOME/.rust_solaris/bin:$PATH
183            ./ci/run.sh ${{ matrix.target }}
184
185  check_cfg:
186    name: "Check #[cfg]s"
187    runs-on: ubuntu-24.04
188    env:
189      TOOLCHAIN: nightly
190    timeout-minutes: 10
191    steps:
192      - uses: actions/checkout@v4
193      - name: Setup Rust toolchain
194        run: ./ci/install-rust.sh
195      - name: Build with check-cfg
196        run: LIBC_CHECK_CFG=1 cargo build -Z unstable-options -Z check-cfg
197
198  # One job that "summarizes" the success state of this pipeline. This can then be added to branch
199  # protection, rather than having to add each job separately.
200  success:
201    name: success
202    runs-on: ubuntu-24.04
203    needs:
204      - style_check
205      - test_tier1
206      - test_tier2
207      - test_tier2_vm
208      - verify_build
209    # Github branch protection is exceedingly silly and treats "jobs skipped because a dependency
210    # failed" as success. So we have to do some contortions to ensure the job fails if any of its
211    # dependencies fails.
212    if: always() # make sure this is never "skipped"
213    steps:
214      # Manually check the status of all dependencies. `if: failure()` does not work.
215      - name: check if any dependency failed
216        run: jq --exit-status 'all(.result == "success")' <<< '${{ toJson(needs) }}'
217