Skip to content

Commit 48eb92c

Browse files
authored
Refactor how CI works in this repository (#588)
There are a number of changes in this commit aimed at addressing #587 and making it easier to test #586 in CI. Notable changes here are: * The matrix of what to test is much different from before. One matrix entry now builds just one target and optionally tests that target. * The CI matrix ensures that wasi-libc builds on a variety of platforms, e.g. Windows/macOS/Linux as well as Linux aarch64. * The CI matrix has one entry for building with an older version of LLVM. This version was bumped from LLVM to LLVM 11 since LLVM is installed through `apt-get`, not through downloads any more. * On Linux LLVM/Clang are downloaded through `apt-get` instead of from llvm-project binaries to avoid dealing with `libtinfo5` and dependencies. * The CI matrix has a test job per-target. This can be expanded/shrunk as necessary but currently everything is tested with LLVM 16 (as before) and only on Linux (also as before). The test run is seqeunced to happen after the build of libc itself. * The CI matrix has split out V8 headless tests into their own job to avoid running multiple suites of tests in a single job. * Installation of LLVM is refactored to a separate action to reduce the noise in `main.yml`. * Setting `TARGET_TRIPLE` can now be done through environment variables as opposed to only through arguments to `make`. * Handling of `BULITINS_LIB` has improved. Previously the build target for `libc_so` would modify the compiler's resource directory and this is updated to use a custom directory in `OBJDIR`. * Arranging compiler-rt for tests is now done with `-resource-dir` instead of copying the directory into the system compiler's location. Overall it's the intention that no amount of testing is lost in this PR. The goal is to expand things out in such a way that it's much easier to add one-off tests of wasi-libc in various build configurations and such. The theory is that this is as "simple" as adding a new matrix entry, copied from previous ones, customized with various variables and environment variables to affect the build (e.g. `CFLAGS`). Closes #587
1 parent 4720b34 commit 48eb92c

File tree

3 files changed

+195
-132
lines changed

3 files changed

+195
-132
lines changed

.github/actions/setup/action.yml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: 'Install LLVM'
2+
description: 'Install LLVM'
3+
inputs:
4+
clang_version:
5+
description: 'version string of Clang to download'
6+
required: true
7+
llvm_asset_suffix:
8+
description: 'extra info about how to download from LLVM binaries'
9+
required: false
10+
default: ''
11+
12+
runs:
13+
using: composite
14+
steps:
15+
- name: Install LLVM tools (Windows)
16+
shell: bash
17+
run: |
18+
curl -fsSLO https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ inputs.clang_version }}/LLVM-${{ inputs.clang_version }}-win64.exe
19+
7z x LLVM-${{ inputs.clang_version }}-win64.exe -y -o"llvm"
20+
echo "$(pwd)/llvm/bin" >> $GITHUB_PATH
21+
echo "CC=$(pwd)/llvm/bin/clang.exe" >> $GITHUB_ENV
22+
echo "AR=$(pwd)/llvm/bin/llvm-ar.exe" >> $GITHUB_ENV
23+
echo "NM=$(pwd)/llvm/bin/llvm-nm.exe" >> $GITHUB_ENV
24+
if: runner.os == 'Windows'
25+
26+
- name: Override llvm-nm with one from rustup (Windows)
27+
shell: bash
28+
run: |
29+
rustup update stable
30+
rustup default stable
31+
rustup component add llvm-tools-preview
32+
echo "NM=$(rustc --print sysroot|sed 's|C:|/c|'|sed 's|\\|/|g')/lib/rustlib/x86_64-pc-windows-msvc/bin/llvm-nm.exe" >> $GITHUB_ENV
33+
if: runner.os == 'Windows'
34+
35+
- name: Install LLVM tools (MacOS)
36+
shell: bash
37+
run: |
38+
curl -sSfL https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ inputs.clang_version }}/clang+llvm-${{ inputs.clang_version }}-${{ inputs.llvm_asset_suffix }}.tar.xz | tar xJf -
39+
export CLANG_DIR=`pwd`/clang+llvm-${{ inputs.clang_version }}-${{ inputs.llvm_asset_suffix }}/bin
40+
echo "$CLANG_DIR" >> $GITHUB_PATH
41+
echo "CC=$CLANG_DIR/clang" >> $GITHUB_ENV
42+
echo "AR=$CLANG_DIR/llvm-ar" >> $GITHUB_ENV
43+
echo "NM=$CLANG_DIR/llvm-nm" >> $GITHUB_ENV
44+
if: runner.os == 'macOS'
45+
46+
# Note that this uses apt-based packages for installing Clang/tools to
47+
# ensure that all various dependencies are also installed. Binaries from
48+
# llvm-project depend on libtinfo.so and TBH I don't know what that is.
49+
# Using apt-get should basically serve the same purpose though.
50+
- name: Install LLVM tools (Linux)
51+
shell: bash
52+
run: |
53+
set -ex
54+
v=${{ inputs.clang_version }}
55+
sudo apt-get update
56+
sudo apt-get install -y clang-$v clang-tools-$v
57+
echo "CC=clang-$v" >> $GITHUB_ENV
58+
echo "AR=llvm-ar-$v" >> $GITHUB_ENV
59+
echo "NM=llvm-nm-$v" >> $GITHUB_ENV
60+
if: runner.os == 'Linux'

