Skip to content

Commit 60ec682

Browse files
committed
Migrate the Makefile to CMake
This commit migrates wasi-libc's build system from a `make`-based system to CMake. This is a complete rewrite of the build system which culminates in the deletion of the current `Makefile` and a few supporting scripts and files. The rationale/reasons for this are similar to WebAssembly/wasi-sdk#429, namely: * Building a correct and robust build system in `make` is not easy. There are many times I've found myself in a situation where I need to blow away the entire build directory between builds. Much of the this this bottoms out in subtle behavior like "this file was renamed, but didn't get deleted in the archive" or subtle things like that. CMake is responsible for handling these by default and, in general, is probably going to be more correct than what we write. * Out-of-tree builds are now supported. * Customizing CFLAGS is now supported via standard mechanisms. Previously `EXTRA_CFLAGS` was required since using `CFLAGS` could break the build. * It's easier to move more logic into CMake, such as downloading compiler-rt, than it is to codify it all in makefiles. * Platform portability is generally easier in CMake than make. Building on Windows shouldn't require a full GNU-like environment, for example. * Tests now properly rebuild themselves when wasi-libc changes. * It's easier to customize high-level options, like "enable SIMD", in CMake than it is in Makefiles. This can be documented as a single option to pass where that option affects the build, flags, etc. Personally I'm not a fan of CMake, but I'm more of a fan of it than Makefiles, hence my desire to switch. I want to make this repository easier to build, configure, and change over time. This will also make it easier to integrate this all into wasi-sdk where everything is CMake-based over there as well. I am not a CMake expert, nor am I necessarily an expert in the previous Makefiles. I've done my best here, but I'm happy to change things if someone who knows more about CMake than I (which is a lot of folks) recommends doing so. I'm also happy to adjust the libc build as desired too. Closes WebAssembly#46 Closes WebAssembly#156 Closes WebAssembly#295 Closes WebAssembly#322 Closes WebAssembly#330 Closes WebAssembly#514 Closes WebAssembly#605
1 parent 75836f0 commit 60ec682

File tree

29 files changed

+1753
-1384
lines changed

29 files changed

+1753
-1384
lines changed

.github/actions/setup/action.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,4 @@ runs:
5757
echo "CC=clang-$v" >> $GITHUB_ENV
5858
echo "AR=llvm-ar-$v" >> $GITHUB_ENV
5959
echo "NM=llvm-nm-$v" >> $GITHUB_ENV
60-
# Note: wasm-component-ld is only needed for Linux because
61-
# currently, wasm32-wasip2 is only tested on Linux. If that changes,
62-
# this step will have to be added to the other targets.
63-
curl -fsSLO https://github.com/bytecodealliance/wasm-component-ld/releases/download/v0.5.15/wasm-component-ld-v0.5.15-x86_64-linux.tar.gz
64-
tar xzf wasm-component-ld-v0.5.15-x86_64-linux.tar.gz
65-
echo "$(pwd)/wasm-component-ld-v0.5.15-x86_64-linux" >> $GITHUB_PATH
6660
if: runner.os == 'Linux'

.github/workflows/main.yml

Lines changed: 53 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313
buildlibc:
1414
name: ${{ matrix.name }}
1515
runs-on: ${{ matrix.os }}
16-
env: ${{ matrix.env || fromJSON('{}') }}
1716
strategy:
1817
fail-fast: false
1918
matrix:
@@ -33,122 +32,101 @@ jobs:
3332
clang_version: 15.0.7
3433
llvm_asset_suffix: arm64-apple-darwin22.0
3534
upload: macos-clang-15
35+
args: -DBUILD_SHARED=OFF -DCMAKE_C_COMPILER_WORKS=ON
3636
- name: Build on Windows x86_64
3737
os: windows-2025
3838
clang_version: 20.1.8
3939
upload: windows-clang-20
40+
args: -DBUILD_SHARED=OFF
4041

4142
# Other versions of LLVM
4243
- name: Build with LLVM 11
4344
os: ubuntu-22.04
4445
clang_version: 11
4546
upload: linux-x86_64-clang-11
46-
env:
47-
BUILD_LIBSETJMP: no
47+
args: -DSETJMP=OFF -DBUILD_SHARED=OFF
4848
- name: Build with LLVM 18
4949
os: ubuntu-24.04
5050
clang_version: 18
5151
upload: linux-x86_64-clang-18
52-
env:
53-
MAKE_TARGETS: "default libc_so"
5452

