Skip to content

Commit dc74ff1

Browse files
authored
Add a test on CI that just the sysroot can be built (#465)
This commit adds a test and matrix entry to CI which asserts that the sysroot can be built to run tests using a stock Clang compiler found on the system. This fixes a few minor issues as well in developing this. This additionally refactors CI a bit to move shared steps amongst jobs into separate composite actions in this repository to avoid duplication across jobs.
1 parent b267916 commit dc74ff1

File tree

5 files changed

+72
-36
lines changed

5 files changed

+72
-36
lines changed

.github/actions/checkout/action.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: 'Prepare wasi-sdk git directory'
2+
description: 'Prepare wasi-sdk git directory'
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- run: git fetch --tags --force
8+
name: Force-fetch tags to work around actions/checkout#290
9+
shell: bash
10+
# We can't use `--depth 1` here sadly because the GNU config
11+
# submodule is not pinned to a particular tag/branch. Please
12+
# bump depth (or even better, the submodule), in case of "error:
13+
# Server does not allow request for unadvertised object" in the
14+
# future.
15+
- run: git submodule update --init --depth 64 --jobs 3
16+
shell: bash
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: 'Install wasi-sdk dependencies'
2+
description: 'Install wasi-sdk dependencies'
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Setup `wasmtime` for tests
8+
uses: bytecodealliance/actions/wasmtime/setup@v1
9+
with:
10+
version: "18.0.2"
11+
- name: Install ccache, ninja (macOS)
12+
run: brew install ccache ninja
13+
if: runner.os == 'macOS'
14+
shell: bash
15+
- name: Install ccache, ninja (Windows)
16+
run: choco install ccache ninja
17+
if: runner.os == 'Windows'
18+
shell: bash
19+
- name: Install ccache, ninja (Linux)
20+
run: sudo apt-get install -y ccache ninja-build
21+
if: runner.os == 'Linux'
22+
shell: bash

.github/workflows/main.yml

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,8 @@ jobs:
6565
- uses: actions/checkout@v4
6666
with:
6767
fetch-depth: 0
68-
- run: git fetch --tags --force
69-
name: Force-fetch tags to work around actions/checkout#290
70-
# We can't use `--depth 1` here sadly because the GNU config
71-
# submodule is not pinned to a particular tag/branch. Please
72-
# bump depth (or even better, the submodule), in case of "error:
73-
# Server does not allow request for unadvertised object" in the
74-
# future.
75-
- run: git submodule update --init --depth 64 --jobs 3
68+
- uses: ./.github/actions/checkout
69+
- uses: ./.github/actions/install-deps
7670

7771
# Persist ccache-based caches across builds. This directory is configured
7872
# via the CCACHE_DIR env var below for ccache to use.
@@ -103,21 +97,6 @@ jobs:
10397
echo WASI_SDK_CI_TOOLCHAIN_CMAKE_ARGS="$cmake_args" >> $GITHUB_ENV
10498
shell: bash
10599
106-
# Add some extra installed software on each runner as necessary.
107-
- name: Setup `wasmtime` for tests
108-
uses: bytecodealliance/actions/wasmtime/setup@v1
109-
with:
110-
version: "18.0.2"
111-
- name: Install ccache, ninja (macOS)
112-
run: brew install ccache ninja
113-
if: runner.os == 'macOS'
114-
- name: Install ccache, ninja (Windows)
115-
run: choco install ccache ninja
116-
if: runner.os == 'Windows'
117-
- name: Install ccache, ninja (Linux)
118-
run: sudo apt install ccache
119-
if: runner.os == 'Linux'
120-
121100
- name: Clear ccache statistics
122101
run: ccache --zero-stats
123102

@@ -184,6 +163,30 @@ jobs:
184163
path: ${{ runner.tool_cache }}/ccache
185164
key: 0-cache-${{ matrix.artifact }}-${{ github.run_id }}
186165

166+
build-only-sysroot:
167+
name: Build only sysroot
168+
runs-on: ubuntu-latest
169+
steps:
170+
- uses: actions/checkout@v4
171+
with:
172+
fetch-depth: 0
173+
- uses: ./.github/actions/checkout
174+
- uses: ./.github/actions/install-deps
175+
- run: |
176+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
177+
name=$(lsb_release -s -c)
178+
sudo add-apt-repository -y "deb http://apt.llvm.org/$name/ llvm-toolchain-$name-18 main"
179+
sudo add-apt-repository -y "deb-src http://apt.llvm.org/$name/ llvm-toolchain-$name-18 main"
180+
sudo apt-get install -y clang-18 llvm-18 lld-18
181+
- run: cargo install [email protected]
182+
- run: |
183+
cmake -G Ninja -B build -S . \
184+
-DCMAKE_C_COMPILER=/usr/lib/llvm-18/bin/clang \
185+
-DCMAKE_SYSTEM_NAME=WASI \
186+
-DWASI_SDK_INCLUDE_TESTS=ON
187+
- run: ninja -C build
188+
- run: ctest --output-on-failure --parallel 10 --test-dir build/tests
189+
187190
# Once all of the above matrix entries have completed this job will run and
188191
# assemble the final `wasi-sdk-*` artifacts by fusing the toolchain/sysroot
189192
# artifacts.
@@ -195,8 +198,7 @@ jobs:
195198
- uses: actions/checkout@v4
196199
with:
197200
fetch-depth: 0
198-
- run: git fetch --tags --force
199-
name: Force-fetch tags to work around actions/checkout#290
201+
- uses: ./.github/actions/checkout
200202

201203
# Download all artifacts from all platforms in `build`, merge them into
202204
# final wasi-sdk-* artifacts, and then upload them.
@@ -256,16 +258,8 @@ jobs:
256258
- uses: actions/checkout@v4
257259
with:
258260
fetch-depth: 0
259-
- run: git fetch --tags --force
260-
name: Force-fetch tags to work around actions/checkout#290
261-
- run: git submodule update --init --depth 64 --jobs 3
262-
- name: Setup `wasmtime` for tests
263-
uses: bytecodealliance/actions/wasmtime/setup@v1
264-
with:
265-
version: "18.0.2"
266-
- name: Install ninja
267-
run: sudo apt-get install -y ninja-build
268-
if: runner.os == 'Linux'
261+
- uses: ./.github/actions/checkout
262+
- uses: ./.github/actions/install-deps
269263
- uses: actions/download-artifact@v4
270264
with:
271265
name: dist-x86_64-linux

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# the host.
88

99
cmake_minimum_required(VERSION 3.26)
10+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1011
project(wasi-sdk)
1112
include(ExternalProject)
1213

@@ -17,7 +18,6 @@ option(WASI_SDK_BUILD_TOOLCHAIN "Build a toolchain instead of the sysroot" OFF)
1718
set(llvm_proj_dir ${CMAKE_CURRENT_SOURCE_DIR}/src/llvm-project)
1819
set(wasi_libc ${CMAKE_CURRENT_SOURCE_DIR}/src/wasi-libc)
1920

20-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
2121
include(wasi-sdk-enable-ccache)
2222

2323
find_program(PYTHON python3 python REQUIRED)

cmake/wasi-sdk-sysroot.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ if(CMAKE_C_COMPILER_VERSION VERSION_LESS ${minimum_clang_required})
1515
message(FATAL_ERROR "compiler version ${CMAKE_C_COMPILER_VERSION} is less than the required version ${minimum_clang_required}")
1616
endif()
1717

18+
message(STATUS "Found executable for `nm`: ${CMAKE_NM}")
19+
message(STATUS "Found executable for `ar`: ${CMAKE_AR}")
20+
1821
find_program(MAKE make REQUIRED)
1922

2023
option(WASI_SDK_DEBUG_PREFIX_MAP "Pass `-fdebug-prefix-map` for built artifacts" ON)
@@ -133,6 +136,7 @@ function(define_wasi_libc_sub target target_suffix lto)
133136

134137
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
135138
get_property(directory_cflags DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY COMPILE_OPTIONS)
139+
list(APPEND directory_cflags -resource-dir ${wasi_resource_dir})
136140
set(extra_cflags_list
137141
"${CMAKE_C_FLAGS} ${directory_cflags} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}")
138142
list(JOIN extra_cflags_list " " extra_cflags)

0 commit comments

Comments
 (0)