Skip to content

Commit 8645d45

Browse files
author
Roberto Dip
authored
build universal binaries for orbit in macOS in our test tuf server (#16712)
two motivations: - prevent mysterious crashes in arm64 machines without Rosetta (often the case in fresh VMs) - prevent unexpected errors in Windows arm64 VMs when using certain system calls # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Manual QA for all new/changed functionality
1 parent dbed680 commit 8645d45

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

orbit/tools/build/build.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ func main() {
3333
commit := os.Getenv("ORBIT_COMMIT")
3434
date := time.Now().UTC().Format("2006-01-02T15:04:05Z")
3535

36+
binaryPath := os.Getenv("ORBIT_BINARY_PATH")
37+
if binaryPath == "" {
38+
binaryPath = "orbit-darwin"
39+
}
40+
3641
codesign := false
3742
if codesignIdentity != "" {
3843
codesign = true
@@ -50,7 +55,6 @@ func main() {
5055
const (
5156
amdBinaryPath = "orbit-darwin-amd64"
5257
armBinaryPath = "orbit-darwin-arm64"
53-
binaryPath = "orbit-darwin"
5458
bundleIdentifier = "com.fleetdm.orbit"
5559
)
5660
if err := buildOrbit(amdBinaryPath, "amd64", version, commit, date); err != nil {

tools/tuf/test/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,19 @@ GOOS=windows GOARCH=amd64 go build -o orbit-windows.exe ./orbit/cmd/orbit
6868
./tools/tuf/test/push_target.sh windows orbit orbit-windows.exe 43
6969
```
7070

71+
If the script was executed on a macOS host, the Orbit binary will be an universal binary. To push updates you can do:
72+
73+
```sh
74+
# Compile a universal binary of Orbit:
75+
CGO_ENABLED=1 \
76+
ORBIT_VERSION=42 \
77+
ORBIT_BINARY_PATH="orbit-macos" \
78+
go run ./orbit/tools/build/build.go
79+
80+
# Push the compiled Orbit as a new version
81+
./tools/tuf/test/push_target.sh macos orbit orbit-macos 43
82+
```
83+
7184
E.g. to add a new version of `osqueryd` for macOS:
7285
```sh
7386
# Generate osqueryd app bundle.

tools/tuf/test/create_repository.sh

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,30 @@ for system in $SYSTEMS; do
6161
rm $osqueryd_path
6262

6363
goose_value="$system"
64+
goarch_value="" # leave it empty to use the default for the system
6465
if [[ $system == "macos" ]]; then
6566
goose_value="darwin"
67+
# for all platforms except Darwin, GOARCH is hardcoded to amd64 to
68+
# prevent cross compilation issues when building macOS arm64 binaries
69+
# from Linux (CGO + libraries are required)
70+
goarch_value="amd64"
6671
fi
6772
orbit_target=orbit-$system
6873
if [[ $system == "windows" ]]; then
6974
orbit_target="${orbit_target}.exe"
7075
fi
7176

72-
# Compile the latest version of orbit from source.
73-
GOOS=$goose_value GOARCH=amd64 go build -ldflags="-X github.com/fleetdm/fleet/v4/orbit/pkg/build.Version=42" -o $orbit_target ./orbit/cmd/orbit
74-
75-
# If macOS and CODESIGN_IDENTITY is defined, sign the executable.
76-
if [[ $system == "macos" && -n "$CODESIGN_IDENTITY" ]]; then
77-
codesign -s "$CODESIGN_IDENTITY" -i com.fleetdm.orbit -f -v --timestamp --options runtime $orbit_target
77+
# compiling a macOS-arm64 binary requires CGO and a macOS computer (for
78+
# Apple keychain, some tables, etc), if this is the case, compile an
79+
# universal binary.
80+
if [ $system == "macos" ] && [ "$(uname -s)" = "Darwin" ]; then
81+
CGO_ENABLED=1 \
82+
CODESIGN_IDENTITY=$CODESIGN_IDENTITY \
83+
ORBIT_VERSION=42 \
84+
ORBIT_BINARY_PATH=$orbit_target \
85+
go run ./orbit/tools/build/build.go
86+
else
87+
GOOS=$goose_value GOARCH=$goarch_value go build -ldflags="-X github.com/fleetdm/fleet/v4/orbit/pkg/build.Version=42" -o $orbit_target ./orbit/cmd/orbit
7888
fi
7989

8090
./build/fleetctl updates add \

0 commit comments

Comments
 (0)