@@ -16,16 +16,28 @@ test: run
1616OBJDIR ?= $(CURDIR ) /build
1717DOWNDIR ?= $(CURDIR ) /download
1818
19+ # preview1 or preview2
20+ WASI_SNAPSHOT ?= preview1
21+
1922# #### DOWNLOAD #################################################################
2023
2124LIBC_TEST_URL ?= https://github.com/bytecodealliance/libc-test
2225LIBC_TEST = $(DOWNDIR ) /libc-test
2326LIBRT_URL ?= https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-16/libclang_rt.builtins-wasm32-wasi-16.0.tar.gz
2427LIBRT = $(DOWNDIR ) /lib/wasi/libclang_rt.builtins-wasm32.a
25- WASMTIME_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/v3 .0.0/wasmtime-v3 .0.0-x86_64-linux.tar.xz
28+ WASMTIME_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/v16 .0.0/wasmtime-v16 .0.0-x86_64-linux.tar.xz
2629WASMTIME = $(DOWNDIR ) /$(shell basename $(WASMTIME_URL ) .tar.xz) /wasmtime
30+ WASM_TOOLS_URL ?= https://github.com/bytecodealliance/wasm-tools/releases/download/wasm-tools-1.0.54/wasm-tools-1.0.54-x86_64-linux.tar.gz
31+ WASM_TOOLS = $(DOWNDIR ) /$(shell basename $(WASM_TOOLS_URL ) .tar.gz) /wasm-tools
32+ ADAPTER_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/v16.0.0/wasi_snapshot_preview1.command.wasm
33+ ADAPTER = $(DOWNDIR ) /wasi_snapshot_preview1.command.wasm
34+
35+ TO_DOWNLOAD = $(LIBC_TEST ) $(LIBRT ) $(WASMTIME )
36+ ifeq ($(WASI_SNAPSHOT ) , preview2)
37+ TO_DOWNLOAD += $(ADAPTER ) $(WASM_TOOLS )
38+ endif
2739
28- download : $(LIBC_TEST ) $( LIBRT ) $( WASMTIME )
40+ download : $(TO_DOWNLOAD )
2941
3042$(DOWNDIR ) :
3143 mkdir -p download
@@ -42,6 +54,13 @@ $(WASMTIME): | $(DOWNDIR)
4254 wget --no-clobber --directory-prefix=$(DOWNDIR ) $(WASMTIME_URL )
4355 tar --extract --file=$(DOWNDIR ) /$(shell basename $(WASMTIME_URL ) ) --directory=$(DOWNDIR ) /
4456
57+ $(WASM_TOOLS ) : | $(DOWNDIR )
58+ wget --no-clobber --directory-prefix=$(DOWNDIR ) $(WASM_TOOLS_URL )
59+ tar --extract --file=$(DOWNDIR ) /$(shell basename $(WASM_TOOLS_URL ) ) --directory=$(DOWNDIR ) /
60+
61+ $(ADAPTER ) : | $(DOWNDIR )
62+ wget --no-clobber --directory-prefix=$(DOWNDIR ) $(ADAPTER_URL )
63+
4564clean ::
4665 rm -rf download
4766
@@ -110,13 +129,18 @@ WASM_OBJS += $(INFRA_WASM_OBJS)
110129DIRS := $(patsubst $(OBJDIR ) /% /,% ,$(sort $(dir $(WASM_OBJS ) ) ) )
111130OBJDIRS := $(DIRS:%=$(OBJDIR ) /% )
112131
132+ TARGET_TRIPLE = wasm32-wasi
133+ ifeq ($(WASI_SNAPSHOT ) , preview2)
134+ TARGET_TRIPLE = wasm32-wasi-preview2
135+ endif
136+
113137# Allow $(CC) to be set from the command line; ?= doesn't work for CC because
114138# make has a default value for it.
115139ifeq ($(origin CC ) , default)
116140CC := clang
117141endif
118142LDFLAGS ?=
119- CFLAGS ?= --target=wasm32-wasi --sysroot=../sysroot
143+ CFLAGS ?= --target=$( TARGET_TRIPLE ) --sysroot=../sysroot
120144# Always include the `libc-test` infrastructure headers.
121145CFLAGS += -I$(LIBC_TEST ) /src/common
122146
@@ -129,7 +153,10 @@ build: download $(WASMS)
129153
130154$(WASMS ) : | $(OBJDIRS )
131155$(OBJDIR ) /% .wasm : $(OBJDIR ) /% .wasm.o $(INFRA_WASM_OBJS )
132- $(CC ) $(CFLAGS ) $(LDFLAGS ) -o $@ $^
156+ $(CC ) $(CFLAGS ) $(LDFLAGS ) -o $@ $^
157+ ifeq ($(WASI_SNAPSHOT ) , preview2)
158+ $(WASM_TOOLS) component new --adapt $(ADAPTER) $@ -o $@
159+ endif
133160
134161$(WASM_OBJS ) : $(LIBC_TEST ) /src/common/test.h | $(OBJDIRS )
135162$(OBJDIR ) /% .wasm.o : $(LIBC_TEST ) /src/% .c
@@ -144,6 +171,9 @@ clean::
144171# #### RUN ######################################################################
145172
146173ENGINE ?= $(WASMTIME ) run
174+ ifeq ($(WASI_SNAPSHOT ) , preview2)
175+ ENGINE += --wasm component-model
176+ endif
147177ERRS:=$(WASMS:%.wasm =%.wasm.err)
148178
149179# Use the provided Wasm engine to execute each test, emitting its output into
0 commit comments