5553
# Test various combinations of target triples.
5654
#
57-
# Configuration here can happen through `env` which is inherited to
58-
# jobs below. For now this only runs tests on Linux with Clang 16,
59-
# but that can be expanded as necessary in the future too. Note that
60-
# some targets run the build for the `libc_so` makefile target to
61-
# ensure the PIC build works.
55+
# Configuration here can happen through `args` which are all passed
56+
# to CMake. For now this only runs tests on Linux with Clang 16,
57+
# but that can be expanded as necessary in the future too.
6258
- name: Test wasm32-wasi
6359
os: ubuntu-24.04
6460
clang_version: 19
6561
test: true
6662
upload: wasm32-wasi
67-
env:
68-
TARGET_TRIPLE: wasm32-wasi
69-
MAKE_TARGETS: "default libc_so"
63+
args: -DTARGET_TRIPLE=wasm32-wasi
64+
7065
- name: Test wasm32-wasip1
7166
os: ubuntu-24.04
7267
clang_version: 19
7368
test: true
7469
upload: wasm32-wasip1
75-
env:
76-
TARGET_TRIPLE: wasm32-wasip1
77-
MAKE_TARGETS: "default libc_so"
70+
args: -DTARGET_TRIPLE=wasm32-wasip1
71+
7872
- name: Test wasm32-wasip2
7973
os: ubuntu-24.04
8074
clang_version: 19
8175
test: true
8276
upload: wasm32-wasip2
83-
env:
84-
TARGET_TRIPLE: wasm32-wasip2
85-
WASI_SNAPSHOT: p2
86-
MAKE_TARGETS: "default libc_so"
77+
args: -DTARGET_TRIPLE=wasm32-wasip2
78+
8779
- name: Test wasm32-wasip1-threads
8880
os: ubuntu-24.04
8981
clang_version: 19
9082
test: true
9183
upload: wasm32-wasip1-threads
92-
env:
93-
TARGET_TRIPLE: wasm32-wasip1-threads
94-
THREAD_MODEL: posix
84+
args: -DTARGET_TRIPLE=wasm32-wasip1-threads
85+
9586
- name: Test wasm32-wasip1 in V8
9687
os: ubuntu-24.04
9788
clang_version: 19
9889
test: true
9990
test_with_v8: true
100-
env:
101-
TARGET_TRIPLE: wasm32-wasip1
91+
args: -DTARGET_TRIPLE=wasm32-wasip1
92+
10293
- name: Test wasm32-wasip1-threads in V8
10394
os: ubuntu-24.04
10495
clang_version: 19
10596
test: true
10697
test_with_v8: true
107-
env:
108-
TARGET_TRIPLE: wasm32-wasip1-threads
109-
THREAD_MODEL: posix
98+
args: -DTARGET_TRIPLE=wasm32-wasip1-threads
11099

111100
- name: Test wasm32-wasi-simd
112101
os: ubuntu-24.04
113102
clang_version: 19
114103
test: true
115104
upload: wasm32-wasi-simd
116-
env:
117-
TARGET_TRIPLE: wasm32-wasip1
118-
MAKE_TARGETS: "no-check-symbols"
119-
EXTRA_CFLAGS: "-O2 -DNDEBUG -msimd128 -mrelaxed-simd -mbulk-memory -D__wasilibc_simd_string"
105+
args: -DSIMD=ON -DCHECK_SYMBOLS=OFF
120106

121107
- name: Test wasm32-wasip1 (debug)
122108
os: ubuntu-24.04
123109
clang_version: 19
124110
test: true
125-
env:
126-
TARGET_TRIPLE: wasm32-wasip1
127-
DEBUG: true
111+
args: -DCMAKE_BUILD_TYPE=Debug
112+
128113
- name: Test wasm32-wasip2 (debug)
129114
os: ubuntu-24.04
130115
clang_version: 19
131116
test: true
132-
env:
133-
TARGET_TRIPLE: wasm32-wasip2
134-
WASI_SNAPSHOT: p2
135-
DEBUG: true
117+
args: -DCMAKE_BUILD_TYPE=Debug -DTARGET_TRIPLE=wasm32-wasip2
118+
136119
- name: Test wasm32-wasip1-threads (debug)
137120
os: ubuntu-24.04
138121
clang_version: 19
139122
test: true
140-
env:
141-
TARGET_TRIPLE: wasm32-wasip1-threads
142-
THREAD_MODEL: posix
143-
DEBUG: true
123+
args: -DCMAKE_BUILD_TYPE=Debug -DTARGET_TRIPLE=wasm32-wasip1-threads
144124

145125
- name: Test emmalloc
146126
os: ubuntu-24.04
147127
clang_version: 19
148128
test: true
149-
env:
150-
TARGET_TRIPLE: wasm32-wasip1
151-
MALLOC_IMPL: emmalloc
129+
args: -DMALLOC=emmalloc
152130

153131
steps:
154132
- uses: actions/[email protected]
@@ -160,9 +138,6 @@ jobs:
160138
clang_version: ${{ matrix.clang_version }}
161139
llvm_asset_suffix: ${{ matrix.llvm_asset_suffix }}
162140

