Skip to content

Commit

Permalink
Start renaming preview1 to p1 and preview2 to p2 (#478)
Browse files Browse the repository at this point in the history
* Start renaming preview1 to p1 and preview2 to p2

This is an initial start at renaming the "preview" terminology in WASI
targets to "pX". For example the `wasm32-wasi` target should transition
to `wasm32-wasip1`, `wasm32-wasi-preview2` should transition to
`wasm32-wasip2`, and `wasm32-wasi-threads` should transition to
`wasm32-wasip1-threads`. This commit applies a few renames in the
`Makefile` such as:

* `WASI_SNAPSHOT` is now either "p1" or "p2"
* The default p2 target triple is now `wasm32-wasip2` instead of
  `wasm32-wasi-preview2` (in the hopes that it's early enough to change
  the default).
* Bindings for WASIp2 were renamed from "preview2" terminology to "wasip2".
* The expected-defines files are renamed and the logic of which
  expectation was used has been updated slightly.

With this commit the intention is that non-preview2 defaults do not
change. For example the default build still produces a `wasm32-wasi`
sysroot. If `TARGET_TRIPLE=wasm32-wasip1` is passed, however, then that
sysroot is produced instead. Similarly a `THREAD_MODEL=posix` build
produces a `wasm32-wasi-threads` sysroot target but you can now also
pass `TARGET_TRIPLE=wasm32-wasip1-threads` to rename the sysroot.

My hope is to integrate this into the wasi-sdk repository and build a
dual sysroot for these new targets for a release or two so both are
supported and then in the future the defaults can be switched away from
`wasm32-wasi` to `wasm32-wasip1` as built-by-default.

* Update builds in CI

* Update test workflow

* Fix test for wasm32-wasip1-threads

* Make github actions rules a bit more readable
  • Loading branch information
alexcrichton authored Mar 4, 2024
1 parent 09683b3 commit c9c7d06
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 169 deletions.
21 changes: 16 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,19 @@ jobs:
- name: Build libc
shell: bash
run: |
make -j4
WASI_SNAPSHOT=preview2 make -j4
make -j4 TARGET_TRIPLE=wasm32-wasi
make -j4 TARGET_TRIPLE=wasm32-wasip1
make -j4 TARGET_TRIPLE=wasm32-wasip2 WASI_SNAPSHOT=p2
- name: Build libc + threads
# Only build the thread-capable wasi-libc in the latest supported Clang
# version; the earliest version does not have all necessary builtins
# (e.g., `__builtin_wasm_memory_atomic_notify`).
if: matrix.clang_version != '10.0.0'
shell: bash
run: make -j4 THREAD_MODEL=posix
run: |
make -j4 THREAD_MODEL=posix TARGET_TRIPLE=wasm32-wasi-threads
make -j4 THREAD_MODEL=posix TARGET_TRIPLE=wasm32-wasip1-threads
- name: Test
shell: bash
Expand All @@ -105,13 +108,21 @@ jobs:
cd test
make download
export WASI_DIR=$(realpath $($CLANG_DIR/clang -print-resource-dir)/lib/wasi/)
mkdir -p $WASI_DIR
export WASIP1_DIR=$(realpath $($CLANG_DIR/clang -print-resource-dir)/lib/wasip1/)
export WASIP2_DIR=$(realpath $($CLANG_DIR/clang -print-resource-dir)/lib/wasip2/)
mkdir -p $WASI_DIR $WASIP1_DIR $WASIP2_DIR
cp download/lib/wasi/libclang_rt.builtins-wasm32.a $WASI_DIR
cp download/lib/wasi/libclang_rt.builtins-wasm32.a $WASIP1_DIR
cp download/lib/wasi/libclang_rt.builtins-wasm32.a $WASIP2_DIR
TARGET_TRIPLE=wasm32-wasi make test
rm -r build
TARGET_TRIPLE=wasm32-wasi-preview2 make test
TARGET_TRIPLE=wasm32-wasip1 make test
rm -r build
TARGET_TRIPLE=wasm32-wasip2 make test
rm -r build
TARGET_TRIPLE=wasm32-wasi-threads make test
rm -r build
TARGET_TRIPLE=wasm32-wasip1-threads 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
61 changes: 36 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ 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
# p1 or p2; the latter is not (yet) compatible with multithreading
WASI_SNAPSHOT ?= p1
# dlmalloc or none
MALLOC_IMPL ?= dlmalloc
# yes or no
BUILD_LIBC_TOP_HALF ?= yes
# The directory where we will store intermediate artifacts.
OBJDIR ?= build/$(TARGET_TRIPLE)
# The directory where we store files and tools for generating WASI Preview 2 bindings
# The directory where we store files and tools for generating WASIp2 bindings
BINDING_WORK_DIR ?= build/bindings
# URL from which to retrieve the WIT files used to generate the WASI Preview 2 bindings
# URL from which to retrieve the WIT files used to generate the WASIp2 bindings
WASI_CLI_URL ?= https://github.com/WebAssembly/wasi-cli/archive/refs/tags/v0.2.0.tar.gz
# URL from which to retrieve the `wit-bindgen` command used to generate the WASI
# Preview 2 bindings.
# URL from which to retrieve the `wit-bindgen` command used to generate the
# WASIp2 bindings.
WIT_BINDGEN_URL ?= https://github.com/bytecodealliance/wit-bindgen/releases/download/wit-bindgen-cli-0.17.0/wit-bindgen-v0.17.0-x86_64-linux.tar.gz

# When the length is no larger than this threshold, we consider the
Expand All @@ -50,8 +50,8 @@ ifeq ($(THREAD_MODEL), posix)
TARGET_TRIPLE = wasm32-wasi-threads
endif

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

BUILTINS_LIB ?= $(shell ${CC} --print-libgcc-file-name)
Expand All @@ -75,16 +75,16 @@ LIBC_BOTTOM_HALF_ALL_SOURCES = \
$(shell find $(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC) -name \*.c) \
$(shell find $(LIBC_BOTTOM_HALF_SOURCES) -name \*.c))