.github/workflows/main.yml

Lines changed: 122 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -2,165 +2,163 @@ name: CI
22
on: [push, pull_request]
33

44
concurrency:
5-
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
5+
group: ${{ github.workflow }}-${{ github.ref }}
66
cancel-in-progress: true
77

8+
defaults:
9+
run:
10+
shell: bash
11+
812
jobs:
913
buildlibc:
10-
name: Build libc
14+
name: ${{ matrix.name }}
1115
runs-on: ${{ matrix.os }}
16+
env: ${{ matrix.env || fromJSON('{}') }}
1217
strategy:
18+
fail-fast: false
1319
matrix:
14-
os: [ubuntu-22.04, macos-15, windows-2025]
15-
clang_version: [10.0.0]
16-
# use different LLVM versions among oses because of the lack of
17-
# official assets on github.
1820
include:
19-
- os: ubuntu-22.04
20-
clang_version: 10.0.0
21-
llvm_asset_suffix: x86_64-linux-gnu-ubuntu-18.04
22-
- os: macos-15
23-
clang_version: 10.0.0
24-
llvm_asset_suffix: x86_64-apple-darwin
25-
- os: windows-2025
26-
clang_version: 10.0.0
27-
- os: ubuntu-22.04
28-
clang_version: 16.0.0
29-
llvm_asset_suffix: x86_64-linux-gnu-ubuntu-18.04
30-
enable_pic: true
31-
- os: macos-15
21+
# Test a number of operating systems and architectures to make sure
22+
# wasi-libc builds on these platforms by default.
23+
- name: Build on Linux x86_64
24+
os: ubuntu-24.04
25+
clang_version: 16
26+
upload: linux-x86_64-clang-16
27+
- name: Build on Linux aarch64
28+
os: ubuntu-24.04-arm
29+
clang_version: 16
30+
upload: linux-aarch64-clang-16
31+
- name: Build on macOS aarch64
32+
os: macos-15
3233
clang_version: 15.0.7
33-
llvm_asset_suffix: x86_64-apple-darwin21.0
34-
- os: windows-2025
35-
clang_version: 16.0.0
36-
enable_pic: true
37-
- os: ubuntu-24.04-arm
34+
llvm_asset_suffix: arm64-apple-darwin22.0
35+
upload: macos-clang-15
36+
- name: Build on Windows x86_64
37+
os: windows-2025
3838
clang_version: 16.0.0
39-
llvm_asset_suffix: aarch64-linux-gnu
40-
enable_pic: true
41-
39+
upload: windows-clang-16
40+
41+
# Historical versions of LLVM (11.0.0 currently)
42+
- name: Build with LLVM 11
43+
os: ubuntu-22.04
44+
clang_version: 11
45+
upload: linux-x86_64-clang-11
46+
env:
47+
BUILD_LIBSETJMP: no
48+
49+
# Test various combinations of targets triples.
50+
#
51+
# Configuration here can happen through `env` which is inherited to
52+
# jobs below. For now this only runs tests on Linux with Clang 16,
53+
# but that can be expanded as necessary in the future too. Note that
54+
# some targets run the build for the `libc_so` makefile target to
55+
# ensure the PIC build works.
56+
- name: Test wasm32-wasi
57+
os: ubuntu-24.04
58+
clang_version: 16
59+
test: true
60+
upload: wasm32-wasi
61+
env:
62+
TARGET_TRIPLE: wasm32-wasi
63+
MAKE_TARGETS: "default libc_so"
64+
- name: Test wasm32-wasip1
65+
os: ubuntu-24.04
66+
clang_version: 16
67+
test: true
68+
upload: wasm32-wasip1
69+
env:
70+
TARGET_TRIPLE: wasm32-wasip1
71+
MAKE_TARGETS: "default libc_so"
72+
- name: Test wasm32-wasip2
73+
os: ubuntu-24.04
74+
clang_version: 16
75+
test: true
76+
upload: wasm32-wasip2
77+
env:
78+
TARGET_TRIPLE: wasm32-wasip2
79+
WASI_SNAPSHOT: p2
80+
MAKE_TARGETS: "default libc_so"
81+
- name: Test wasm32-wasi-threads
82+
os: ubuntu-24.04
83+
clang_version: 16
84+
test: true
85+
upload: wasm32-wasi-threads
86+
env:
87+
TARGET_TRIPLE: wasm32-wasi-threads
88+
THREAD_MODEL: posix
89+
- name: Test wasm32-wasip1-threads
90+
os: ubuntu-24.04
91+
clang_version: 16
92+
test: true
93+
upload: wasm32-wasip1-threads
94+
env:
95+
TARGET_TRIPLE: wasm32-wasip1-threads
96+
THREAD_MODEL: posix
97+
- name: Test wasm32-wasip1 in V8
98+
os: ubuntu-24.04
99+
clang_version: 16
100+
test: true
101+
test_with_v8: true
102+
env:
103+
TARGET_TRIPLE: wasm32-wasip1
104+
- name: Test wasm32-wasip1-threads in V8
105+
os: ubuntu-24.04
106+
clang_version: 16
107+
test: true
108+
test_with_v8: true
109+
env:
110+
TARGET_TRIPLE: wasm32-wasip1-threads
111+
THREAD_MODEL: posix
112+
42113
steps:
43114
- uses: actions/checkout@v4.1.7
44115
with:
45116
submodules: true
46117

