Skip to content

Commit

Permalink
build: Add cross-build target
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cfergeau committed Sep 23, 2022
1 parent eea2452 commit c02599b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
15 changes: 14 additions & 1 deletion example/linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
15 changes: 14 additions & 1 deletion example/macOS/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:

0 comments on commit c02599b

Please sign in to comment.