ifeq ($(WASI_SNAPSHOT), preview1)
# Omit source files not relevant to WASI Preview 1. As we introduce files
# supporting `wasi-sockets` for `wasm32-wasi-preview2`, we'll add those files to
ifeq ($(WASI_SNAPSHOT), p1)
# Omit source files not relevant to WASIp1. As we introduce files
# supporting `wasi-sockets` for `wasm32-wasip2`, we'll add those files to
# this list.
LIBC_BOTTOM_HALF_OMIT_SOURCES := \
$(LIBC_BOTTOM_HALF_SOURCES)/preview2.c \
$(LIBC_BOTTOM_HALF_SOURCES)/wasip2.c \
$(LIBC_BOTTOM_HALF_SOURCES)/descriptor_table.c
LIBC_BOTTOM_HALF_ALL_SOURCES := $(filter-out $(LIBC_BOTTOM_HALF_OMIT_SOURCES),$(LIBC_BOTTOM_HALF_ALL_SOURCES))
# Omit preview2-specific headers from include-all.c test.
INCLUDE_ALL_CLAUSES := -not -name preview2.h -not -name descriptor_table.h
# Omit p2-specific headers from include-all.c test.
INCLUDE_ALL_CLAUSES := -not -name wasip2.h -not -name descriptor_table.h
endif

# FIXME(https://reviews.llvm.org/D85567) - due to a bug in LLD the weak
Expand Down Expand Up @@ -382,8 +382,8 @@ DLMALLOC_OBJS = $(call objs,$(DLMALLOC_SOURCES))
EMMALLOC_OBJS = $(call objs,$(EMMALLOC_SOURCES))
LIBC_BOTTOM_HALF_ALL_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_ALL_SOURCES))
LIBC_TOP_HALF_ALL_OBJS = $(call asmobjs,$(call objs,$(LIBC_TOP_HALF_ALL_SOURCES)))
ifeq ($(WASI_SNAPSHOT), preview2)
LIBC_OBJS += $(OBJDIR)/preview2_component_type.o
ifeq ($(WASI_SNAPSHOT), p2)
LIBC_OBJS += $(OBJDIR)/wasip2_component_type.o
endif
ifeq ($(MALLOC_IMPL),dlmalloc)
LIBC_OBJS += $(DLMALLOC_OBJS)
Expand Down Expand Up @@ -606,7 +606,7 @@ $(OBJDIR)/%.long-double.pic.o: %.c include_dirs
@mkdir -p "$(@D)"
$(CC) $(CFLAGS) -MD -MP -o $@ -c $<

$(OBJDIR)/preview2_component_type.pic.o $(OBJDIR)/preview2_component_type.o: $(LIBC_BOTTOM_HALF_SOURCES)/preview2_component_type.o
$(OBJDIR)/wasip2_component_type.pic.o $(OBJDIR)/wasip2_component_type.o: $(LIBC_BOTTOM_HALF_SOURCES)/wasip2_component_type.o
@mkdir -p "$(@D)"
cp $< $@

Expand Down Expand Up @@ -741,6 +741,17 @@ endif
DEFINED_SYMBOLS = $(SYSROOT_SHARE)/defined-symbols.txt
UNDEFINED_SYMBOLS = $(SYSROOT_SHARE)/undefined-symbols.txt

