Skip to content

Commit fe065b7

Browse files
authored
Wrap wasm-opt to prevent clang from running while linking (#350)
Clang now runs wasm-opt automatically if it's present in the path when linking wasm artifacts. For debug builds on osx this produces a bus error, it's also not clear that we want wasm-opt -O2 applied to our debug artifacts. This PR introduces a script named wasm-opt that immediately exits successfully, and adds it to the PATH when linking the runtime. This prevents clang from running the real wasm-opt, and gives us more control over what optimizations are enabled when we do choose to run it.
1 parent 1182938 commit fe065b7

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

c-dependencies/js-compute-runtime/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,16 @@ $(OBJ_DIR)xqd-world/xqd_world_adapter.o: $(FSM_SRC)xqd-world/xqd_world_adapter.c
9494
$(OBJ_DIR)xqd-world/xqd_world_adapter_component.o: $(FSM_SRC)xqd-world/xqd_world_adapter.cpp $(FSM_SRC)Makefile compiler_flags
9595
$(WASI_CXX) $(CXX_FLAGS) $(CXX_OPT) $(DEFINES) -DCOMPONENT -I $(SM_SRC)include -MMD -MP -c -o $@ $<
9696

97+
# NOTE: we shadow wasm-opt by adding $(FSM_SRC)/scripts to the path, which
98+
# includes a script called wasm-opt that immediately exits successfully. See
99+
# that script for more information about why we do this.
100+
97101
js-compute-runtime.wasm: $(FSM_OBJ) $(SM_OBJ) $(OBJ_DIR)xqd-world/xqd_world.o $(OBJ_DIR)xqd-world/xqd_world_adapter.o $(RUST_URL_LIB)
98-
$(WASI_CXX) $(CXX_FLAGS) $(CXX_OPT) $(DEFINES) $(LD_FLAGS) -o $@ $^
102+
PATH="$(FSM_SRC)/scripts:$$PATH" $(WASI_CXX) $(CXX_FLAGS) $(CXX_OPT) $(DEFINES) $(LD_FLAGS) -o $@ $^
99103
$(call WASM_STRIP,$@)
100104

101105
js-compute-runtime-component.wasm: $(FSM_OBJ) $(OBJ_DIR)xqd-world/xqd_world.o $(OBJ_DIR)xqd-world/xqd_world_adapter_component.o $(SM_OBJ) $(RUST_URL_LIB)
102-
$(WASI_CXX) $(CXX_FLAGS) $(CXX_OPT) $(DEFINES) $(LD_FLAGS) -o $@ $^
106+
PATH="$(FSM_SRC)/scripts:$$PATH" $(WASI_CXX) $(CXX_FLAGS) $(CXX_OPT) $(DEFINES) $(LD_FLAGS) -o $@ $^
103107
$(call WASM_STRIP,$@)
104108

105109
install: js-compute-runtime.wasm
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
# We use this script to hide wasm-opt from clang, which will unconditionally run
4+
# wasm-opt when linking if it's discovered in your path. We'd like tighter
5+
# control over if wasm-opt is run at all, and this script makes it a concrete
6+
# choice in our build system instead.

0 commit comments

Comments
 (0)