Skip to content

Commit 61fcaa6

Browse files
committed
Refactor how CI works in this repository
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 61fcaa6

File tree

3 files changed

+189
-135
lines changed

3 files changed

+189
-135
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: 116 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -2,164 +2,153 @@ 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+
- name: Build on Linux aarch64
27+
os: ubuntu-24.04-arm
28+
clang_version: 16
29+
- name: Build on macOS aarch64
30+
os: macos-15
3231
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
32+
llvm_asset_suffix: arm64-apple-darwin22.0
33+
- name: Build on Windows x86_64
34+
os: windows-2025
3835
clang_version: 16.0.0
39-
llvm_asset_suffix: aarch64-linux-gnu
40-
enable_pic: true
41-
36+
37+
# Historical versions of LLVM (11.0.0 currently)
38+
- name: Build with LLVM 11
39+
os: ubuntu-22.04
40+
clang_version: 11
41+
env:
42+
BUILD_LIBSETJMP: no
43+
44+
# Test various combinations of targets triples.
45+
#
46+
# Configuration here can happen through `env` which is inherited to
47+
# jobs below. For now this only runs tests on Linux with Clang 16,
48+
# but that can be expanded as necessary in the future too. Note that
49+
# some targets run the build for the `libc_so` makefile target to
50+
# ensure the PIC build works.
51+
- name: Test wasm32-wasi
52+
os: ubuntu-24.04
53+
clang_version: 16
54+
test: true
55+
env:
56+
TARGET_TRIPLE: wasm32-wasi
57+
MAKE_TARGETS: "default libc_so"
58+
- name: Test wasm32-wasip1
59+
os: ubuntu-24.04
60+
clang_version: 16
61+
test: true
62+
env:
63+
TARGET_TRIPLE: wasm32-wasip1
64+
MAKE_TARGETS: "default libc_so"
65+
- name: Test wasm32-wasip2
66+
os: ubuntu-24.04
67+
clang_version: 16
68+
test: true
69+
env:
70+
TARGET_TRIPLE: wasm32-wasip2
71+
WASI_SNAPSHOT: p2
72+
MAKE_TARGETS: "default libc_so"
73+
- name: Test wasm32-wasi-threads
74+
os: ubuntu-24.04
75+
clang_version: 16
76+
test: true
77+
env:
78+
TARGET_TRIPLE: wasm32-wasi-threads
79+
THREAD_MODEL: posix
80+
- name: Test wasm32-wasip1-threads
81+
os: ubuntu-24.04
82+
clang_version: 16
83+
test: true
84+
env:
85+
TARGET_TRIPLE: wasm32-wasip1-threads
86+
THREAD_MODEL: posix
87+
- name: Test wasm32-wasip1 in V8
88+
os: ubuntu-24.04
89+
clang_version: 16
90+
test: true
91+
test_with_v8: true
92+
env:
93+
TARGET_TRIPLE: wasm32-wasip1
94+
- name: Test wasm32-wasip1-threads in V8
95+
os: ubuntu-24.04
96+
clang_version: 16
97+
test: true
98+
test_with_v8: true
99+
env:
100+
TARGET_TRIPLE: wasm32-wasip1-threads
101+
THREAD_MODEL: posix
102+
42103
steps:
43104
- uses: actions/checkout@v4.1.7
44105
with:
45106
submodules: true
46107

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
108+
- uses: ./.github/actions/setup
109+
with:
110+
clang_version: ${{ matrix.clang_version }}
111+
llvm_asset_suffix: ${{ matrix.llvm_asset_suffix }}
107112

108113
- 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
114+
run: make -j4 $MAKE_TARGETS
114115

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
116+
- name: Download Test dependencies
117+
if: matrix.test
118+
run: cd test && make download
119+
120+
- name: Install V8 dependencies
121+
if: matrix.test_with_v8
121122
run: |
122-
make -j4 THREAD_MODEL=posix TARGET_TRIPLE=wasm32-wasi-threads
123-
make -j4 THREAD_MODEL=posix TARGET_TRIPLE=wasm32-wasip1-threads
123+
npm -C test/scripts/browser-test install
124+
npx -C test/scripts/browser-test playwright install chromium-headless-shell
125+
echo ENGINE="$PWD/test/scripts/browser-test/harness.mjs" >> $GITHUB_ENV
124126
125127
- name: Test
126-
shell: bash
128+
if: matrix.test
127129
# For Clang linking to work correctly, we need to place Clang's runtime
128130
# library for `wasm32-wasi` in the right location (i.e., the `mkdir` and
129131
# `cp` below).
130132
run: |
131133
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/)
134+
mkdir resource-dir
135+
export WASI_DIR=./resource-dir/lib/wasi/
136+
export WASIP1_DIR=./resource-dir/lib/wasip1/
137+
export WASIP2_DIR=./resource-dir/lib/wasip2/
136138
mkdir -p $WASI_DIR $WASIP1_DIR $WASIP2_DIR
137139
cp build/download/libclang_rt.builtins-wasm32.a $WASI_DIR
138140
cp build/download/libclang_rt.builtins-wasm32.a $WASIP1_DIR
139141
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'
142+
export LDFLAGS="-resource-dir $(pwd)/resource-dir"
143+
make test
155144
156-
- uses: actions/upload-artifact@v4.4.0
157-
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) }}
162-
path: sysroot
145+
# - uses: actions/upload-artifact@v4.4.0
146+
# with:
147+
# # Upload the sysroot folder. To avoid action erros, we give it a unique
148+
# # name using the OS it was built for and the Clang version it was built
149+
# # with.
150+
# name: ${{ format( 'sysroot-{0}-clang-{1}.tgz', matrix.os, matrix.clang_version) }}
151+
# path: sysroot
163152

164153
# Disable the headerstest job for now, while WASI transitions from the
165154
# witx snapshots to wit proposals, and we have a few manual edits to the
@@ -176,7 +165,6 @@ jobs:
176165
with:
177166
submodules: true
178167
- name: Install Rust (rustup)
179-
shell: bash
180168
run: rustup update stable --no-self-update && rustup default stable
181169
if: matrix.os != 'macos-15'
182170
- name: Install Rust (macos)

0 commit comments

Comments
 (0)