Skip to content

Commit 5a69318

Browse files
authored
add wasm32-wasi-preview2 target (#457)
Currently, this is identical to the `wasm32-wasi` in all but name. See #449 for the next step, which is to incrementally add Preview 2 features, e.g. `wasi-sockets`. Per the discussion in that PR, I've split the `wasi-sysroot/include` directory into per-target directories. Eventually, we'll want to build a separate sysroot for each target, but there's currently uncertainty about how to configure the default sysroot for e.g. clang, so we're not tackling that yet. See also #447 for further details. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent 4bac52e commit 5a69318

7 files changed

Lines changed: 4856 additions & 7 deletions

File tree

.github/workflows/main.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ jobs:
8484

8585
- name: Build libc
8686
shell: bash
87-
run: make -j4
87+
run: |
88+
make -j4
89+
WASI_SNAPSHOT=preview2 make -j4
8890
8991
- name: Test
9092
shell: bash
@@ -98,6 +100,8 @@ jobs:
98100
mkdir -p $WASI_DIR
99101
cp download/lib/wasi/libclang_rt.builtins-wasm32.a $WASI_DIR
100102
make test
103+
rm -r build
104+
WASI_SNAPSHOT=preview2 make test
101105
# The older version of Clang does not provide the expected symbol for the
102106
# test entrypoints: `undefined symbol: __main_argc_argv`.
103107
# The older (<15.0.7) version of wasm-ld does not provide `__heap_end`,

Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ SYSROOT ?= $(CURDIR)/sysroot
1515
INSTALL_DIR ?= /usr/local
1616
# single or posix; note that pthread support is still a work-in-progress.
1717
THREAD_MODEL ?= single
18+
# preview1 or preview2; the latter is not (yet) compatible with multithreading
19+
WASI_SNAPSHOT ?= preview1
1820
# dlmalloc or none
1921
MALLOC_IMPL ?= dlmalloc
2022
# yes or no
@@ -41,6 +43,10 @@ ifeq ($(THREAD_MODEL), posix)
4143
TARGET_TRIPLE = wasm32-wasi-threads
4244
endif
4345

46+
ifeq ($(WASI_SNAPSHOT), preview2)
47+
TARGET_TRIPLE = wasm32-wasi-preview2
48+
endif
49+
4450
BUILTINS_LIB ?= $(shell ${CC} --print-libgcc-file-name)
4551

4652
# These variables describe the locations of various files and directories in
@@ -386,7 +392,7 @@ LIBC_BOTTOM_HALF_CRT_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_CRT_SOURCES))
386392
# These variables describe the locations of various files and
387393
# directories in the generated sysroot tree.
388394
SYSROOT_LIB := $(SYSROOT)/lib/$(TARGET_TRIPLE)
389-
SYSROOT_INC = $(SYSROOT)/include
395+
SYSROOT_INC = $(SYSROOT)/include/$(TARGET_TRIPLE)
390396
SYSROOT_SHARE = $(SYSROOT)/share/$(TARGET_TRIPLE)
391397

392398
# Files from musl's include directory that we don't want to install in the
@@ -511,7 +517,7 @@ PIC_OBJS = \
511517
# to CC. This is a workaround for a Windows command line size limitation. See
512518
# the `%.a` rule below for details.
513519
$(SYSROOT_LIB)/%.so: $(OBJDIR)/%.so.a $(BUILTINS_LIB)
514-
$(CC) -nodefaultlibs -shared --sysroot=$(SYSROOT) \
520+
$(CC) --target=$(TARGET_TRIPLE) -nodefaultlibs -shared --sysroot=$(SYSROOT) \
515521
-o $@ -Wl,--whole-archive $< -Wl,--no-whole-archive $(BUILTINS_LIB)
516522

517523
$(OBJDIR)/libc.so.a: $(LIBC_SO_OBJS) $(MUSL_PRINTSCAN_LONG_DOUBLE_SO_OBJS)

0 commit comments

Comments
 (0)