Cross-compilation and Packaging
Cross-compilation and Packaging
GM Desktop runs on Linux (amd64 / arm64) and macOS, so the Go backend must be built as a static binary (CGO_ENABLED=0) with no dynamic dependencies.
1. Recommended Makefile
.PHONY: build build-linux clean
APP_NAME = backend
BUILD_DIR = build
build:
CGO_ENABLED=0 go build -ldflags "-s -w" -o $(BUILD_DIR)/$(APP_NAME) cmd/main.go
build-linux-amd64:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o $(BUILD_DIR)/$(APP_NAME)-linux-amd64 cmd/main.go
build-linux-arm64:
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags "-s -w" -o $(BUILD_DIR)/$(APP_NAME)-linux-arm64 cmd/main.go
clean:
rm -rf $(BUILD_DIR)2. Release Package Layout
The ZIP package delivered to GM Desktop looks like this:
my-app.zip
├── manifest.json # app metadata
├── conf/
│ └── config.yaml # runtime configuration
├── dist/ # static frontend build output
│ ├── index.html
│ └── assets/
└── bin/ # statically built Go backend
└── backend