163-
- name: Build libc
164-
run: make -j4 $MAKE_TARGETS CHECK_SYMBOLS=yes
165-
166141
- name: Install V8 dependencies
167142
if: matrix.test_with_v8
168143
run: |
@@ -171,29 +146,29 @@ jobs:
171146
echo ENGINE="$PWD/test/scripts/browser-test/harness.mjs" >> $GITHUB_ENV
172147
echo CTEST_ARGS="--label-exclude v8fail" >> $GITHUB_ENV
173148
174-
- name: Setup testing
175-
if: matrix.test
149+
- name: Configure libc
176150
run: |
177-
cmake -S test -B testbuild -G Ninja \
178-
-DTARGET_TRIPLE=${{ env.TARGET_TRIPLE }} \
179-
-DENGINE=${{ env.ENGINE }} \
180-
-DCMAKE_LINK_DEPENDS_USE_LINKER=OFF \
181-
-DMALLOC_IMPL=${{ env.MALLOC_IMPL }}
151+
cmake -G Ninja -S . -B build \
152+
-DCHECK_SYMBOLS=ON \
153+
${{ matrix.args }} \
154+
-DCMAKE_LINK_DEPENDS_USE_LINKER=OFF
182155
183-
- name: Build tests
156+
- name: Configure testing
184157
if: matrix.test
185-
run: ninja -C testbuild
158+
run: cmake -S . -B build -DBUILD_TESTS=ON -DENGINE=${{ env.ENGINE }}
159+
160+
- name: Build
161+
run: ninja -C build -v
186162

187163
- name: Test
188164
if: matrix.test
189-
run: ctest --test-dir testbuild --output-on-failure -j4 $CTEST_ARGS
190-
165+
run: ctest --test-dir build/test --output-on-failure -j4 $CTEST_ARGS
191166

192167
- uses: actions/[email protected]
193168
if: matrix.upload
194169
with:
195170
name: ${{ format( 'sysroot-{0}.tgz', matrix.upload) }}
196-
path: sysroot
171+
path: build/sysroot
197172

198173

199174
# Disable the headerstest job for now, while WASI transitions from the
@@ -244,7 +219,8 @@ jobs:
244219
- uses: actions/[email protected]
245220
with:
246221
submodules: true
247-
- run: make bindings
222+
- run: CC=clang cmake -S . -B build -G Ninja
223+
- run: ninja -C build bindings
248224
- run: git diff --exit-code
249225

250226
# Currently wasi-libc's test suite is pretty bare-bones. To try to increase
@@ -253,42 +229,39 @@ jobs:
253229
# the end this runs at least some Python tests against a from-source-built
254230
# copy of wasi-libc.
255231
python:
256-
name: Test Python
232+
name: Test Python ${{ matrix.name }}
257233
runs-on: ubuntu-24.04-arm
258-
env: ${{ matrix.env || fromJSON('{}') }}
259234
strategy:
260235
fail-fast: false
261236
matrix:
262237
include:
263-
- env:
264-
TARGET_TRIPLE: wasm32-wasip1
265-
- env:
266-
TARGET_TRIPLE: wasm32-wasip2
267-
WASI_SNAPSHOT: p2
268-
- env:
269-
TARGET_TRIPLE: wasm32-wasip1
270-
MALLOC_IMPL: emmalloc
238+
- name: wasm32-wasip1
239+
args: -DTARGET_TRIPLE=wasm32-wasip1
240+
- name: emmalloc
241+
args: -DTARGET_TRIPLE=wasm32-wasip1 -DMALLOC=emmalloc
242+
- name: wasm32-wasip2
243+
args: -DTARGET_TRIPLE=wasm32-wasip2
271244
steps:
272245
- uses: actions/[email protected]
273246
with:
274247
submodules: true
275248
- run: |
276-
curl https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-24/wasi-sdk-24.0-arm64-linux.tar.gz -L | tar xzvf -
277-
echo "WASI_SDK_PATH=`pwd`/wasi-sdk-24.0-arm64-linux" >> $GITHUB_ENV
249+
curl https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/wasi-sdk-25.0-arm64-linux.tar.gz -L | tar xzvf -
250+
echo "WASI_SDK_PATH=`pwd`/wasi-sdk-25.0-arm64-linux" >> $GITHUB_ENV
278251
if: runner.os == 'Linux'
279252
shell: bash
280253
working-directory: ${{ runner.tool_cache }}
281254
- name: Setup `wasmtime`
282255
uses: bytecodealliance/actions/wasmtime/setup@v1
283256
with:
284257
version: "38.0.3"
285-
- run: make -j4 CC=$WASI_SDK_PATH/bin/clang AR=$WASI_SDK_PATH/bin/llvm-ar
286-
- name: Setup testing
258+
- name: Setup wasi-libc
287259
run: |
288-
cmake -S test -B testbuild -G Ninja \
289-
-DTARGET_TRIPLE=${{ env.TARGET_TRIPLE }} \
260+
cmake -S . -B build -G Ninja \
261+
${{ matrix.args }} \
290262
-DCMAKE_LINK_DEPENDS_USE_LINKER=OFF \
291263
-DPYTHON_TESTS=ON \
292-
-DCMAKE_C_COMPILER=clang
264+
-DBUILD_TESTS=ON \
265+
-DCMAKE_C_COMPILER=$WASI_SDK_PATH/bin/clang
293266
- name: Build and test python
294-
run: ninja -C testbuild python
267+
run: ninja -C build -v python

0 commit comments

Comments
 (0)