Skip to content

Commit a25ab11

Browse files
authored
Add support for generating a compile_commands.json for c-dependencies/js-compute-runtime (#91)
* Add support for generating a compile_commands.json for c-dependencies/js-compute-runtime * Move gitignore patterns to c-dependencies/js-compute-runtime * Fix assignment of `MODE` and `CARGO_FLAG` in `else` branch * Use a separate command for invoking `WASM_STRIP` * Mark the `compile_commands.json` target as `.PHONY` * The default WASM_STRIP definition is no longer needed
1 parent bfbd200 commit a25ab11

File tree

2 files changed

+51
-13
lines changed

2 files changed

+51
-13
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# clangd state
2+
/compile_commands.json
3+
/.cache
4+
5+
/rusturl
6+
/compiler_flags
7+
/*.o
8+
/*.d
9+
/*.wasm

c-dependencies/js-compute-runtime/Makefile

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,40 @@ WIZER ?= wizer
33

44
CXX_OPT ?= -O2
55

6-
MODE=release
7-
CARGO_FLAG=--release
86
ifdef DEBUG
9-
MODE=debug
10-
CARGO_FLAG=
7+
MODE := debug
8+
CARGO_FLAG :=
119
CXX_OPT := $(CXX_OPT) -DDEBUG -DJS_DEBUG
10+
Q :=
11+
else
12+
MODE := release
13+
CARGO_FLAG := --release
14+
Q := @
1215
endif
1316

14-
ROOT_SRC?=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/..
15-
SM_SRC=$(ROOT_SRC)/spidermonkey/$(MODE)/
16-
SM_OBJ=$(SM_SRC)lib/*.o
17-
SM_OBJ+=$(SM_SRC)lib/*.a
18-
FSM_SRC=$(ROOT_SRC)/js-compute-runtime/
17+
ROOT_SRC ?= $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/..
18+
SM_SRC := $(ROOT_SRC)/spidermonkey/$(MODE)/
19+
SM_OBJ := $(SM_SRC)lib/*.o
20+
SM_OBJ += $(SM_SRC)lib/*.a
21+
FSM_SRC := $(ROOT_SRC)/js-compute-runtime/
1922

2023
WASI_CXX ?= /opt/wasi-sdk/bin/clang++
2124

2225

2326
CXX_FLAGS := -std=gnu++17 -Wall -Werror -Qunused-arguments -fno-sized-deallocation -fno-aligned-new -mthread-model single -fPIC -fno-rtti -fno-exceptions -fno-math-errno -pipe -fno-omit-frame-pointer -funwind-tables
27+
DEFINES ?=
2428
LD_FLAGS := -Wl,-z,noexecstack -Wl,-z,text -Wl,-z,relro -Wl,-z,nocopyreloc -Wl,-z,stack-size=1048576 -Wl,--stack-first
2529

26-
.PHONY: all
30+
.PHONY: all clean compile_commands.json
2731

2832
all: js-compute-runtime.wasm
2933

3034
compiler_flags:
31-
echo '$(CXX_OPT)' | cmp -s - $@ || echo '$(CXX_OPT)' > $@
35+
echo '$(CXX_OPT) $(CXX_FLAGS)' | cmp -s - $@ || echo '$(CXX_OPT) $(CXX_FLAGS)' > $@
3236

3337
ifeq (,$(findstring g,$(CXX_OPT)))
3438
ifneq (,$(shell which wasm-opt))
35-
WASM_STRIP = wasm-opt --strip-debug -o $@ $@
39+
WASM_STRIP = wasm-opt --strip-debug -o $1 $1
3640
endif
3741
endif
3842

@@ -54,7 +58,32 @@ $(RUST_URL_LIB): $(RUST_URL_RS_FILES) $(RUST_URL_SRC)/Cargo.toml $(RUST_URL_SRC)
5458

5559
js-compute-runtime.wasm: $(FSM_OBJ) $(SM_OBJ) $(RUST_URL_LIB)
5660
$(WASI_CXX) $(CXX_FLAGS) $(CXX_OPT) $(DEFINES) $(LD_FLAGS) -o $@ $^
57-
$(WASM_STRIP)
61+
$(call WASM_STRIP,$@)
5862

5963
initialized-js-compute-runtime.wasm: js-compute-runtime.wasm $(INIT_JS)
6064
cat $(INIT_JS) | $(WIZER) --allow-wasi --dir=. -r _start=wizer.resume -o $@ $<
65+
66+
clean:
67+
$(RM) compile_commands.json $(FSM_OBJ)
68+
69+
distclean: clean
70+
$(RM) $(FSM_DEP) compiler_flags
71+
72+
.PHONY: compile_commands.json
73+
compile_commands.json:
74+
$Q ( \
75+
sep="["; \
76+
for file in $(FSM_CPP); do \
77+
echo "$$sep"; \
78+
sep=","; \
79+
echo "{ \"directory\": \"$(FSM_SRC)\","; \
80+
echo " \"command\": \"$(WASI_CXX) $(CXX_FLAGS) $(DEFINES) -I $(SM_SRC)include\","; \
81+
echo -n " \"file\": \"$$(basename $$file)\"}"; \
82+
done; \
83+
echo; \
84+
echo ']' \
85+
) > "$@"
86+
87+
# Useful for debugging, try `make print-FSM_CPP`
88+
print-%:
89+
$Q echo "$($*)"

0 commit comments

Comments
 (0)