Skip to content

Commit b4cf77c

Browse files
authored
Makefile: build macOS universal binary and use it in release script (#138)
This PR updates the build process to generate a macOS universal binary containing both `x86_64` and `arm64` architectures. Previously, the macOS binary was `x86_64` only (`vt: Mach-O 64-bit executable x86_64`), which required Rosetta 2 to run on Apple Silicon Macs. This change fixes the binary for Apple Silicon machines that do not have Rosetta 2 installed. ### Changes: - Updated **Makefile** to compile both `darwin/amd64` and `darwin/arm64`, then combine them using `lipo`. - Added a fallback to `makefat` (via `go run`) when `lipo` is not available, ensuring that the build still succeeds on Linux-based CI runners (like GitHub Actions `ubuntu-latest`). - Updated **new_release.sh** to package the universal binary in `MacOSX.zip`.
1 parent c7e4cdb commit b4cf77c

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎Makefile‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,22 @@ install:
1515
go install ${LDFLAGS} github.com/VirusTotal/vt-cli/vt
1616

1717
# Build the project for multiple architectures
18-
.PHONY: all
19-
all:
18+
.PHONY: bins
19+
bins:
2020
gox ${LDFLAGS} \
21-
-osarch="linux/amd64 linux/386 windows/amd64 windows/386 darwin/amd64 freebsd/amd64 freebsd/386" \
21+
-osarch="linux/amd64 linux/386 windows/amd64 windows/386 darwin/amd64 darwin/arm64 freebsd/amd64 freebsd/386" \
2222
-output "build/{{.OS}}/{{.Arch}}/{{.Dir}}" github.com/VirusTotal/vt-cli/vt
2323

24+
# Build a universal binary for macOS (combining amd64 and arm64)
25+
.PHONY: all
26+
all: bins
27+
@mkdir -p build/darwin/universal
28+
@if command -v lipo >/dev/null 2>&1; then \
29+
lipo -create -output build/darwin/universal/vt build/darwin/amd64/vt build/darwin/arm64/vt; \
30+
else \
31+
go run github.com/randall77/makefat@latest build/darwin/universal/vt build/darwin/amd64/vt build/darwin/arm64/vt; \
32+
fi
33+
2434
# Cleans our project: deletes binaries
2535
.PHONY: clean
2636
clean:

‎new_release.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
mkdir dist
4-
zip -j dist/MacOSX.zip build/darwin/amd64/vt
4+
zip -j dist/MacOSX.zip build/darwin/universal/vt
55
zip -j dist/Linux32.zip build/linux/386/vt
66
zip -j dist/Linux64.zip build/linux/amd64/vt
77
zip -j dist/Windows32.zip build/windows/386/vt.exe

0 commit comments

Comments
 (0)