Skip to content

Commit

Permalink
makefile: autodetect target arch for builds
Browse files Browse the repository at this point in the history
Use TARGET_ARCH based on the uname -r instead of always relying on manually passed values. This should enable using current instruction for local development without any changes.
Simplify kernel related makefile targets.

Signed-off-by: Misha Sakhnov <[email protected]>
  • Loading branch information
mikhail-sakhnov committed Jan 10, 2025
1 parent 0f36d50 commit c96ac0a
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ GOOS ?= $(shell go env GOOS)

# The target architecture for linux kernel. Possible values: amd64 or arm64.
# Any other supported by linux kernel architecture could be added by introducing new build step into neonvm/hack/kernel/Dockerfile.kernel-builder
KERNEL_TARGET_ARCH ?= amd64
TARGET_ARCH ?= amd64
UNAME_ARCH := $(shell uname -m)
ifeq ($(UNAME_ARCH),x86_64)
TARGET_ARCH ?= amd64
else ifeq ($(UNAME_ARCH),aarch64)
TARGET_ARCH ?= arm64
else
$(error Unsupported architecture: $(UNAME_ARCH))
endif

# Get the currently used golang base path
GOPATH=$(shell go env GOPATH)
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
Expand Down Expand Up @@ -264,19 +271,9 @@ ifndef ignore-not-found
ignore-not-found = false
endif

# Build the kernel for the amd64 architecture. Uses generic target.
.PHONY: kernel_amd64
kernel_amd64: KERNEL_TARGET_ARCH=amd64
kernel_amd64: kernel

# Build the kernel for the arm64 architecture. Uses generic target.
.PHONY: kernel_arm64
kernel_arm64: KERNEL_TARGET_ARCH=arm64
kernel_arm64: kernel

# Build the kernel for the target architecture.
# The builder image platform is not specified because the kernel is built for the target architecture using crosscompilation.
# Target is generic and can be used for any supported architecture by specifying the KERNEL_TARGET_ARCH variable.
# Target is generic and can be used for any supported architecture by specifying the TARGET_ARCH variable.
.PHONY: kernel
kernel: ## Build linux kernel.
rm -f neonvm-kernel/vmlinuz; \
Expand All @@ -286,7 +283,7 @@ kernel: ## Build linux kernel.
trap "rm $$iidfile" EXIT; \
docker buildx build \
--build-arg KERNEL_VERSION=$$kernel_version \
--target "kernel_${KERNEL_TARGET_ARCH}" \
--target "kernel_${TARGET_ARCH}" \
--pull \
--load \
--iidfile $$iidfile \
Expand Down Expand Up @@ -394,12 +391,9 @@ load-example-vms: check-local-context kubectl kind k3d ## Load the testing VM im
@if [ $$($(KUBECTL) config current-context) = kind-$(CLUSTER_NAME) ]; then $(KIND) load docker-image $(E2E_TESTS_VM_IMG) --name $(CLUSTER_NAME); fi

.PHONY: example-vms
example-vms: TARGET_ARCH=$(TARGET_ARCH)
example-vms: docker-build-examples load-example-vms ## Build and push the testing VM images to the kind/k3d cluster.

.PHONY: example-vms-arm64
example-vms-arm64: TARGET_ARCH=arm64
example-vms-arm64: example-vms

.PHONY: load-pg16-disk-test
load-pg16-disk-test: check-local-context kubectl kind k3d ## Load the pg16-disk-test VM image to the kind/k3d cluster.
@if [ $$($(KUBECTL) config current-context) = k3d-$(CLUSTER_NAME) ]; then $(K3D) image import $(PG16_DISK_TEST_IMG) --cluster $(CLUSTER_NAME) --mode direct; fi
Expand Down

0 comments on commit c96ac0a

Please sign in to comment.