@@ -6,29 +6,48 @@ TEST_IMG_NAME ?= wasmtest:latest
6
6
RUNTIMES ?= wasmedge wasmtime wasmer
7
7
CONTAINERD_NAMESPACE ?= default
8
8
9
+ # We have a bit of fancy logic here to determine the target
10
+ # since we support building for gnu and musl
11
+ # TARGET must evenutually match one of the values in the cross.toml
12
+ HOST_TARGET = $(shell rustc --version -v | sed -En 's/host: (.* ) /\1/p')
13
+
14
+ # if TARGET is not set and we are using cross
15
+ # default to musl to facilitate easier use shim on other distros becuase of the static build
16
+ # otherwise use the host target
17
+ ifeq ($(TARGET ) ,)
9
18
ifeq ($(CARGO ) ,cross)
10
- # Set the default target as defined in Cross.toml
11
- TARGET ?= $(shell uname -m) -unknown-linux-musl
19
+ override TARGET = $(shell uname -m) -unknown-linux-musl
20
+ else
21
+ override TARGET = $(HOST_TARGET )
22
+ endif
23
+ endif
24
+
25
+ # always use cross when the target is not the host target
26
+ ifneq ($(TARGET ) ,$(HOST_TARGET ) )
27
+ override CARGO = cross
28
+ endif
29
+
30
+ ifeq ($(CARGO ) ,cross)
31
+ override TARGET_DIR := $(or $(TARGET_DIR ) ,./target/build/$(TARGET ) /)
12
32
# When using `cross` we need to run the tests outside the `cross` container.
13
33
# We stop `cargo test` from running the tests with the `--no-run` flag.
14
34
# We then need to run the generate test binary manually.
15
35
# For that we use `--message-format=json` and `jq` to find the name of the binary, `xargs` and execute it.
16
36
TEST_ARGS_SEP = --no-run --color=always --message-format=json | \
17
37
jq -R '. as $$line | try (fromjson | .executable | strings) catch ($$line+"\n" | stderr | empty)' -r | \
38
+ sed -E 's|^/target|$(TARGET_DIR ) |' | \
18
39
xargs -I_ ./scripts/test-runner.sh ./_
19
40
else
20
- TARGET ? = $(shell rustc --version -v | sed -En 's/host: (. * ) /\1/p' )
41
+ override TARGET_DIR : = $(or $( TARGET_DIR ) ,./target/ )
21
42
TEST_ARGS_SEP = --
22
43
endif
44
+ TARGET_FLAG = --target=$(TARGET ) --target-dir=$(TARGET_DIR )
23
45
24
46
OPT_PROFILE ?= debug
25
47
RELEASE_FLAG :=
26
48
ifeq ($(OPT_PROFILE ) ,release)
27
49
RELEASE_FLAG = --release
28
50
endif
29
- ifneq ($(TARGET ) ,)
30
- TARGET_FLAG = --target=$(TARGET )
31
- endif
32
51
33
52
FEATURES_wasmedge =
34
53
WARNINGS = -D warnings
@@ -111,7 +130,7 @@ install: $(RUNTIMES:%=install-%);
111
130
112
131
install-% : build-%
113
132
mkdir -p $(PREFIX ) /bin
114
- $(INSTALL ) target /$(TARGET ) /$(OPT_PROFILE ) /containerd-shim-$* -v1 $(PREFIX ) /bin/
133
+ $(INSTALL ) $( TARGET_DIR ) /$(TARGET ) /$(OPT_PROFILE ) /containerd-shim-$* -v1 $(PREFIX ) /bin/
115
134
$(LN ) ./containerd-shim-$* -v1 $(PREFIX ) /bin/containerd-shim-$* d-v1
116
135
$(LN ) ./containerd-shim-$* -v1 $(PREFIX ) /bin/containerd-$* d
117
136
@@ -181,8 +200,8 @@ bin/kind: test/k8s/Dockerfile
181
200
$(DOCKER_BUILD ) --output=bin/ -f test/k8s/Dockerfile --target=kind .
182
201
183
202
# Use a static build of the shims for better compatibility.
184
- # Using cross defaults to x86_64 -unknown-linux-musl, which creates a static build .
185
- test/k8s/_out/img-% : CARGO=cross
203
+ # Using cross with no target defaults to <arch> -unknown-linux-musl, which creates a static binary .
204
+ test/k8s/_out/img-% : override CARGO=cross TARGET= TARGET_DIR=
186
205
test/k8s/_out/img-% : test/k8s/Dockerfile dist-%
187
206
mkdir -p $(@D ) && $(DOCKER_BUILD ) -f test/k8s/Dockerfile --build-arg=" RUNTIME=$* " --iidfile=$(@ ) --load .
188
207
@@ -233,3 +252,11 @@ test/k3s-%: dist/img.tar bin/k3s dist-%
233
252
234
253
.PHONY : test/k3s/clean
235
254
test/k3s/clean : bin/k3s/clean;
255
+
256
+ .PHONY : clean
257
+ clean :
258
+ -rm -rf dist
259
+ -rm -rf bin
260
+ -$(MAKE ) test-image/clean
261
+ -$(MAKE ) test/k8s/clean
262
+ -$(MAKE ) test/k3s/clean
0 commit comments