47-
- name: Install libtinfo5
48-
run: |
49-
set -ex
50-
sudo apt-get update
51-
sudo apt-get install -y libtinfo5
52-
if: startsWith(matrix.os, 'ubuntu-22')
53-
54-
- name: Install LLVM tools (Windows)
55-
shell: bash
56-
run: |
57-
curl -fsSLO https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.clang_version }}/LLVM-${{ matrix.clang_version }}-win64.exe
58-
7z x LLVM-${{ matrix.clang_version }}-win64.exe -y -o"llvm"
59-
echo "$(pwd)/llvm/bin" >> $GITHUB_PATH
60-
echo "CC=$(pwd)/llvm/bin/clang.exe" >> $GITHUB_ENV
61-
echo "AR=$(pwd)/llvm/bin/llvm-ar.exe" >> $GITHUB_ENV
62-
echo "NM=$(pwd)/llvm/bin/llvm-nm.exe" >> $GITHUB_ENV
63-
if: matrix.os == 'windows-2025'
64-
65-
- name: Override llvm-nm with one from rustup (Windows)
66-
run: |
67-
rustup update stable
68-
rustup default stable
69-
rustup component add llvm-tools-preview
70-
echo "NM=$(rustc --print sysroot|sed 's|C:|/c|'|sed 's|\\|/|g')/lib/rustlib/x86_64-pc-windows-msvc/bin/llvm-nm.exe" >> $GITHUB_ENV
71-
if: matrix.os == 'windows-2025'
72-
73-
- name: Install LLVM tools (MacOS)
74-
shell: bash
75-
run: |
76-
curl -sSfL https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.clang_version }}/clang+llvm-${{ matrix.clang_version }}-${{ matrix.llvm_asset_suffix }}.tar.xz | tar xJf -
77-
export CLANG_DIR=`pwd`/clang+llvm-${{ matrix.clang_version }}-${{ matrix.llvm_asset_suffix }}/bin
78-
echo "$CLANG_DIR" >> $GITHUB_PATH
79-
echo "CC=$CLANG_DIR/clang" >> $GITHUB_ENV
80-
echo "AR=$CLANG_DIR/llvm-ar" >> $GITHUB_ENV
81-
echo "NM=$CLANG_DIR/llvm-nm" >> $GITHUB_ENV
82-
if: matrix.os == 'macos-15'
83-
84-
- name: Install LLVM tools (Linux)
85-
shell: bash
86-
run: |
87-
curl -sSfL https://github.com/llvm/llvm-project/releases/download/llvmorg-${{ matrix.clang_version }}/clang+llvm-${{ matrix.clang_version }}-${{ matrix.llvm_asset_suffix }}.tar.xz | tar xJf -
88-
export CLANG_DIR=`pwd`/clang+llvm-${{ matrix.clang_version }}-${{ matrix.llvm_asset_suffix }}/bin
89-
echo "$CLANG_DIR" >> $GITHUB_PATH
90-
echo "CLANG_DIR=$CLANG_DIR" >> $GITHUB_ENV
91-
echo "CC=$CLANG_DIR/clang" >> $GITHUB_ENV
92-
echo "AR=$CLANG_DIR/llvm-ar" >> $GITHUB_ENV
93-
echo "NM=$CLANG_DIR/llvm-nm" >> $GITHUB_ENV
94-
if: startsWith(matrix.os, 'ubuntu-')
95-
96-
- name: Disable libsetjmp for old LLVM
97-
shell: bash
98-
run: |
99-
echo "BUILD_LIBSETJMP=no" >> $GITHUB_ENV
100-
if: matrix.clang_version == '10.0.0'
101-
102-
- name: Enable PIC build for new LLVM
103-
shell: bash
104-
run: |
105-
echo "MAKE_TARGETS=default libc_so" >> $GITHUB_ENV
106-
if: matrix.enable_pic
118+
- uses: ./.github/actions/setup
119+
with:
120+
clang_version: ${{ matrix.clang_version }}
121+
llvm_asset_suffix: ${{ matrix.llvm_asset_suffix }}
107122

