Skip to content

Commit

Permalink
add wasm32-wasi-preview2 target
Browse files Browse the repository at this point in the history
Currently, this is identical to the `wasm32-wasi` in all but name.  See WebAssembly#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 WebAssembly#447 for further details.

Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Dec 20, 2023
1 parent 4bac52e commit 4679dd8
Show file tree
Hide file tree
Showing 7 changed files with 4,856 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ jobs:

- name: Build libc
shell: bash
run: make -j4
run: |
make -j4
WASI_SNAPSHOT=preview2 make -j4
- name: Test
shell: bash
Expand All @@ -98,6 +100,8 @@ jobs:
mkdir -p $WASI_DIR
cp download/lib/wasi/libclang_rt.builtins-wasm32.a $WASI_DIR
make test
rm -r build
WASI_SNAPSHOT=preview2 make test
# The older version of Clang does not provide the expected symbol for the
# test entrypoints: `undefined symbol: __main_argc_argv`.
# The older (<15.0.7) version of wasm-ld does not provide `__heap_end`,
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ SYSROOT ?= $(CURDIR)/sysroot
INSTALL_DIR ?= /usr/local
# single or posix; note that pthread support is still a work-in-progress.
THREAD_MODEL ?= single
# preview1 or preview2; the latter is not (yet) compatible with multithreading
WASI_SNAPSHOT ?= preview1
# dlmalloc or none
MALLOC_IMPL ?= dlmalloc
# yes or no
Expand All @@ -41,6 +43,10 @@ ifeq ($(THREAD_MODEL), posix)
TARGET_TRIPLE = wasm32-wasi-threads
endif

ifeq ($(WASI_SNAPSHOT), preview2)
TARGET_TRIPLE = wasm32-wasi-preview2
endif

BUILTINS_LIB ?= $(shell ${CC} --print-libgcc-file-name)

# These variables describe the locations of various files and directories in
Expand Down Expand Up @@ -386,7 +392,7 @@ LIBC_BOTTOM_HALF_CRT_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_CRT_SOURCES))
# These variables describe the locations of various files and
# directories in the generated sysroot tree.
SYSROOT_LIB := $(SYSROOT)/lib/$(TARGET_TRIPLE)
SYSROOT_INC = $(SYSROOT)/include
SYSROOT_INC = $(SYSROOT)/include/$(TARGET_TRIPLE)
SYSROOT_SHARE = $(SYSROOT)/share/$(TARGET_TRIPLE)

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

$(OBJDIR)/libc.so.a: $(LIBC_SO_OBJS) $(MUSL_PRINTSCAN_LONG_DOUBLE_SO_OBJS)
Expand Down
Loading

0 comments on commit 4679dd8

Please sign in to comment.