Skip to content

Commit

Permalink
Start renaming preview1 to p1 and preview2 to p2
Browse files Browse the repository at this point in the history
This commit is a reflection of WebAssembly/wasi-libc#478 into this
repository where a few changes are happening:

* A new `wasm32-wasip1` sysroot is prepared matching `wasm32-wasi`
* A new `wasm32-wasip1-threads` sysroot is prepared matching `wasm32-wasi-threads`
* The `wasm32-wasi-preview2` target is renamed `wasm32-wasip2`

I've done a bit of makefile refactoring to deduplicate things a bit now
that there's a number of targets being built.

The long-term goal would be to remove the `wasm32-wasi` and
`wasm32-wasip1-threads` targets, but that's not proposed just yet at
this time.
  • Loading branch information
alexcrichton committed Mar 2, 2024
1 parent f1ebc52 commit 36499ca
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
url = https://github.com/llvm/llvm-project
[submodule "src/wasi-libc"]
path = src/wasi-libc
url = https://github.com/WebAssembly/wasi-libc
url = https://github.com/alexcrichton/wasi-libc
[submodule "src/config"]
path = src/config
url = https://git.savannah.gnu.org/git/config.git
103 changes: 45 additions & 58 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,22 @@ build/llvm.BUILT:
llvm-config
touch build/llvm.BUILT

# Flags for running `make` in wasi-libc
# $(1): the target that's being built
WASI_LIBC_MAKEFLAGS = \
-C $(ROOT_DIR)/src/wasi-libc \
CC=$(BUILD_PREFIX)/bin/clang \
AR=$(BUILD_PREFIX)/bin/llvm-ar \
NM=$(BUILD_PREFIX)/bin/llvm-nm \
SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \
TARGET_TRIPLE=$(1)

build/wasi-libc.BUILT: build/compiler-rt.BUILT
$(MAKE) -C $(ROOT_DIR)/src/wasi-libc \
CC=$(BUILD_PREFIX)/bin/clang \
AR=$(BUILD_PREFIX)/bin/llvm-ar \
NM=$(BUILD_PREFIX)/bin/llvm-nm \
SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \
WASI_SNAPSHOT=preview2 \
default libc_so
$(MAKE) -C $(ROOT_DIR)/src/wasi-libc \
CC=$(BUILD_PREFIX)/bin/clang \
AR=$(BUILD_PREFIX)/bin/llvm-ar \
NM=$(BUILD_PREFIX)/bin/llvm-nm \
SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \
default libc_so
$(MAKE) -C $(ROOT_DIR)/src/wasi-libc \
CC=$(BUILD_PREFIX)/bin/clang \
AR=$(BUILD_PREFIX)/bin/llvm-ar \
NM=$(BUILD_PREFIX)/bin/llvm-nm \
SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \
THREAD_MODEL=posix
$(MAKE) $(call WASI_LIBC_MAKEFLAGS,wasm32-wasi) default libc_so
$(MAKE) $(call WASI_LIBC_MAKEFLAGS,wasm32-wasip1) default libc_so
$(MAKE) $(call WASI_LIBC_MAKEFLAGS,wasm32-wasip2) WASI_SNAPSHOT=p2 default libc_so
$(MAKE) $(call WASI_LIBC_MAKEFLAGS,wasm32-wasi-threads) THREAD_MODEL=posix
$(MAKE) $(call WASI_LIBC_MAKEFLAGS,wasm32-wasip1-threads) THREAD_MODEL=posix
touch build/wasi-libc.BUILT

build/compiler-rt.BUILT: build/llvm.BUILT
Expand Down Expand Up @@ -156,11 +152,15 @@ build/compiler-rt.BUILT: build/llvm.BUILT
DESTDIR=$(DESTDIR) ninja $(NINJA_FLAGS) -C build/compiler-rt install
# Install clang-provided headers.
cp -R $(ROOT_DIR)/build/llvm/lib/clang $(BUILD_PREFIX)/lib/
cp -R $(BUILD_PREFIX)/lib/clang/17/lib/wasi $(BUILD_PREFIX)/lib/clang/17/lib/wasip1
cp -R $(BUILD_PREFIX)/lib/clang/17/lib/wasi $(BUILD_PREFIX)/lib/clang/17/lib/wasip2
touch build/compiler-rt.BUILT

# Flags for libcxx and libcxxabi.
# $(1): pthreads ON or OFF
# $(2): shared libraries ON or OFF
# $(3): the name of the target being built for
# $(4): extra compiler flags to pass
LIBCXX_CMAKE_FLAGS = \
-DCMAKE_C_COMPILER_WORKS=ON \
-DCMAKE_CXX_COMPILER_WORKS=ON \
Expand Down Expand Up @@ -199,47 +199,34 @@ LIBCXX_CMAKE_FLAGS = \
-DLIBCXXABI_ENABLE_PIC:BOOL=$(2) \
-DWASI_SDK_PREFIX=$(BUILD_PREFIX) \
-DUNIX:BOOL=ON \
--debug-trycompile
--debug-trycompile \
-DCMAKE_SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \
-DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) $(EXTRA_CFLAGS) $(4) --target=$(3)" \
-DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) $(EXTRA_CXXFLAGS) $(4) --target=$(3)" \
-DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/$(3) \
-DLIBCXXABI_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/$(3) \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
$(LLVM_PROJ_DIR)/runtimes

