From b2d5b3c5b203e23b4e5e92942cc92998d65808c4 Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Tue, 22 Jul 2025 12:27:13 -0700 Subject: [PATCH] Fix build and tests for wasm32-wasip2 target and upgrade clang - Fix setting of TARGET_TRIPLE in Makefile when WASI_SNAPSHOT or THREAD_MODEL is set - Run `make builtins` by default - Fix paths used when running `make builtins` on Windows - When building wasip2 tests, pass --skip-wit-component flag to linker in first step (when building the core module) - Upgrade clang to version 19 (20 on Windows as the installer for 19 didn't seem to include wasm targets) - Download wasm-component-ld when building for Linux --- .github/actions/setup/action.yml | 6 +++++ .github/workflows/main.yml | 36 +++++++++++++----------------- Makefile | 38 ++++++++++++++++++-------------- test/Makefile | 16 ++++++++++++++ 4 files changed, 59 insertions(+), 37 deletions(-) diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index d56dc9190..05090de3a 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -57,4 +57,10 @@ runs: echo "CC=clang-$v" >> $GITHUB_ENV echo "AR=llvm-ar-$v" >> $GITHUB_ENV echo "NM=llvm-nm-$v" >> $GITHUB_ENV + # Note: wasm-component-ld is only needed for Linux because + # currently, wasm32-wasip2 is only tested on Linux. If that changes, + # this step will have to be added to the other targets. + curl -fsSLO https://github.com/bytecodealliance/wasm-component-ld/releases/download/v0.5.15/wasm-component-ld-v0.5.15-x86_64-linux.tar.gz + tar xzf wasm-component-ld-v0.5.15-x86_64-linux.tar.gz + echo "$(pwd)/wasm-component-ld-v0.5.15-x86_64-linux" >> $GITHUB_PATH if: runner.os == 'Linux' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2fea10ecb..755cadcbc 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -22,12 +22,12 @@ jobs: # wasi-libc builds on these platforms by default. - name: Build on Linux x86_64 os: ubuntu-24.04 - clang_version: 16 - upload: linux-x86_64-clang-16 + clang_version: 19 + upload: linux-x86_64-clang-19 - name: Build on Linux aarch64 os: ubuntu-24.04-arm - clang_version: 16 - upload: linux-aarch64-clang-16 + clang_version: 19 + upload: linux-aarch64-clang-19 - name: Build on macOS aarch64 os: macos-15 clang_version: 15.0.7 @@ -35,8 +35,8 @@ jobs: upload: macos-clang-15 - name: Build on Windows x86_64 os: windows-2025 - clang_version: 16.0.0 - upload: windows-clang-16 + clang_version: 20.1.8 + upload: windows-clang-20 # Other versions of LLVM - name: Build with LLVM 11 @@ -45,12 +45,6 @@ jobs: upload: linux-x86_64-clang-11 env: BUILD_LIBSETJMP: no - - name: Build with LLVM 19 - os: ubuntu-24.04 - clang_version: 19 - upload: linux-x86_64-clang-19 - env: - MAKE_TARGETS: "default libc_so" - name: Build with LLVM 18 os: ubuntu-24.04 clang_version: 18 @@ -58,7 +52,7 @@ jobs: env: MAKE_TARGETS: "default libc_so" - # Test various combinations of targets triples. + # Test various combinations of target triples. # # Configuration here can happen through `env` which is inherited to # jobs below. For now this only runs tests on Linux with Clang 16, @@ -67,7 +61,7 @@ jobs: # ensure the PIC build works. - name: Test wasm32-wasi os: ubuntu-24.04 - clang_version: 16 + clang_version: 19 test: true upload: wasm32-wasi env: @@ -75,7 +69,7 @@ jobs: MAKE_TARGETS: "default libc_so" - name: Test wasm32-wasip1 os: ubuntu-24.04 - clang_version: 16 + clang_version: 19 test: true upload: wasm32-wasip1 env: @@ -83,7 +77,7 @@ jobs: MAKE_TARGETS: "default libc_so" - name: Test wasm32-wasip2 os: ubuntu-24.04 - clang_version: 16 + clang_version: 19 test: true upload: wasm32-wasip2 env: @@ -92,7 +86,7 @@ jobs: MAKE_TARGETS: "default libc_so" - name: Test wasm32-wasi-threads os: ubuntu-24.04 - clang_version: 16 + clang_version: 19 test: true upload: wasm32-wasi-threads env: @@ -100,7 +94,7 @@ jobs: THREAD_MODEL: posix - name: Test wasm32-wasip1-threads os: ubuntu-24.04 - clang_version: 16 + clang_version: 19 test: true upload: wasm32-wasip1-threads env: @@ -108,14 +102,14 @@ jobs: THREAD_MODEL: posix - name: Test wasm32-wasip1 in V8 os: ubuntu-24.04 - clang_version: 16 + clang_version: 19 test: true test_with_v8: true env: TARGET_TRIPLE: wasm32-wasip1 - name: Test wasm32-wasip1-threads in V8 os: ubuntu-24.04 - clang_version: 16 + clang_version: 19 test: true test_with_v8: true env: @@ -124,7 +118,7 @@ jobs: - name: Test wasm32-wasi-simd os: ubuntu-24.04 - clang_version: 16 + clang_version: 19 test: true upload: wasm32-wasi-simd env: diff --git a/Makefile b/Makefile index 26bdcfa9b..19145f7ea 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,20 @@ MALLOC_IMPL ?= dlmalloc BUILD_LIBC_TOP_HALF ?= yes # yes or no BUILD_LIBSETJMP ?= yes + +# Set the default WASI target triple. +TARGET_TRIPLE ?= wasm32-wasi + +# Threaded version necessitates a different target, as objects from different +# targets can't be mixed together while linking. +ifeq ($(THREAD_MODEL), posix) +TARGET_TRIPLE = wasm32-wasip1-threads +endif + +ifeq ($(WASI_SNAPSHOT), p2) +TARGET_TRIPLE = wasm32-wasip2 +endif + # The directory where we will store intermediate artifacts. OBJDIR ?= build/$(TARGET_TRIPLE) @@ -46,19 +60,6 @@ BULK_MEMORY_THRESHOLD ?= 32 # Variables from this point on are not meant to be overridable via the # make command-line. -# Set the default WASI target triple. -TARGET_TRIPLE ?= wasm32-wasi - -# Threaded version necessitates a different target, as objects from different -# targets can't be mixed together while linking. -ifeq ($(THREAD_MODEL), posix) -TARGET_TRIPLE ?= wasm32-wasi-threads -endif - -ifeq ($(WASI_SNAPSHOT), p2) -TARGET_TRIPLE ?= wasm32-wasip2 -endif - # These artifacts are "stamps" that we use to mark that some task (e.g., copying # files) has been completed. INCLUDE_DIRS := $(OBJDIR)/copy-include-headers.stamp @@ -596,7 +597,9 @@ PIC_OBJS = \ # exists that should be used instead. SYSTEM_BUILTINS_LIB := $(shell ${CC} ${CFLAGS} --print-libgcc-file-name) SYSTEM_RESOURCE_DIR := $(shell ${CC} ${CFLAGS} -print-resource-dir) -BUILTINS_LIB_REL := $(subst $(SYSTEM_RESOURCE_DIR),,$(SYSTEM_BUILTINS_LIB)) +BUILTINS_LIB_REL_1 := $(subst $(SYSTEM_RESOURCE_DIR),,$(SYSTEM_BUILTINS_LIB)) +# Substitute '/' for '\' so Windows paths work +BUILTINS_LIB_REL := $(subst \,/,$(BUILTINS_LIB_REL_1)) TMP_RESOURCE_DIR := $(OBJDIR)/resource-dir BUILTINS_LIB_PATH := $(TMP_RESOURCE_DIR)/$(BUILTINS_LIB_REL) BUILTINS_LIB_DIR := $(dir $(BUILTINS_LIB_PATH)) @@ -610,7 +613,10 @@ else BUILTINS_URL := https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/libclang_rt.builtins-wasm32-wasi-25.0.tar.gz $(BUILTINS_LIB_PATH): - mkdir -p $(BUILTINS_LIB_DIR) +# mkdir on Windows will error if the directory already exists +ifeq ("$(wildcard $(BUILTINS_LIB_DIR))","") + mkdir -p "$(BUILTINS_LIB_DIR)" +endif curl -sSfL $(BUILTINS_URL) | \ tar xzf - -C $(BUILTINS_LIB_DIR) --strip-components 1 if [ ! -f $(BUILTINS_LIB_PATH) ]; then \ @@ -850,7 +856,7 @@ STATIC_LIBS += \ $(SYSROOT_LIB)/libsetjmp.a endif -libc: $(INCLUDE_DIRS) $(STATIC_LIBS) +libc: $(INCLUDE_DIRS) $(STATIC_LIBS) builtins DUMMY := m rt pthread crypt util xnet resolv DUMMY_LIBS := $(patsubst %,$(SYSROOT_LIB)/lib%.a,$(DUMMY)) diff --git a/test/Makefile b/test/Makefile index 4aff0ab9f..b84ebf3de 100644 --- a/test/Makefile +++ b/test/Makefile @@ -14,6 +14,15 @@ test: run # Decide which target to build for and which libc to use. TARGET_TRIPLE ?= wasm32-wasi +# See comment in ../Makefile +ifeq ($(THREAD_MODEL), posix) +TARGET_TRIPLE = wasm32-wasip1-threads +endif + +ifeq ($(WASI_SNAPSHOT), p2) +TARGET_TRIPLE = wasm32-wasip2 +endif + # Setup various paths used by the tests. OBJDIR ?= build/$(TARGET_TRIPLE) DOWNDIR ?= build/download @@ -135,6 +144,13 @@ $(BUILTINS_STAMP): make -C .. builtins touch $@ +# For wasip2, we want clang to generate a core module rather than a component, +# because `wasm-tools component new` is called subsequently and it expects +# a core module. +ifeq ($(TARGET_TRIPLE), wasm32-wasip2) +LDFLAGS += -Wl,--skip-wit-component +endif + # Build up all the `*.wasm.o` object files; these are the same regardless of # whether we're building core modules or components. $(WASM_OBJS): $(INFRA_HEADERS)