108123
- name: Build libc
109-
shell: bash
110-
run: |
111-
make -j4 TARGET_TRIPLE=wasm32-wasi $MAKE_TARGETS
112-
make -j4 TARGET_TRIPLE=wasm32-wasip1 $MAKE_TARGETS
113-
make -j4 TARGET_TRIPLE=wasm32-wasip2 WASI_SNAPSHOT=p2 $MAKE_TARGETS
124+
run: make -j4 $MAKE_TARGETS
125+
126+
- name: Download Test dependencies
127+
if: matrix.test
128+
run: cd test && make download
114129

115-
- name: Build libc + threads
116-
# Only build the thread-capable wasi-libc in the latest supported Clang
117-
# version; the earliest version does not have all necessary builtins
118-
# (e.g., `__builtin_wasm_memory_atomic_notify`).
119-
if: matrix.clang_version != '10.0.0'
120-
shell: bash
130+
- name: Install V8 dependencies
131+
if: matrix.test_with_v8
121132
run: |
122-
make -j4 THREAD_MODEL=posix TARGET_TRIPLE=wasm32-wasi-threads
123-
make -j4 THREAD_MODEL=posix TARGET_TRIPLE=wasm32-wasip1-threads
133+
npm -C test/scripts/browser-test install
134+
npx -C test/scripts/browser-test playwright install chromium-headless-shell
135+
echo ENGINE="$PWD/test/scripts/browser-test/harness.mjs" >> $GITHUB_ENV
124136
125137
- name: Test
126-
shell: bash
138+
if: matrix.test
127139
# For Clang linking to work correctly, we need to place Clang's runtime
128140
# library for `wasm32-wasi` in the right location (i.e., the `mkdir` and
129141
# `cp` below).
130142
run: |
131143
cd test
132-
make download
133-
export WASI_DIR=$(realpath $($CLANG_DIR/clang -print-resource-dir)/lib/wasi/)
134-
export WASIP1_DIR=$(realpath $($CLANG_DIR/clang -print-resource-dir)/lib/wasip1/)
135-
export WASIP2_DIR=$(realpath $($CLANG_DIR/clang -print-resource-dir)/lib/wasip2/)
144+
mkdir resource-dir
145+
export WASI_DIR=./resource-dir/lib/wasi/
146+
export WASIP1_DIR=./resource-dir/lib/wasip1/
147+
export WASIP2_DIR=./resource-dir/lib/wasip2/
136148
mkdir -p $WASI_DIR $WASIP1_DIR $WASIP2_DIR
137149
cp build/download/libclang_rt.builtins-wasm32.a $WASI_DIR
138150
cp build/download/libclang_rt.builtins-wasm32.a $WASIP1_DIR
139151
cp build/download/libclang_rt.builtins-wasm32.a $WASIP2_DIR
140-
TARGET_TRIPLE=wasm32-wasi make test
141-
TARGET_TRIPLE=wasm32-wasip1 make test
142-
TARGET_TRIPLE=wasm32-wasip2 make test
143-
TARGET_TRIPLE=wasm32-wasi-threads make test
144-
TARGET_TRIPLE=wasm32-wasip1-threads make test
145-
146-
npm -C scripts/browser-test install
147-
npx -C scripts/browser-test playwright install chromium-headless-shell
148-
ENGINE="$PWD/scripts/browser-test/harness.mjs" TARGET_TRIPLE=wasm32-wasip1 make test
149-
ENGINE="$PWD/scripts/browser-test/harness.mjs" TARGET_TRIPLE=wasm32-wasip1-threads make test
150-
# The older version of Clang does not provide the expected symbol for the
151-
# test entrypoints: `undefined symbol: __main_argc_argv`.
152-
# The older (<15.0.7) version of wasm-ld does not provide `__heap_end`,
153-
# which is required by our malloc implementation.
154-
if: startsWith(matrix.os, 'ubuntu-') && matrix.clang_version != '10.0.0'
152+
export LDFLAGS="-resource-dir $(pwd)/resource-dir"
153+
make test
155154
156155
- uses: actions/upload-artifact@v4.4.0
156+
if: matrix.upload
157157
with:
158-
# Upload the sysroot folder. To avoid action erros, we give it a unique
159-
# name using the OS it was built for and the Clang version it was built
160-
# with.
161-
name: ${{ format( 'sysroot-{0}-clang-{1}.tgz', matrix.os, matrix.clang_version) }}
158+
name: ${{ format( 'sysroot-{0}.tgz', matrix.upload) }}
162159
path: sysroot
163160

161+
164162
# Disable the headerstest job for now, while WASI transitions from the
165163
# witx snapshots to wit proposals, and we have a few manual edits to the
166164
# generated header to make life easier for folks.
@@ -176,7 +174,6 @@ jobs:
176174
with:
177175
submodules: true
178176
- name: Install Rust (rustup)
179-
shell: bash
180177
run: rustup update stable --no-self-update && rustup default stable
181178
if: matrix.os != 'macos-15'
182179
- name: Install Rust (macos)

0 commit comments

Comments
 (0)