forked from fermyon/spin-go-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
130 lines (108 loc) · 5.33 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
VERSION = 2.3.0-pre0
# ----------------------------------------------------------------------
# Test
# ----------------------------------------------------------------------
.PHONY: test
test: test-integration
tinygo test -target=wasi -gc=leaking -v ./http
tinygo test -target=wasi -gc=leaking -v ./redis
.PHONY: test-integration
test-integration: http/testdata/http-tinygo/main.wasm
go test -v -count=1 .
http/testdata/http-tinygo/main.wasm: generate
http/testdata/http-tinygo/main.wasm: http/testdata/http-tinygo/main.go
tinygo build -target=wasi -gc=leaking -no-debug -o http/testdata/http-tinygo/main.wasm http/testdata/http-tinygo/main.go
# ----------------------------------------------------------------------
# Build examples
# ----------------------------------------------------------------------
EXAMPLES_DIR = examples
.PHONY: build-examples
build-examples: generate
build-examples: $(EXAMPLES_DIR)/http-tinygo-outbound-http/outbound-http-to-same-app/main.wasm
build-examples: $(EXAMPLES_DIR)/http-tinygo-outbound-http/tinygo-hello/main.wasm
build-examples: $(EXAMPLES_DIR)/http-tinygo/main.wasm
build-examples: $(EXAMPLES_DIR)/tinygo-outbound-redis/main.wasm
build-examples: $(EXAMPLES_DIR)/tinygo-redis/main.wasm
build-examples: $(EXAMPLES_DIR)/tinygo-key-value/main.wasm
build-examples: $(EXAMPLES_DIR)/tinygo-sqlite/main.wasm
build-examples: $(EXAMPLES_DIR)/tinygo-llm/main.wasm
build-examples: $(EXAMPLES_DIR)/tinygo-outbound-mysql/main.wasm
build-examples: $(EXAMPLES_DIR)/tinygo-outbound-pg/main.wasm
build-examples: $(EXAMPLES_DIR)/variables-tinygo/main.wasm
$(EXAMPLES_DIR)/%/main.wasm: $(EXAMPLES_DIR)/%/main.go
tinygo build -target=wasi -gc=leaking -no-debug -o $@ $<
# ----------------------------------------------------------------------
# Generate C bindings
# ----------------------------------------------------------------------
GENERATED_SPIN_VARIABLES = variables/spin-config.c variables/spin-config.h
GENERATED_OUTBOUND_HTTP = http/wasi-outbound-http.c http/wasi-outbound-http.h
GENERATED_SPIN_HTTP = http/spin-http.c http/spin-http.h
GENERATED_OUTBOUND_REDIS = redis/outbound-redis.c redis/outbound-redis.h
GENERATED_SPIN_REDIS = redis/spin-redis.c redis/spin-redis.h
GENERATED_KEY_VALUE = kv/key-value.c kv/key-value.h
GENERATED_SQLITE = sqlite/sqlite.c sqlite/sqlite.h
GENERATED_LLM = llm/llm.c llm/llm.h
GENERATED_OUTBOUND_MYSQL = mysql/outbound-mysql.c mysql/outbound-mysql.h
GENERATED_OUTBOUND_PG = pg/outbound-pg.c pg/outbound-pg.h
SDK_VERSION_SOURCE_FILE = sdk_version/sdk-version-go-template.c
# NOTE: Please update this list if you add a new directory to the SDK:
SDK_VERSION_DEST_FILES = variables/sdk-version-go.c http/sdk-version-go.c \
kv/sdk-version-go.c redis/sdk-version-go.c \
sqlite/sdk-version-go.c llm/sdk-version-go.c
# NOTE: To generate the C bindings you need to install a forked version of wit-bindgen.
#
# cargo install wit-bindgen-cli --git https://github.com/fermyon/wit-bindgen-backport --rev "b89d5079ba5b07b319631a1b191d2139f126c976"
#
.PHONY: generate
generate: $(GENERATED_OUTBOUND_HTTP) $(GENERATED_SPIN_HTTP)
generate: $(GENERATED_OUTBOUND_REDIS) $(GENERATED_SPIN_REDIS)
generate: $(GENERATED_SPIN_VARIABLES) $(GENERATED_KEY_VALUE)
generate: $(GENERATED_SQLITE) $(GENERATED_LLM)
generate: $(GENERATED_OUTBOUND_MYSQL) $(GENERATED_OUTBOUND_PG)
generate: $(SDK_VERSION_DEST_FILES)
$(SDK_VERSION_DEST_FILES): $(SDK_VERSION_SOURCE_FILE)
export commit="$$(git rev-parse HEAD)"; \
sed -e "s/{{VERSION}}/${VERSION}/" -e "s/{{COMMIT}}/$${commit}/" < $< > $@
$(GENERATED_SPIN_VARIABLES):
wit-bindgen c --import wit/spin-config.wit --out-dir ./variables
$(GENERATED_OUTBOUND_HTTP):
wit-bindgen c --import wit/wasi-outbound-http.wit --out-dir ./http
$(GENERATED_SPIN_HTTP):
wit-bindgen c --export wit/spin-http.wit --out-dir ./http
$(GENERATED_OUTBOUND_REDIS):
wit-bindgen c --import wit/outbound-redis.wit --out-dir ./redis
$(GENERATED_SPIN_REDIS):
wit-bindgen c --export wit/spin-redis.wit --out-dir ./redis
$(GENERATED_KEY_VALUE):
wit-bindgen c --import wit/key-value.wit --out-dir ./kv
$(GENERATED_SQLITE):
wit-bindgen c --import wit/sqlite.wit --out-dir ./sqlite
$(GENERATED_LLM):
wit-bindgen c --import wit/llm.wit --out-dir ./llm
$(GENERATED_OUTBOUND_MYSQL):
wit-bindgen c --import wit/outbound-mysql.wit --out-dir ./mysql
$(GENERATED_OUTBOUND_PG):
wit-bindgen c --import wit/outbound-pg.wit --out-dir ./pg
# ----------------------------------------------------------------------
# Cleanup
# ----------------------------------------------------------------------
.PHONY: clean
clean:
rm -f $(GENERATED_SPIN_CONFIG)
rm -f $(GENERATED_OUTBOUND_HTTP) $(GENERATED_SPIN_HTTP)
rm -f $(GENERATED_OUTBOUND_REDIS) $(GENERATED_SPIN_REDIS)
rm -f $(GENERATED_KEY_VALUE) $(GENERATED_SQLITE)
rm -f $(GENERATED_LLM)
rm -f $(GENERATED_OUTBOUND_MYSQL)
rm -f $(GENERATED_SDK_VERSION)
rm -f http/testdata/http-tinygo/main.wasm
rm -f $(EXAMPLES_DIR)/http-tinygo/main.wasm
rm -f $(EXAMPLES_DIR)/http-tinygo-outbound-http/main.wasm
rm -f $(EXAMPLES_DIR)/tinygo-outbound-redis/main.wasm
rm -f $(EXAMPLES_DIR)/tinygo-redis/main.wasm
rm -f $(EXAMPLES_DIR)/tinygo-key-value/main.wasm
rm -f $(EXAMPLES_DIR)/tinygo-sqlite/main.wasm
rm -f $(EXAMPLES_DIR)/tinygo-llm/main.wasm
rm -f $(EXAMPLES_DIR)/tinygo-outbound-mysql/main.wasm
rm -f $(EXAMPLES_DIR)/tinygo-outbound-pg/main.wasm
rm -f $(SDK_VERSION_DEST_FILES)