1name: CI 2 3on: 4 - push 5 - pull_request 6 7jobs: 8 rustfmt: 9 runs-on: ubuntu-latest 10 timeout-minutes: 10 11 12 steps: 13 - uses: actions/checkout@v3 14 15 - name: Install rustfmt 16 run: | 17 rustup component add rustfmt 18 19 - name: Rustfmt 20 run: | 21 cargo fmt --check 22 rustfmt --check build_system/main.rs 23 rustfmt --check example/* 24 25 26 test: 27 runs-on: ${{ matrix.os }} 28 timeout-minutes: 60 29 30 defaults: 31 run: 32 shell: bash 33 34 strategy: 35 fail-fast: false 36 matrix: 37 include: 38 - os: ubuntu-latest 39 env: 40 TARGET_TRIPLE: x86_64-unknown-linux-gnu 41 - os: macos-latest 42 env: 43 TARGET_TRIPLE: x86_64-apple-darwin 44 # cross-compile from Linux to Windows using mingw 45 - os: ubuntu-latest 46 env: 47 TARGET_TRIPLE: x86_64-pc-windows-gnu 48 - os: ubuntu-latest 49 env: 50 TARGET_TRIPLE: aarch64-unknown-linux-gnu 51 # s390x requires QEMU 6.1 or greater, we could build it from source, but ubuntu 22.04 comes with 6.2 by default 52 - os: ubuntu-latest 53 env: 54 TARGET_TRIPLE: s390x-unknown-linux-gnu 55 - os: windows-latest 56 env: 57 TARGET_TRIPLE: x86_64-pc-windows-msvc 58 - os: windows-latest 59 env: 60 TARGET_TRIPLE: x86_64-pc-windows-gnu 61 62 steps: 63 - uses: actions/checkout@v3 64 65 - name: Cache cargo target dir 66 uses: actions/cache@v3 67 with: 68 path: build/cg_clif 69 key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} 70 71 - name: Set MinGW as the default toolchain 72 if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' 73 run: rustup set default-host x86_64-pc-windows-gnu 74 75 - name: Install MinGW toolchain and wine 76 if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' 77 run: | 78 sudo apt-get update 79 sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable 80 81 - name: Install AArch64 toolchain and qemu 82 if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu' 83 run: | 84 sudo apt-get update 85 sudo apt-get install -y gcc-aarch64-linux-gnu qemu-user 86 87 - name: Install s390x toolchain and qemu 88 if: matrix.env.TARGET_TRIPLE == 's390x-unknown-linux-gnu' 89 run: | 90 sudo apt-get update 91 sudo apt-get install -y gcc-s390x-linux-gnu qemu-user 92 93 - name: Prepare dependencies 94 run: ./y.sh prepare 95 96 - name: Build 97 run: ./y.sh build --sysroot none 98 99 - name: Test 100 env: 101 TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }} 102 run: ./y.sh test 103 104 - name: Install LLVM standard library 105 run: rustup target add ${{ matrix.env.TARGET_TRIPLE }} 106 107 # This is roughly config rust-lang/rust uses for testing 108 - name: Test with LLVM sysroot 109 # Skip native x86_64-pc-windows-gnu. It is way too slow and cross-compiled 110 # x86_64-pc-windows-gnu covers at least part of the tests. 111 if: matrix.os != 'windows-latest' || matrix.env.TARGET_TRIPLE != 'x86_64-pc-windows-gnu' 112 env: 113 TARGET_TRIPLE: ${{ matrix.env.TARGET_TRIPLE }} 114 run: ./y.sh test --sysroot llvm --no-unstable-features 115 116 117 # This job doesn't use cg_clif in any way. It checks that all cg_clif tests work with cg_llvm too. 118 test_llvm: 119 runs-on: ubuntu-latest 120 timeout-minutes: 60 121 122 defaults: 123 run: 124 shell: bash 125 126 steps: 127 - uses: actions/checkout@v3 128 129 - name: Prepare dependencies 130 run: ./y.rs prepare 131 132 - name: Disable JIT tests 133 run: | 134 sed -i 's/jit./#jit./' config.txt 135 136 - name: Test 137 env: 138 TARGET_TRIPLE: x86_64-unknown-linux-gnu 139 run: ./y.rs test --use-backend llvm 140 141 bench: 142 runs-on: ubuntu-latest 143 timeout-minutes: 60 144 145 defaults: 146 run: 147 shell: bash 148 149 steps: 150 - uses: actions/checkout@v3 151 152 - name: Cache cargo target dir 153 uses: actions/cache@v3 154 with: 155 path: build/cg_clif 156 key: ${{ runner.os }}-x86_64-unknown-linux-gnu-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} 157 158 - name: Cache cargo bin dir 159 uses: actions/cache@v3 160 with: 161 path: ~/.cargo/bin 162 key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-cargo-bin-dir-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} 163 164 - name: Install hyperfine 165 run: cargo install hyperfine || true 166 167 - name: Prepare dependencies 168 run: ./y.sh prepare 169 170 - name: Build 171 run: CI_OPT=1 ./y.sh build --sysroot none 172 173 - name: Benchmark 174 run: CI_OPT=1 ./y.sh bench 175 176 177 dist: 178 runs-on: ${{ matrix.os }} 179 timeout-minutes: 60 180 181 defaults: 182 run: 183 shell: bash 184 185 strategy: 186 fail-fast: false 187 matrix: 188 include: 189 # FIXME update at some point in the future once most distros use a newer glibc 190 - os: ubuntu-20.04 191 env: 192 TARGET_TRIPLE: x86_64-unknown-linux-gnu 193 - os: macos-latest 194 env: 195 TARGET_TRIPLE: x86_64-apple-darwin 196 # cross-compile from Linux to Windows using mingw 197 - os: ubuntu-latest 198 env: 199 TARGET_TRIPLE: x86_64-pc-windows-gnu 200 - os: windows-latest 201 env: 202 TARGET_TRIPLE: x86_64-pc-windows-msvc 203 - os: windows-latest 204 env: 205 TARGET_TRIPLE: x86_64-pc-windows-gnu 206 207 steps: 208 - uses: actions/checkout@v3 209 210 - name: Cache cargo target dir 211 uses: actions/cache@v3 212 with: 213 path: build/cg_clif 214 key: ${{ runner.os }}-${{ matrix.env.TARGET_TRIPLE }}-dist-cargo-build-target-${{ hashFiles('rust-toolchain', '**/Cargo.lock') }} 215 216 - name: Set MinGW as the default toolchain 217 if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' 218 run: rustup set default-host x86_64-pc-windows-gnu 219 220 - name: Install MinGW toolchain and wine 221 if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' 222 run: | 223 sudo apt-get update 224 sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable 225 226 - name: Prepare dependencies 227 run: ./y.sh prepare 228 229 - name: Build backend 230 run: CI_OPT=1 ./y.sh build --sysroot none 231 232 - name: Build sysroot 233 run: CI_OPT=1 ./y.sh build 234 235 - name: Package prebuilt cg_clif 236 run: tar cvfJ cg_clif.tar.xz dist 237 238 - name: Upload prebuilt cg_clif 239 if: matrix.os == 'windows-latest' || matrix.env.TARGET_TRIPLE != 'x86_64-pc-windows-gnu' 240 uses: actions/upload-artifact@v3 241 with: 242 name: cg_clif-${{ matrix.env.TARGET_TRIPLE }} 243 path: cg_clif.tar.xz 244 245 - name: Upload prebuilt cg_clif (cross compile) 246 if: matrix.os != 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu' 247 uses: actions/upload-artifact@v3 248 with: 249 name: cg_clif-${{ runner.os }}-cross-x86_64-mingw 250 path: cg_clif.tar.xz 251 252 release: 253 runs-on: ubuntu-latest 254 timeout-minutes: 10 255 if: ${{ github.ref == 'refs/heads/master' }} 256 needs: [rustfmt, test, bench, dist] 257 258 concurrency: 259 group: release-dev 260 cancel-in-progress: true 261 262 steps: 263 - uses: actions/checkout@v3 264 265 - name: Download all built artifacts 266 uses: actions/download-artifact@v3 267 with: 268 path: artifacts/ 269 270 - run: | 271 ls -R artifacts/ 272 mkdir release/ 273 pushd artifacts/ 274 for dir in *; do 275 mv $dir/cg_clif.tar.xz ../release/$dir.tar.xz 276 rmdir $dir/ # verify $dir is empty 277 done 278 popd 279 rmdir artifacts/ # verify all artifacts are represented in release/ 280 ls -R release/ 281 282 - run: npm install --production 283 working-directory: .github/actions/github-release 284 285 - name: Publish Release 286 uses: ./.github/actions/github-release 287 with: 288 files: "release/*" 289 token: ${{ github.token }} 290 continue-on-error: true 291