Skip to content

Commit

Permalink
fix: compile wasm32-wasip2 target correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
abrown committed Nov 23, 2024
1 parent 86bb7a1 commit 0626461
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,14 @@ $(INFRA_HEADERS): $(DOWNLOADED)
# the $(WASMS) tests.
ALL_TESTS := $(shell find $(SRCDIR) -name '*.c')
TESTS := $(shell TARGET_TRIPLE=$(TARGET_TRIPLE) scripts/filter.py $(ALL_TESTS))
WASMS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.core.wasm)
WASM_OBJS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.wasm.o)
WASM_OBJS += $(INFRA_WASM_OBJS)
ifeq ($(TARGET_TRIPLE), wasm32-wasip2)
WASMS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.component.wasm)
else
WASMS := $(TESTS:$(SRCDIR)/%.c=$(OBJDIR)/%.core.wasm)
endif


# Setup the compiler. We allow $(CC) to be set from the command line; ?= doesn't
# work for CC because make has a default value for it.
Expand All @@ -135,18 +140,15 @@ $(OBJDIR)/%.wasm.o: $(SRCDIR)/%.c $(DOWNLOADED) $(SYSROOT)
$(CC) $(CFLAGS) $(shell scripts/add-flags.py CFLAGS $<) -c $< -o $@

# Build up all the `*.wasm` files.
#$(WASMS): $(WASM_OBJS)
obj_to_c = $(patsubst $(OBJDIR)/%.wasm.o,$(SRCDIR)/%.c,$1)
$(OBJDIR)/%.core.wasm: $(OBJDIR)/%.wasm.o $(INFRA_WASM_OBJS)
@mkdir -p $(@D)
$(CC) $(CFLAGS) $(LDFLAGS) $(shell scripts/add-flags.py LDFLAGS $(call obj_to_c,$<)) $^ -o $@

# For wasip2, we include an additional step to wrap up the core module into
# a component.
ifeq ($(TARGET_TRIPLE), wasm32-wasip2)
$(OBJDIR)/%.component.wasm: $(OBJDIR)/%.core.wasm
$(WASM_TOOLS) component new --adapt $(ADAPTER) $< -o $@
endif

# Compile each selected test using Clang. Note that failures here are likely
# due to a missing `libclang_rt.builtins-wasm32.a` in the Clang lib directory.
Expand Down Expand Up @@ -175,7 +177,7 @@ generate-stubs:
ENGINE ?= $(WASMTIME) run
ifeq ($(TARGET_TRIPLE), wasm32-wasip2)
ENGINE += --wasm component-model
OBJPAT := $(OBJDIR)%.component.wasm
OBJPAT := $(OBJDIR)/%.component.wasm
else
OBJPAT := $(OBJDIR)/%.core.wasm
endif
Expand All @@ -184,7 +186,7 @@ endif
# script and an `output.log` file (see `scripts/run-test.sh` for details). The
# `success` file is never generated, which means the test will rerun every time.
# To ignore a test temporarily, `touch .../success:`.
RUNTESTS:=$(WASMS:$(OBJDIR)%.core.wasm=$(RUNDIR)%.c/success)
RUNTESTS:=$(WASMS:$(OBJPAT)=$(RUNDIR)/%/success)
wasm_to_c = $(patsubst $(OBJPAT),$(SRCDIR)/%.c,$1)
$(RUNDIR)/%.c/success: $(OBJPAT)
@mkdir -p $(@D)
Expand Down

0 comments on commit 0626461

Please sign in to comment.