# Rules to build libcxx, factored out here to deduplicate the below
# $(1): pthreads ON or OFF
# $(2): shared libraries ON or OFF
# $(3): the name of the target being built for
define BUILD_LIBCXX
mkdir -p build/libcxx-$(3)
cd build/libcxx-$(3) && cmake -G Ninja $(call LIBCXX_CMAKE_FLAGS,$(1),$(2),$(3),$(4))
ninja $(NINJA_FLAGS) -C build/libcxx-$(3)
DESTDIR=$(DESTDIR) ninja $(NINJA_FLAGS) -C build/libcxx-$(3) install
rm -rf $(BUILD_PREFIX)/share/wasi-sysroot/include/$(3)/c++
mv $(BUILD_PREFIX)/share/wasi-sysroot/include/c++ $(BUILD_PREFIX)/share/wasi-sysroot/include/$(3)/
endef

build/libcxx.BUILT: build/llvm.BUILT build/wasi-libc.BUILT
# Do the build.
mkdir -p build/libcxx-preview2
cd build/libcxx-preview2 && cmake -G Ninja $(call LIBCXX_CMAKE_FLAGS,OFF,ON) \
-DCMAKE_SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \
-DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) $(EXTRA_CFLAGS) --target=wasm32-wasi-preview2" \
-DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) $(EXTRA_CXXFLAGS) --target=wasm32-wasi-preview2" \
-DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi-preview2 \
-DLIBCXXABI_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi-preview2 \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
$(LLVM_PROJ_DIR)/runtimes
ninja $(NINJA_FLAGS) -C build/libcxx-preview2
mkdir -p build/libcxx
cd build/libcxx && cmake -G Ninja $(call LIBCXX_CMAKE_FLAGS,OFF,ON) \
-DCMAKE_SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \
-DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) $(EXTRA_CFLAGS) --target=wasm32-wasi" \
-DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) $(EXTRA_CXXFLAGS) --target=wasm32-wasi" \
-DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \
-DLIBCXXABI_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
$(LLVM_PROJ_DIR)/runtimes
ninja $(NINJA_FLAGS) -C build/libcxx
mkdir -p build/libcxx-threads
cd build/libcxx-threads && cmake -G Ninja $(call LIBCXX_CMAKE_FLAGS,ON,OFF) \
-DCMAKE_SYSROOT=$(BUILD_PREFIX)/share/wasi-sysroot \
-DCMAKE_C_FLAGS="$(DEBUG_PREFIX_MAP) -pthread $(EXTRA_CFLAGS) --target=wasm32-wasi-threads" \
-DCMAKE_CXX_FLAGS="$(DEBUG_PREFIX_MAP) -pthread $(EXTRA_CXXFLAGS) --target=wasm32-wasi-threads" \
-DLIBCXX_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi-threads \
-DLIBCXXABI_LIBDIR_SUFFIX=$(ESCAPE_SLASH)/wasm32-wasi-threads \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
$(LLVM_PROJ_DIR)/runtimes
ninja $(NINJA_FLAGS) -C build/libcxx-threads
# Do the install.
DESTDIR=$(DESTDIR) ninja $(NINJA_FLAGS) -C build/libcxx-preview2 install
mv $(BUILD_PREFIX)/share/wasi-sysroot/include/c++ $(BUILD_PREFIX)/share/wasi-sysroot/include/wasm32-wasi-preview2/
DESTDIR=$(DESTDIR) ninja $(NINJA_FLAGS) -C build/libcxx install
mv $(BUILD_PREFIX)/share/wasi-sysroot/include/c++ $(BUILD_PREFIX)/share/wasi-sysroot/include/wasm32-wasi/
DESTDIR=$(DESTDIR) ninja $(NINJA_FLAGS) -C build/libcxx-threads install
mv $(BUILD_PREFIX)/share/wasi-sysroot/include/c++ $(BUILD_PREFIX)/share/wasi-sysroot/include/wasm32-wasi-threads/
$(call BUILD_LIBCXX,OFF,ON,wasm32-wasi)
$(call BUILD_LIBCXX,OFF,ON,wasm32-wasip1)
$(call BUILD_LIBCXX,OFF,ON,wasm32-wasip2)
$(call BUILD_LIBCXX,ON,OFF,wasm32-wasi-threads,-pthread)
$(call BUILD_LIBCXX,ON,OFF,wasm32-wasip1-threads,-pthread)
# As of this writing, `clang++` will ignore the above include dirs unless this one also exists:
mkdir -p $(BUILD_PREFIX)/share/wasi-sysroot/include/c++/v1
touch build/libcxx.BUILT
Expand Down
2 changes: 1 addition & 1 deletion tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ echo $CC
echo $CXX
echo "SDK: $wasi_sdk"

for target in wasm32-wasi wasm32-wasi-threads wasm32-wasi-preview2; do
for target in wasm32-wasi wasm32-wasip1 wasm32-wasi-threads wasm32-wasip1-threads wasm32-wasip2; do
echo "===== Testing target $target ====="
cd $testdir/compile-only
for options in -O0 -O2 "-O2 -flto"; do
Expand Down
2 changes: 1 addition & 1 deletion tests/testcase.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ else
file_options=
fi

if [ "$target" == "wasm32-wasi-threads" ]; then
if echo "$target" | grep -q -- '-threads$'; then
pthread_options="-pthread"
else
pthread_options=
Expand Down

0 comments on commit 36499ca

Please sign in to comment.