Skip to content

Commit da7f96b

Browse files
committed
Use new compiler-rt logic for testing
1 parent cb3543a commit da7f96b

File tree

3 files changed

+15
-25
lines changed

3 files changed

+15
-25
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -157,21 +157,7 @@ jobs:
157157
158158
- name: Test
159159
if: matrix.test
160-
# For Clang linking to work correctly, we need to place Clang's runtime
161-
# library for `wasm32-wasi` in the right location (i.e., the `mkdir` and
162-
# `cp` below).
163-
run: |
164-
cd test
165-
mkdir resource-dir
166-
export WASI_DIR=./resource-dir/lib/wasi/
167-
export WASIP1_DIR=./resource-dir/lib/wasip1/
168-
export WASIP2_DIR=./resource-dir/lib/wasip2/
169-
mkdir -p $WASI_DIR $WASIP1_DIR $WASIP2_DIR
170-
cp build/download/libclang_rt.builtins-wasm32.a $WASI_DIR
171-
cp build/download/libclang_rt.builtins-wasm32.a $WASIP1_DIR
172-
cp build/download/libclang_rt.builtins-wasm32.a $WASIP2_DIR
173-
export LDFLAGS="-resource-dir $(pwd)/resource-dir"
174-
make test
160+
run: make -C test test
175161

176162
- uses: actions/[email protected]
177163
if: matrix.upload

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,8 @@ $(BUILTINS_LIB_PATH):
597597
fi
598598
endif
599599

600+
builtins: $(BUILTINS_LIB_PATH)
601+
600602
# TODO: Specify SDK version, e.g. libc.so.wasi-sdk-21, as SO_NAME once `wasm-ld`
601603
# supports it.
602604
#

test/Makefile

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ $(SYSROOT):
3535

3636
LIBC_TEST_URL ?= https://github.com/bytecodealliance/libc-test
3737
LIBC_TEST = $(DOWNDIR)/libc-test
38-
LIBRT_URL ?= https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-25/libclang_rt.builtins-wasm32-wasi-25.0.tar.gz
39-
LIBRT = $(DOWNDIR)/libclang_rt.builtins-wasm32.a
4038
ARCH := $(shell uname -m)
4139
WASMTIME_URL ?= https://github.com/bytecodealliance/wasmtime/releases/download/v29.0.1/wasmtime-v29.0.1-$(ARCH)-linux.tar.xz
4240
WASMTIME = $(abspath $(DOWNDIR)/$(shell basename $(WASMTIME_URL) .tar.xz)/wasmtime)
@@ -51,12 +49,6 @@ $(DOWNDIR):
5149
$(LIBC_TEST): | $(DOWNDIR)
5250
git clone --depth 1 $(LIBC_TEST_URL) $@
5351

54-
# TODO: add install target to copy builtins library directly into a Clang
55-
# installation.
56-
$(LIBRT): | $(DOWNDIR)
57-
wget --no-clobber --directory-prefix=$(DOWNDIR) $(LIBRT_URL)
58-
tar --extract --file=$(DOWNDIR)/$(shell basename $(LIBRT_URL)) --strip-components=1 --directory=$(DOWNDIR)/
59-
6052
$(WASMTIME): | $(DOWNDIR)
6153
wget --no-clobber --directory-prefix=$(DOWNDIR) $(WASMTIME_URL)
6254
tar --extract --file=$(DOWNDIR)/$(shell basename $(WASMTIME_URL)) --directory=$(DOWNDIR)/
@@ -69,7 +61,7 @@ $(ADAPTER): | $(DOWNDIR)
6961
wget --no-clobber --directory-prefix=$(DOWNDIR) $(ADAPTER_URL)
7062

7163
# Target to download all necessary dependencies.
72-
TO_DOWNLOAD = $(LIBC_TEST) $(LIBRT) $(WASMTIME)
64+
TO_DOWNLOAD = $(LIBC_TEST) $(WASMTIME)
7365
ifeq ($(TARGET_TRIPLE), wasm32-wasip2)
7466
TO_DOWNLOAD += $(ADAPTER) $(WASM_TOOLS)
7567
endif
@@ -133,6 +125,16 @@ ifneq ($(findstring -threads,$(TARGET_TRIPLE)),)
133125
CFLAGS += -pthread
134126
endif
135127

128+
# Handle compiler-rt which is required for tests. This is done by requesting
129+
# that the parent directory, the main wasi-libc directory, fetch its compiler-rt
130+
# which will create a `resource-dir` argument which we can then add to LDFLAGS
131+
# which gets fed down below into the actual linking of wasms.
132+
LDFLAGS += -resource-dir ../build/$(TARGET_TRIPLE)/resource-dir
133+
BUILTINS_STAMP := $(OBJDIR)/builtins.stamp
134+
$(BUILTINS_STAMP):
135+
make -C .. builtins
136+
touch $@
137+
136138
# Build up all the `*.wasm.o` object files; these are the same regardless of
137139
# whether we're building core modules or components.
138140
$(WASM_OBJS): $(INFRA_HEADERS)
@@ -142,7 +144,7 @@ $(OBJDIR)/%.wasm.o: $(SRCDIR)/%.c $(DOWNLOADED) $(SYSROOT)
142144

143145
# Build up all the `*.wasm` files.
144146
obj_to_c = $(patsubst $(OBJDIR)/%.wasm.o,$(SRCDIR)/%.c,$1)
145-
$(OBJDIR)/%.core.wasm: $(OBJDIR)/%.wasm.o $(INFRA_WASM_OBJS)
147+
$(OBJDIR)/%.core.wasm: $(OBJDIR)/%.wasm.o $(INFRA_WASM_OBJS) $(BUILTINS_STAMP)
146148
@mkdir -p $(@D)
147149
$(CC) $(CFLAGS) $(LDFLAGS) $(shell scripts/add-flags.py LDFLAGS $(call obj_to_c,$<)) $^ -o $@
148150

0 commit comments

Comments
 (0)