Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-compile for Linux #1152

Merged
merged 11 commits into from
Apr 20, 2023
9 changes: 4 additions & 5 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ jobs:
- name: Run govulncheck
run: go install golang.org/x/vuln/cmd/govulncheck@latest; govulncheck ./...

- name: Set up zig
if: ${{ contains(matrix.os, 'ubuntu') }}
uses: goto-bus-stop/setup-zig@v2

- name: Build
if: ${{ ! contains(matrix.os, 'ubuntu') }}
run: make -j2 github-build

- name: Build (No Cross Compiles)
if: ${{ contains(matrix.os, 'ubuntu') }}
run: make -j2 github-build-no-cross

- name: Lipo
run: make github-lipo
if: ${{ contains(matrix.os, 'macos') }}
Expand Down
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ build/darwin.universal/%: lipo_%
##
GITHUB_TARGETS=launcher grpc.ext tables.ext package-builder
GITHUB_ARCHS=amd64 arm64
# linux cross compiles aren't working. Disable for now
github-build-no-cross: $(foreach t, $(GITHUB_TARGETS), build_$(t))
github-build: $(foreach t, $(GITHUB_TARGETS), $(foreach a, $(GITHUB_ARCHS), build_$(t)_noop_$(a)))
github-lipo: $(foreach t, $(GITHUB_TARGETS), lipo_$(t))
github-launcherapp: $(foreach a, $(GITHUB_ARCHS) universal, build/darwin.$(a)/Kolide.app)
Expand Down
4 changes: 2 additions & 2 deletions cmd/make/make.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func main() {
// on linux (for fscrypt)
optsMaybeCgo := opts
if *flBuildOS == "linux" {
// overwrite with append, since optsMaybyeCgo was a shallow clone
// overwrite with append, since optsMaybeCgo was a shallow clone
optsMaybeCgo = append(opts, make.WithCgo())
}

Expand All @@ -91,7 +91,7 @@ func main() {
"generate-tuf": make.New(opts...).GenerateTUF,
"launcher": make.New(optsMaybeCgo...).BuildCmd("./cmd/launcher", fakeName("launcher", *flFakeData)),
"tables.ext": make.New(optsMaybeCgo...).BuildCmd("./cmd/launcher.ext", "tables.ext"),
"grpc.ext": make.New(opts...).BuildCmd("./cmd/grpc.ext", "grpc.ext"),
"grpc.ext": make.New(optsMaybeCgo...).BuildCmd("./cmd/grpc.ext", "grpc.ext"),
"package-builder": make.New(opts...).BuildCmd("./cmd/package-builder", "package-builder"),
"make": make.New(opts...).BuildCmd("./cmd/make", "make"),
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/make/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,9 @@ func (b *Builder) BuildCmd(src, appName string) func(context.Context) error {
var ldFlags []string
if b.static {
ldFlags = append(ldFlags, "-d -linkmode internal")
} else if b.os == "linux" && b.arch != runtime.GOARCH {
// Cross-compiling for Linux requires external linking
ldFlags = append(ldFlags, "-linkmode external")
}

if !b.notStripped {
Expand Down