From fbdbf8f406ddb3bcd990e35c32d20e417f5d10d9 Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Wed, 7 Sep 2022 10:01:19 +0200 Subject: [PATCH] build: Add cross-build target This builds both virtualization-amd64 and virtualization-arm64 for easier cross-platform testing. https://github.com/randall77/makefat can then be used to generate a universal binary if needed. --- example/linux/Makefile | 15 ++++++++++++++- example/macOS/Makefile | 15 ++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/example/linux/Makefile b/example/linux/Makefile index 260b05ef..541adff9 100644 --- a/example/linux/Makefile +++ b/example/linux/Makefile @@ -5,6 +5,19 @@ all: build codesign codesign: codesign --entitlements vz.entitlements -s - ./virtualization -.PHONY: build +.PHONY: build cross-build build: go build -o virtualization . + +cross-build: virtualization-amd64 virtualization-arm64 + +virtualization-amd64 virtualization-arm64: virtualization-%: force-build + CGO_ENABLED=1 GOOS=darwin GOARCH=$* go build -o $@ . + +# the go compiler is doing a good job at not rebuilding unchanged files +# this phony target ensures out/vfkit-* are always considered out of date +# and rebuilt. If the code was unchanged, go won't rebuild anything so that's +# fast. Forcing the rebuild ensure we rebuild when needed, ie when the source code +# changed, without adding explicit dependencies to the go files/go.mod +.PHONY: force-build +force-build: diff --git a/example/macOS/Makefile b/example/macOS/Makefile index 260b05ef..541adff9 100644 --- a/example/macOS/Makefile +++ b/example/macOS/Makefile @@ -5,6 +5,19 @@ all: build codesign codesign: codesign --entitlements vz.entitlements -s - ./virtualization -.PHONY: build +.PHONY: build cross-build build: go build -o virtualization . + +cross-build: virtualization-amd64 virtualization-arm64 + +virtualization-amd64 virtualization-arm64: virtualization-%: force-build + CGO_ENABLED=1 GOOS=darwin GOARCH=$* go build -o $@ . + +# the go compiler is doing a good job at not rebuilding unchanged files +# this phony target ensures out/vfkit-* are always considered out of date +# and rebuilt. If the code was unchanged, go won't rebuild anything so that's +# fast. Forcing the rebuild ensure we rebuild when needed, ie when the source code +# changed, without adding explicit dependencies to the go files/go.mod +.PHONY: force-build +force-build: