@@ -6,29 +6,48 @@ TEST_IMG_NAME ?= wasmtest:latest
66RUNTIMES ?= wasmedge wasmtime wasmer
77CONTAINERD_NAMESPACE ?= default
88
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 ) ,)
918ifeq ($(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 ) /)
1232# When using `cross` we need to run the tests outside the `cross` container.
1333# We stop `cargo test` from running the tests with the `--no-run` flag.
1434# We then need to run the generate test binary manually.
1535# For that we use `--message-format=json` and `jq` to find the name of the binary, `xargs` and execute it.
1636TEST_ARGS_SEP = --no-run --color=always --message-format=json | \
1737 jq -R '. as $$line | try (fromjson | .executable | strings) catch ($$line+"\n" | stderr | empty)' -r | \
38+ sed -E 's|^/target|$(TARGET_DIR ) |' | \
1839 xargs -I_ ./scripts/test-runner.sh ./_
1940else
20- TARGET ? = $(shell rustc --version -v | sed -En 's/host: (. * ) /\1/p' )
41+ override TARGET_DIR : = $(or $( TARGET_DIR ) ,./target/ )
2142TEST_ARGS_SEP = --
2243endif
44+ TARGET_FLAG = --target=$(TARGET ) --target-dir=$(TARGET_DIR )
2345
2446OPT_PROFILE ?= debug
2547RELEASE_FLAG :=
2648ifeq ($(OPT_PROFILE ) ,release)
2749RELEASE_FLAG = --release
2850endif
29- ifneq ($(TARGET ) ,)
30- TARGET_FLAG = --target=$(TARGET )
31- endif
3251
3352FEATURES_wasmedge =
3453WARNINGS = -D warnings
@@ -111,7 +130,7 @@ install: $(RUNTIMES:%=install-%);
111130
112131install-% : build-%
113132 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/
115134 $(LN ) ./containerd-shim-$* -v1 $(PREFIX ) /bin/containerd-shim-$* d-v1
116135 $(LN ) ./containerd-shim-$* -v1 $(PREFIX ) /bin/containerd-$* d
117136
@@ -149,8 +168,8 @@ bin/kind: test/k8s/Dockerfile
149168 $(DOCKER_BUILD ) --output=bin/ -f test/k8s/Dockerfile --target=kind .
150169
151170# Use a static build of the shims for better compatibility.
152- # Using cross defaults to x86_64 -unknown-linux-musl, which creates a static build .
153- test/k8s/_out/img-% : CARGO=cross
171+ # Using cross with no target defaults to <arch> -unknown-linux-musl, which creates a static binary .
172+ test/k8s/_out/img-% : override CARGO=cross TARGET= TARGET_DIR=
154173test/k8s/_out/img-% : test/k8s/Dockerfile dist-%
155174 mkdir -p $(@D ) && $(DOCKER_BUILD ) -f test/k8s/Dockerfile --build-arg=" RUNTIME=$* " --iidfile=$(@ ) --load .
156175
@@ -193,3 +212,11 @@ test/k3s-%: dist/img.tar bin/k3s dist-%
193212
194213.PHONY : test/k3s/clean
195214test/k3s/clean : bin/k3s/clean;
215+
216+ .PHONY : clean
217+ clean :
218+ -rm -rf dist
219+ -rm -rf bin
220+ -$(MAKE ) test-image/clean
221+ -$(MAKE ) test/k8s/clean
222+ -$(MAKE ) test/k3s/clean
0 commit comments