-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
71 lines (48 loc) · 2.18 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Helper makefile for building / testing wasm components
# Default runtime directory, override using env
RUNTIME_DIR?=./target/debug
# Default runtime executor, override using env
RUNTIME_EXEC?=wasmtime
# Build test list
TESTS=$(foreach f,$(wildcard ./spec/tests/*.toml),$(subst .toml,,$(subst ./spec/tests/,,$(f))))
# Build everything
all: runtime build-rs-tests build-as-tests
# Build the linux runtime
runtime:
cargo build -p wasm-embedded-rt
# Run all tests
test: test-rs test-as
### Rust Tests ###
# Helper to execute a rust given test using specified runtime
RS_TEST_DIR?=target/wasm32-wasi/debug
$(RS_TEST_DIR)/test-%.wasm: hal_rs/src/tests/test_%.rs $(wildcard ./hal_rs/src/*.rs)
cd hal_rs && cargo build --features=$(subst .rs,,$(subst hal_rs/src/tests/,,$<))
test-rs-%: $(RS_TEST_DIR)/test-%.wasm
@echo "----------- $(RUNTIME_EXEC)/$@ (config: $(subst test-rs-,,$@).toml) -----------"
$(RUNTIME_DIR)/wasm-embedded-rt --engine mock --runtime $(RUNTIME_EXEC) \
--config ./spec/tests/$(subst test-rs-,,$@).toml \
$(RS_TEST_DIR)/$(subst test-rs-,test-,$@).wasm
# Run all rust tests
test-rs: $(foreach f,$(TESTS),test-rs-$(f))
# Build all rust tests
build-rs-tests: $(foreach f,$(TESTS),$(RS_TEST_DIR)/test-$(f).wasm)
### AssemblyScript Tests ###
# Helper to execute a given assemblyscript test using specified runtime
AS_TEST_DIR?=./hal_as/build
# Build AssemblyScript tests
AS_TEST_SRCS=$(foreach f,$(TESTS),./hal_as/tests/test_$(f).ts)
AS_TEST_BINS := $(foreach f,$(TESTS),./hal_as/build/test-$(f).wasm)
hal_as/build/test-%.wasm: hal_as/tests/test_%.ts $(wildcard ./hal_as/assembly/*.ts)
cd hal_as/ && npm exec asc -- ../$< -o ../$@
# Run specific assemblyscript test
test-as-%: hal_as/build/test-%.wasm
@echo "Running $@ (config: $(subst test-as-,,$@).toml)"
@echo ----------- wasmtime -----------
$(RUNTIME_DIR)/wasm-embedded-rt --engine mock --runtime $(RUNTIME_EXEC) \
--config ./spec/tests/$(subst test-as-,,$@).toml \
$(AS_TEST_DIR)/$(subst test-as-,test-,$@).wasm
# Run all assemblyscript tests
test-as: $(foreach f,$(TESTS),test-as-$(f))
# Build all assemblyscript tests
build-as-tests: $(foreach f,$(TESTS),hal_as/build/test-$(f).wasm)
.PHONY: build-rs-tests build-as-tests