Skip to content

Commit 94003ca

Browse files
jsturtevantjprendes
andcommitted
Fix issue running k8s and cross locally
Signed-off-by: James Sturtevant <[email protected]> Signed-off-by: Jorge Prendes <[email protected]> Co-authored-by: Jorge Prendes <[email protected]>
1 parent 98006dc commit 94003ca

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

Makefile

+36-9
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,48 @@ TEST_IMG_NAME ?= wasmtest:latest
66
RUNTIMES ?= wasmedge wasmtime wasmer
77
CONTAINERD_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),)
918
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)/)
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.
1636
TEST_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 ./_
1940
else
20-
TARGET ?= $(shell rustc --version -v | sed -En 's/host: (.*)/\1/p')
41+
override TARGET_DIR := $(or $(TARGET_DIR),./target/)
2142
TEST_ARGS_SEP= --
2243
endif
44+
TARGET_FLAG = --target=$(TARGET) --target-dir=$(TARGET_DIR)
2345

2446
OPT_PROFILE ?= debug
2547
RELEASE_FLAG :=
2648
ifeq ($(OPT_PROFILE),release)
2749
RELEASE_FLAG = --release
2850
endif
29-
ifneq ($(TARGET),)
30-
TARGET_FLAG = --target=$(TARGET)
31-
endif
3251

3352
FEATURES_wasmedge =
3453
WARNINGS = -D warnings
@@ -111,7 +130,7 @@ install: $(RUNTIMES:%=install-%);
111130

112131
install-%: 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

@@ -181,8 +200,8 @@ bin/kind: test/k8s/Dockerfile
181200
$(DOCKER_BUILD) --output=bin/ -f test/k8s/Dockerfile --target=kind .
182201

183202
# 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=
186205
test/k8s/_out/img-%: test/k8s/Dockerfile dist-%
187206
mkdir -p $(@D) && $(DOCKER_BUILD) -f test/k8s/Dockerfile --build-arg="RUNTIME=$*" --iidfile=$(@) --load .
188207

@@ -233,3 +252,11 @@ test/k3s-%: dist/img.tar bin/k3s dist-%
233252

234253
.PHONY: test/k3s/clean
235254
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

Comments
 (0)