-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
68 lines (52 loc) · 2.19 KB
/
Makefile
File metadata and controls
68 lines (52 loc) · 2.19 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
SHELL := /bin/bash
export RUST_BACKTRACE ?= 1
export WASMTIME_BACKTRACE_DETAILS ?= 1
COMPONENTS = $(shell ls -1 components)
.PHONY: all
all: components
.PHONY: clean
clean:
cargo clean
rm -rf lib/*.wasm
rm -rf lib/*.wasm.md
.PHONY: components
components: $(foreach component,$(COMPONENTS),lib/$(component).wasm $(foreach component,$(COMPONENTS),lib/$(component).debug.wasm))
define BUILD_COMPONENT
lib/$1.wasm: Cargo.toml Cargo.lock wit/deps $(shell find components/$1 -type f)
cargo component build -p $1 --target wasm32-unknown-unknown --release
cp target/wasm32-unknown-unknown/release/$(subst -,_,$1).wasm lib/$1.wasm
cp components/$1/README.md lib/$1.wasm.md
lib/$1.debug.wasm: Cargo.toml Cargo.lock wit/deps $(shell find components/$1 -type f)
cargo component build -p $1 --target wasm32-wasip2
cp target/wasm32-wasip2/debug/$(subst -,_,$1).wasm lib/$1.debug.wasm
cp components/$1/README.md lib/$1.debug.wasm.md
endef
$(foreach component,$(COMPONENTS),$(eval $(call BUILD_COMPONENT,$(component))))
.PHONY: wit
wit: wit/deps
wit/deps: wkg.toml $(shell find wit -type f -name "*.wit" -not -path "deps")
wkg wit fetch
.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/cli.git" \
--annotation "org.opencontainers.image.revision=${REVISION}" \
--annotation "org.opencontainers.image.licenses=Apache-2.0" \
"${REPOSITORY}/${COMPONENT}:${TAG}" \
"lib/${FILE}"