forked from vmware-labs/webassembly-language-runtimes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.helpers
188 lines (150 loc) · 4.78 KB
/
Makefile.helpers
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# Default wask-sdk version used in builds
WASI_SDK_VERSION ?= 20.0
define push_container_image
$(eval $@_IMAGE_NAME = $(1))
@(docker image inspect $($@_IMAGE_NAME) 1>/dev/null 2>&1 || \
(echo "Missing $($@_IMAGE_NAME). Cannot push" && false) ) && \
echo Pushing $($@_IMAGE_NAME) ... && \
echo Authenticating to ghcr.io ... && \
docker login ghcr.io && \
docker push $($@_IMAGE_NAME) && \
docker image rm $($@_IMAGE_NAME) && \
echo Pushed and deleted local tag to avoid usage of stale image in future.
endef
define make_builder_image
$(eval $@_IMAGE_NAME = $(1))
$(eval $@_ROOT_DIR = $(2))
$(eval $@_WASI_SDK_VERSION = $(3))
@echo Building $($@_IMAGE_NAME) in $($@_ROOT_DIR) ... && \
docker build \
--platform linux/amd64 \
-f $($@_ROOT_DIR)/Dockerfile \
--build-arg WASI_SDK_VERSION=$($@_WASI_SDK_VERSION) \
-t $($@_IMAGE_NAME) \
$($@_ROOT_DIR)
endef
##########
# Builds a wlr-make target inside a container.
# USAGE:
# - Inside a GNU make target
# - @$(call build_in_container,ghcr.io/vmware-labs/wasmlabs/wasi-builder:19,$(REPO_ROOT),libs/zlib/v1.2.13)
#
define build_in_container
$(eval $@_IMAGE_NAME = $(1))
$(eval $@_REPO_ROOT = $(2))
$(eval $@_WL_MAKE_TARGET = $(3))
docker run \
--platform linux/amd64 \
--rm \
-e WLR_BUILD_FLAVOR \
-e WLR_RUNTIME \
-e WLR_SKIP_CONFIGURE \
-e WLR_DEPS_FORCE_LOCAL \
-e WLR_PACKAGE_NAME \
-e WLR_PACKAGE_VERSION \
-v $($@_REPO_ROOT):/wlr/ \
-v $($@_REPO_ROOT)/scripts/wrappers/wasm-opt:/opt/priority-bin/wasm-opt \
$($@_IMAGE_NAME) \
./wlr-make.sh $($@_WL_MAKE_TARGET)
endef
##########
# Creates lib subtargets for libs that are built from external repo.
#
# USAGE:
# - At root level (not as part of a target)
# - Within the $(REPO_ROOT)/Makefile
# - $(eval $(call create_external_lib_sub_targets,zlib))
# - $(eval $(call create_external_lib_sub_targets,uuid))
define create_external_lib_sub_targets
# $1 - LIB_NAME
.PHONY: libs/$(1)/*
libs/$(1)/*:
make -C libs/$(1) $$(subst libs/$(1)/,,$$@)
endef
##########
# Creates lib subtargets for libs that are built from this repo.
#
# USAGE:
# - At root level (not as part of a target)
# - Within the $(REPO_ROOT)/Makefile
# - $(eval $(call create_local_lib_sub_targets,zlib))
# - $(eval $(call create_local_lib_sub_targets,uuid))
define create_local_lib_sub_targets
# $1 - LIB_NAME
.PHONY: libs/$(1)
libs/$(1):
make -C libs/$(1)
endef
##########
# Creates default targets for libs that are built from external repo.
#
# USAGE:
# - At Makefile root level (not as part of a target)
# - Within the lib/LIBNAME/Makefile
# - $(eval $(call create_default_external_lib_targets,$(REPO_ROOT),zlib,$(WASI_SDK_VERSION)))
# - $(eval $(call create_default_external_lib_targets,$(REPO_ROOT),uuid,$(WASI_SDK_VERSION)))
#
define create_default_external_lib_targets
# $1 - REPO_ROOT
# $2 - LIB_NAME
# $3 - WASI_SDK_VERSION
$(eval $(2)_BUILDER = ghcr.io/vmware-labs/wasmlabs/wasi-builder:$(3))
.PHONY: v*
v*:
@$(call build_in_container,$($(2)_BUILDER),$(1),libs/$(2)/$$$$@)
# The four $$-s are there because we have two passes in which we escape $ by a double $.
# We need the $@ variable only when the target is actually built
.PHONY: clean
clean:
rm -rf $(1)/build-output/$(2) $(1)/build-staging/$(2)
endef
##########
# Creates default targets for libs that are built from this repo.
#
# USAGE:
# - At Makefile root level (not as part of a target)
# - Within the lib/LIBNAME/Makefile
# - $(eval $(call create_default_local_lib_targets,$(REPO_ROOT),bundle_wlr,$(WASI_SDK_VERSION)))
#
define create_default_local_lib_targets
# $1 - REPO_ROOT
# $2 - LIB_NAME
# $3 - WASI_SDK_VERSION
$(eval $(2)_BUILDER = ghcr.io/vmware-labs/wasmlabs/wasi-builder:$(3))
.PHONY: all
all:
@$(call build_in_container,$($(2)_BUILDER),$(1),libs/$(2))
# The four $$-s are there because we have two passes in which we escape $ by a double $.
# We need the $@ variable only when the target is actually built
.PHONY: clean
clean:
rm -rf $(1)/build-output/$(2) $(1)/build-staging/$(2)
endef
##########
# Creates a flavor target for given runtime+version that is built from this repo.
#
# USAGE:
# - At Makefile root level (not as part of a target)
# - $(eval $(call create_flavor_target,php,v1.2.3,slim))
#
define create_flavor_target
# $1 - TARGET_NAME
# $2 - TARGET_VERSION
# $3 - TARGET_FLAVOR
.PHONY: $(1)/$(2)-$(3)
$(1)/$(2)-$(3):
WLR_BUILD_FLAVOR=$(3) make -C $(1) $(2)
endef
##########
# Creates target for all given flavors or given runtime+version that is built from this repo.
#
# USAGE:
# - At Makefile root level (not as part of a target)
# - $(call create_flavor_targets,php,v1.2.3,slim wasmedge slim-wasmedge)
#
define create_flavor_targets
# $1 - TARGET_NAME
# $2 - TARGET_VERSION
# $3 - TARGET_FLAVORS - separated by space
$(foreach _,${3},$(eval $(call create_flavor_target,${1},${2},$_)))
endef