-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
106 lines (87 loc) · 4.2 KB
/
Makefile
File metadata and controls
106 lines (87 loc) · 4.2 KB
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
export RUST_BACKTRACE ?= 1
export WASMTIME_BACKTRACE_DETAILS ?= 1
WASMTIME_RUN_FLAGS ?= -Sinherit-network -Sallow-ip-name-lookup
.PHONY: all
all: components
.PHONY: clean
clean:
cargo clean
rm -rf lib/*.wasm
rm -rf lib/*.wasm.md
.PHONY: run
run: lib/cli.debug.wasm
@wasmtime run $(WASMTIME_RUN_FLAGS) lib/cli.debug.wasm $(cmd)
.PHONY: components
components: lib/interface.wasm lib/cli.wasm lib/cli.debug.wasm lib/keyvalue-to-valkey.wasm lib/keyvalue-to-valkey.debug.wasm lib/valkey-client.wasm lib/valkey-client.debug.wasm lib/valkey-ops.wasm lib/valkey-ops.debug.wasm lib/sample-http-incrementor.wasm lib/sample-http-incrementor.debug.wasm
lib/interface.wasm: wit/deps README.md
wkg wit build -o lib/interface.wasm
cp README.md lib/interface.wasm.md
define BUILD_COMPONENT
# $1 - component
# $2 - release target
# $3 - release target deps
# $4 - debug target deps
lib/$1.wasm: $3 Cargo.toml Cargo.lock components/wit/deps $(shell find components/wit -type f) $(shell find components/$1 -type f)
cargo component build -p $1 --target $2 --release
$(if $(findstring $1,cli),
wac plug target/$2/release/$(subst -,_,$1).wasm --plug lib/valkey-ops.wasm -o lib/$1.wasm,
cp target/$2/release/$(subst -,_,$1).wasm lib/$1.wasm)
cp components/$1/README.md lib/$1.wasm.md
lib/$1.debug.wasm: $4 Cargo.toml Cargo.lock wit/deps $(shell find components/$1 -type f)
cargo component build -p $1 --target wasm32-wasip2
$(if $(findstring $1,cli),
wac plug target/$2/debug/$(subst -,_,$1).wasm --plug lib/valkey-ops.debug.wasm -o lib/$1.debug.wasm,
cp target/wasm32-wasip2/debug/$(subst -,_,$1).wasm lib/$1.debug.wasm)
cp components/$1/README.md lib/$1.debug.wasm.md
endef
$(eval $(call BUILD_COMPONENT,valkey-ops,wasm32-unknown-unknown))
$(eval $(call BUILD_COMPONENT,keyvalue-to-valkey,wasm32-unknown-unknown))
$(eval $(call BUILD_COMPONENT,cli,wasm32-wasip2,lib/valkey-ops.wasm,lib/valkey-ops.debug.wasm))
$(eval $(call BUILD_COMPONENT,sample-http-incrementor,wasm32-unknown-unknown))
lib/valkey-client.wasm: components/valkey-client.wac lib/valkey-ops.wasm lib/keyvalue-to-valkey.wasm
wac compose -o lib/valkey-client.wasm \
-d componentized:valkey-ops=./lib/valkey-ops.wasm \
-d componentized:keyvalue-to-valkey=./lib/keyvalue-to-valkey.wasm \
components/valkey-client.wac
cp README.md lib/valkey-client.wasm.md
lib/valkey-client.debug.wasm: components/valkey-client.wac lib/valkey-ops.debug.wasm lib/keyvalue-to-valkey.debug.wasm
wac compose -o lib/valkey-client.debug.wasm \
-d componentized:valkey-ops=./lib/valkey-ops.debug.wasm \
-d componentized:keyvalue-to-valkey=./lib/keyvalue-to-valkey.debug.wasm \
components/valkey-client.wac
cp README.md lib/valkey-client.debug.wasm.md
.PHONY: wit
wit: wit/deps components/wit/deps
wit/deps: wkg.toml $(shell find wit -type f -name "*.wit" -not -path "deps")
wkg wit fetch
components/wit/deps: wit/deps components/wkg.toml $(shell find components/wit -type f -name "*.wit" -not -path "deps")
(cd components && wkg wit fetch)
# TODO remove once wkg consumes wit-component 0.245
perl -pi -e 's/ map\(/ %map\(/g' components/wit/deps/componentized-valkey/package.wit
.PHONY: test
test:
@$(MAKE) run cmd="hello"
.PHONY: publish
publish: $(shell find lib -type f -name "*.wasm" | sed -e 's:^lib/:publish-:g')
.PHONY: publish-%
publish-%:
ifndef VERSION
$(error VERSION is undefined)
endif
ifndef REPOSITORY
$(error REPOSITORY is undefined)
endif
@$(eval FILE := $(@:publish-%=%))
@$(eval COMPONENT := $(FILE:%.wasm=%))
@$(eval DESCRIPTION := $(shell head -n 3 "lib/${FILE}.md" | tail -n 1))
@$(eval REVISION := $(shell git rev-parse HEAD)$(shell git diff --quiet HEAD && echo "+dirty"))
@$(eval TAG := $(shell echo "${VERSION}" | sed 's/[^a-zA-Z0-9_.\-]/--/g'))
wkg oci push \
--annotation "org.opencontainers.image.title=${COMPONENT}" \
--annotation "org.opencontainers.image.description=${DESCRIPTION}" \
--annotation "org.opencontainers.image.version=${VERSION}" \
--annotation "org.opencontainers.image.source=https://github.com/componentized/valkey.git" \
--annotation "org.opencontainers.image.revision=${REVISION}" \
--annotation "org.opencontainers.image.licenses=Apache-2.0" \
"${REPOSITORY}/${COMPONENT}:${TAG}" \
"lib/${FILE}"