Skip to content

Commit 93bd1f6

Browse files
authored
Fix build and tests for wasm32-wasip2 target (#599)
Trying to build wasi-libc for the `wasm32-wasip2` target and run the tests, I noticed a few issues: - `TARGET_TRIPLE` was being used before definition, in the definition of `OBJDIR`. - The ?= operator instead of = was being used to set `TARGET_TRIPLE` to `wasm32-wasip2`. This always left the target as `wasm32-wasi`, since it was defined to that in a previous line. - `builtins` wasn't being built by default, so building the tests would fail because it was unable to find `libclang_rt.builtins.a`. - `make test` didn't take the`WASI_SNAPSHOT` variable into consideration. - When building tests, `clang --target=wasm32-wasip2` was building a P2 component, which caused the subsequent `wasm-tools component new` to fail because the input was already a component. This PR fixes these issues. Now I'm able to run the tests with `WASI_SNAPSHOT=p2`.
1 parent 3f7eb4c commit 93bd1f6

File tree

4 files changed

+59
-37
lines changed

4 files changed

+59
-37
lines changed

.github/actions/setup/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,10 @@ 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
6066
if: runner.os == 'Linux'

.github/workflows/main.yml

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,21 @@ jobs:
2222
# wasi-libc builds on these platforms by default.
2323
- name: Build on Linux x86_64
2424
os: ubuntu-24.04
25-
clang_version: 16
26-
upload: linux-x86_64-clang-16
25+
clang_version: 19
26+
upload: linux-x86_64-clang-19
2727
- name: Build on Linux aarch64
2828
os: ubuntu-24.04-arm
29-
clang_version: 16
30-
upload: linux-aarch64-clang-16
29+
clang_version: 19
30+
upload: linux-aarch64-clang-19
3131
- name: Build on macOS aarch64
3232
os: macos-15
3333
clang_version: 15.0.7
3434
llvm_asset_suffix: arm64-apple-darwin22.0
3535
upload: macos-clang-15
3636
- name: Build on Windows x86_64
3737
os: windows-2025
38-
clang_version: 16.0.0
39-
upload: windows-clang-16
38+
clang_version: 20.1.8
39+
upload: windows-clang-20
4040

4141
# Other versions of LLVM
4242
- name: Build with LLVM 11
@@ -45,20 +45,14 @@ jobs:
4545
upload: linux-x86_64-clang-11
4646
env:
4747
BUILD_LIBSETJMP: no
48-
- name: Build with LLVM 19
49-
os: ubuntu-24.04
50-
clang_version: 19
51-
upload: linux-x86_64-clang-19
52-
env:
53-
MAKE_TARGETS: "default libc_so"
5448
- name: Build with LLVM 18
5549
os: ubuntu-24.04
5650
clang_version: 18
5751
upload: linux-x86_64-clang-18
5852
env:
5953
MAKE_TARGETS: "default libc_so"
6054

61-
# Test various combinations of targets triples.
55+
# Test various combinations of target triples.
6256
#
6357
# Configuration here can happen through `env` which is inherited to
6458
# jobs below. For now this only runs tests on Linux with Clang 16,
@@ -67,23 +61,23 @@ jobs:
6761
# ensure the PIC build works.
6862
- name: Test wasm32-wasi
6963
os: ubuntu-24.04
70-
clang_version: 16
64+
clang_version: 19
7165
test: true
7266
upload: wasm32-wasi
7367
env:
7468
TARGET_TRIPLE: wasm32-wasi
7569
MAKE_TARGETS: "default libc_so"
7670
- name: Test wasm32-wasip1
7771
os: ubuntu-24.04
78-
clang_version: 16
72+
clang_version: 19
7973
test: true
8074
upload: wasm32-wasip1
8175
env:
8276
TARGET_TRIPLE: wasm32-wasip1
8377
MAKE_TARGETS: "default libc_so"
8478
- name: Test wasm32-wasip2
8579
os: ubuntu-24.04
86-
clang_version: 16
80+
clang_version: 19
8781
test: true
8882
upload: wasm32-wasip2
8983
env:
@@ -92,30 +86,30 @@ jobs:
9286
MAKE_TARGETS: "default libc_so"
9387
- name: Test wasm32-wasi-threads
9488
os: ubuntu-24.04
95-
clang_version: 16
89+
clang_version: 19
9690
test: true
9791
upload: wasm32-wasi-threads
9892
env:
9993
TARGET_TRIPLE: wasm32-wasi-threads
10094
THREAD_MODEL: posix
10195
- name: Test wasm32-wasip1-threads
10296
os: ubuntu-24.04
103-
clang_version: 16
97+
clang_version: 19
10498
test: true
10599
upload: wasm32-wasip1-threads
106100
env:
107101
TARGET_TRIPLE: wasm32-wasip1-threads
108102
THREAD_MODEL: posix
109103
- name: Test wasm32-wasip1 in V8
110104
os: ubuntu-24.04
111-
clang_version: 16
105+
clang_version: 19
112106
test: true
113107
test_with_v8: true
114108
env:
115109
TARGET_TRIPLE: wasm32-wasip1
116110
- name: Test wasm32-wasip1-threads in V8
117111
os: ubuntu-24.04
118-
clang_version: 16
112+
clang_version: 19
119113
test: true
120114
test_with_v8: true
121115
env:
@@ -124,7 +118,7 @@ jobs:
124118

125119
- name: Test wasm32-wasi-simd
126120
os: ubuntu-24.04
127-
clang_version: 16
121+
clang_version: 19
128122
test: true
129123
upload: wasm32-wasi-simd
130124
env:

Makefile

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ MALLOC_IMPL ?= dlmalloc
2323
BUILD_LIBC_TOP_HALF ?= yes
2424
# yes or no
2525
BUILD_LIBSETJMP ?= yes
26+
27+
# Set the default WASI target triple.
28+
TARGET_TRIPLE ?= wasm32-wasi
29+
30+
# Threaded version necessitates a different target, as objects from different
31+
# targets can't be mixed together while linking.
32+
ifeq ($(THREAD_MODEL), posix)
33+
TARGET_TRIPLE = wasm32-wasip1-threads
34+
endif
35+
36+
ifeq ($(WASI_SNAPSHOT), p2)
37+
TARGET_TRIPLE = wasm32-wasip2
38+
endif
39+
2640
# The directory where we will store intermediate artifacts.
2741
OBJDIR ?= build/$(TARGET_TRIPLE)
2842

@@ -46,19 +60,6 @@ BULK_MEMORY_THRESHOLD ?= 32
4660
# Variables from this point on are not meant to be overridable via the
4761
# make command-line.
4862

49-
# Set the default WASI target triple.
50-
TARGET_TRIPLE ?= wasm32-wasi
51-
52-
# Threaded version necessitates a different target, as objects from different
53-
# targets can't be mixed together while linking.
54-
ifeq ($(THREAD_MODEL), posix)
55-
TARGET_TRIPLE ?= wasm32-wasi-threads
56-
endif
57-
58-
ifeq ($(WASI_SNAPSHOT), p2)
59-
TARGET_TRIPLE ?= wasm32-wasip2
60-
endif
61-
6263
# These artifacts are "stamps" that we use to mark that some task (e.g., copying
6364
# files) has been completed.
6465
INCLUDE_DIRS := $(OBJDIR)/copy-include-headers.stamp
@@ -596,7 +597,9 @@ PIC_OBJS = \
596597
# exists that should be used instead.
597598
SYSTEM_BUILTINS_LIB := $(shell ${CC} ${CFLAGS} --print-libgcc-file-name)
598599
SYSTEM_RESOURCE_DIR := $(shell ${CC} ${CFLAGS} -print-resource-dir)
599-
BUILTINS_LIB_REL := $(subst $(SYSTEM_RESOURCE_DIR),,$(SYSTEM_BUILTINS_LIB))
600+
BUILTINS_LIB_REL_1 := $(subst $(SYSTEM_RESOURCE_DIR),,$(SYSTEM_BUILTINS_LIB))
601+
# Substitute '/' for '\' so Windows paths work
602+
BUILTINS_LIB_REL := $(subst \,/,$(BUILTINS_LIB_REL_1))
600603
TMP_RESOURCE_DIR := $(OBJDIR)/resource-dir
601604
BUILTINS_LIB_PATH := $(TMP_RESOURCE_DIR)/$(BUILTINS_LIB_REL)
602605
BUILTINS_LIB_DIR := $(dir $(BUILTINS_LIB_PATH))
@@ -610,7 +613,10 @@ else
610613
BUILTINS_URL := https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/libclang_rt.builtins-wasm32-wasi-25.0.tar.gz
611614

612615
$(BUILTINS_LIB_PATH):
613-
mkdir -p $(BUILTINS_LIB_DIR)
616+
# mkdir on Windows will error if the directory already exists
617+
ifeq ("$(wildcard $(BUILTINS_LIB_DIR))","")
618+
mkdir -p "$(BUILTINS_LIB_DIR)"
619+
endif
614620
curl -sSfL $(BUILTINS_URL) | \
615621
tar xzf - -C $(BUILTINS_LIB_DIR) --strip-components 1
616622
if [ ! -f $(BUILTINS_LIB_PATH) ]; then \
@@ -850,7 +856,7 @@ STATIC_LIBS += \
850856
$(SYSROOT_LIB)/libsetjmp.a
851857
endif
852858

853-
libc: $(INCLUDE_DIRS) $(STATIC_LIBS)
859+
libc: $(INCLUDE_DIRS) $(STATIC_LIBS) builtins
854860

855861
DUMMY := m rt pthread crypt util xnet resolv
856862
DUMMY_LIBS := $(patsubst %,$(SYSROOT_LIB)/lib%.a,$(DUMMY))

test/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ test: run
1414
# Decide which target to build for and which libc to use.
1515
TARGET_TRIPLE ?= wasm32-wasi
1616

17+
# See comment in ../Makefile
18+
ifeq ($(THREAD_MODEL), posix)
19+
TARGET_TRIPLE = wasm32-wasip1-threads
20+
endif
21+
22+
ifeq ($(WASI_SNAPSHOT), p2)
23+
TARGET_TRIPLE = wasm32-wasip2
24+
endif
25+
1726
# Setup various paths used by the tests.
1827
OBJDIR ?= build/$(TARGET_TRIPLE)
1928
DOWNDIR ?= build/download
@@ -135,6 +144,13 @@ $(BUILTINS_STAMP):
135144
make -C .. builtins
136145
touch $@
137146

147+
# For wasip2, we want clang to generate a core module rather than a component,
148+
# because `wasm-tools component new` is called subsequently and it expects
149+
# a core module.
150+
ifeq ($(TARGET_TRIPLE), wasm32-wasip2)
151+
LDFLAGS += -Wl,--skip-wit-component
152+
endif
153+
138154
# Build up all the `*.wasm.o` object files; these are the same regardless of
139155
# whether we're building core modules or components.
140156
$(WASM_OBJS): $(INFRA_HEADERS)

0 commit comments

Comments
 (0)