ifeq ($(WASI_SNAPSHOT),p2)
EXPECTED_TARGET_DIR = expected/wasm32-wasip2
else
ifeq ($(THREAD_MODEL),posix)
EXPECTED_TARGET_DIR = expected/wasm32-wasip1-threads
else
EXPECTED_TARGET_DIR = expected/wasm32-wasip1
endif
endif


check-symbols: startup_files libc
#
# Collect metadata on the sysroot and perform sanity checks.
Expand Down Expand Up @@ -836,7 +847,7 @@ check-symbols: startup_files libc

# Check that the computed metadata matches the expected metadata.
# This ignores whitespace because on Windows the output has CRLF line endings.
diff -wur "expected/$(TARGET_TRIPLE)" "$(SYSROOT_SHARE)"
diff -wur "$(EXPECTED_TARGET_DIR)" "$(SYSROOT_SHARE)"

install: finish
mkdir -p "$(INSTALL_DIR)"
Expand All @@ -860,7 +871,7 @@ bindings: $(BINDING_WORK_DIR)/wasi-cli $(BINDING_WORK_DIR)/wit-bindgen
cd "$(BINDING_WORK_DIR)" && \
./wit-bindgen/wit-bindgen c \
--autodrop-borrows yes \
--rename-world preview2 \
--rename-world wasip2 \
--type-section-suffix __wasi_libc \
--world wasi:cli/[email protected] \
--rename wasi:clocks/[email protected]=monotonic_clock \
Expand Down Expand Up @@ -891,12 +902,12 @@ bindings: $(BINDING_WORK_DIR)/wasi-cli $(BINDING_WORK_DIR)/wit-bindgen
--rename wasi:cli/[email protected]=terminal_stdout \
--rename wasi:cli/[email protected]=terminal_stderr \
./wasi-cli/wit && \
mv preview2.h ../../libc-bottom-half/headers/public/wasi/ && \
mv preview2_component_type.o ../../libc-bottom-half/sources && \
sed 's_#include "preview2\.h"_#include "wasi/preview2.h"_' \
< preview2.c \
> ../../libc-bottom-half/sources/preview2.c && \
rm preview2.c
mv wasip2.h ../../libc-bottom-half/headers/public/wasi/ && \
mv wasip2_component_type.o ../../libc-bottom-half/sources && \
sed 's_#include "wasip2\.h"_#include "wasi/wasip2.h"_' \
< wasip2.c \
> ../../libc-bottom-half/sources/wasip2.c && \
rm wasip2.c


clean:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ __c_locale
__clock
__clock_gettime
__clock_nanosleep
__component_type_object_force_link_preview2
__component_type_object_force_link_preview2_public_use_in_this_compilation_unit
__component_type_object_force_link_wasip2
__component_type_object_force_link_wasip2_public_use_in_this_compilation_unit
__cos
__cosdf
__cosl
Expand Down Expand Up @@ -1008,15 +1008,6 @@ powf
powl
pread
preadv
preview2_list_string_free
preview2_list_tuple2_string_string_free
preview2_list_u32_free
preview2_list_u8_free
preview2_option_string_free
preview2_string_dup
preview2_string_free
preview2_string_set
preview2_tuple2_string_string_free
printf
program_invocation_name
program_invocation_short_name
Expand Down Expand Up @@ -1384,6 +1375,15 @@ vwprintf
vwscanf
wall_clock_now
wall_clock_resolution
wasip2_list_string_free
wasip2_list_tuple2_string_string_free
wasip2_list_u32_free
wasip2_list_u8_free
wasip2_option_string_free
wasip2_string_dup
wasip2_string_free
wasip2_string_set
wasip2_tuple2_string_string_free
wcpcpy
wcpncpy
wcrtomb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,6 @@
#include <wasi/libc-find-relpath.h>
#include <wasi/libc-nocwd.h>
#include <wasi/libc.h>
#include <wasi/preview2.h>
#include <wasi/wasip2.h>
#include <wchar.h>
#include <wctype.h>
Original file line number Diff line number Diff line change
Expand Up @@ -2474,7 +2474,7 @@
#define __BIGGEST_ALIGNMENT__ 16
#define __BIG_ENDIAN 4321
#define __BIND 19950621
#define __BINDINGS_PREVIEW2_H
#define __BINDINGS_WASIP2_H
#define __BYTE_ORDER __BYTE_ORDER__
#define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
#define __CHAR16_TYPE__ unsigned short
Expand Down
2 changes: 1 addition & 1 deletion libc-bottom-half/headers/private/wasi/descriptor_table.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef DESCRIPTOR_TABLE_H
#define DESCRIPTOR_TABLE_H

#include <wasi/preview2.h>
#include <wasi/wasip2.h>

typedef struct {
int dummy;
Expand Down
Loading

0 comments on commit c9c7d06

Please sign in to comment.