Start renaming preview1 to p1 and preview2 to p2 (#386)

* Start renaming preview1 to p1 and preview2 to p2

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.

* Use $(CLANG_VERSION) instead of hardcoding
pull/388/head
Alex Crichton 10 months ago committed by GitHub
parent f1ebc52a74
commit c2f9c100b0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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
@ -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/$(CLANG_VERSION)/lib/wasi $(BUILD_PREFIX)/lib/clang/$(CLANG_VERSION)/lib/wasip1
cp -R $(BUILD_PREFIX)/lib/clang/$(CLANG_VERSION)/lib/wasi $(BUILD_PREFIX)/lib/clang/$(CLANG_VERSION)/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 \
@ -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

@ -1 +1 @@
Subproject commit cc62fa82c29bfced82d280cbccc231667ee80822
Subproject commit c9c7d0616e0f7fe4d0d0fa54372b6d1f5689f91d

@ -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

@ -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=

Loading…
Cancel
Save