From f9f93080dceb15edf060b98d1b3dfef2b14ce93c Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Thu, 20 Apr 2023 10:26:58 -0400 Subject: [PATCH 01/10] cross-compile for linux --- .github/workflows/go.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index d67a47e74..33c73e076 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -61,13 +61,8 @@ jobs: run: go install golang.org/x/vuln/cmd/govulncheck@latest; govulncheck ./... - 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') }} From 436e07eefc159f7a2b432df097e4b56e225a6b7d Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Thu, 20 Apr 2023 10:41:44 -0400 Subject: [PATCH 02/10] Add zig action --- .github/workflows/go.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 33c73e076..5cec1c65c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -60,6 +60,14 @@ 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: Zig test + if: ${{ contains(matrix.os, 'ubuntu') }} + run: zig build test + - name: Build run: make -j2 github-build From a77014e836474c9f1f426039f1317accdfc65cea Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Thu, 20 Apr 2023 10:45:35 -0400 Subject: [PATCH 03/10] No zig test for now --- .github/workflows/go.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 5cec1c65c..36e9090d2 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -64,9 +64,9 @@ jobs: if: ${{ contains(matrix.os, 'ubuntu') }} uses: goto-bus-stop/setup-zig@v2 - - name: Zig test - if: ${{ contains(matrix.os, 'ubuntu') }} - run: zig build test + #- name: Zig test + # if: ${{ contains(matrix.os, 'ubuntu') }} + # run: zig build test - name: Build run: make -j2 github-build From b5f65d5d6b960635712b06fc0ab9057aacbb7a16 Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Thu, 20 Apr 2023 10:52:03 -0400 Subject: [PATCH 04/10] Don't need zig test --- .github/workflows/go.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 36e9090d2..4a7600cc9 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -64,10 +64,6 @@ jobs: if: ${{ contains(matrix.os, 'ubuntu') }} uses: goto-bus-stop/setup-zig@v2 - #- name: Zig test - # if: ${{ contains(matrix.os, 'ubuntu') }} - # run: zig build test - - name: Build run: make -j2 github-build From 7343e6f6deb089ae92a7726f160129399c38be3c Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Thu, 20 Apr 2023 10:52:34 -0400 Subject: [PATCH 05/10] Remove no-cross build target --- Makefile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Makefile b/Makefile index a8225e056..08526b96a 100644 --- a/Makefile +++ b/Makefile @@ -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) From d672b883f17a36ffac8d6b0a615b80d845e2fe75 Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Thu, 20 Apr 2023 10:55:33 -0400 Subject: [PATCH 06/10] Set CC_FOR_TARGET and CXX_FOR_TARGET for linux cross-compiles --- pkg/make/builder.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/make/builder.go b/pkg/make/builder.go index a6ddc7cc7..f14fabc71 100644 --- a/pkg/make/builder.go +++ b/pkg/make/builder.go @@ -173,6 +173,8 @@ func New(opts ...Option) *Builder { fmt.Sprintf("ZIGTARGET=%s", zigTarget(b.os, b.arch)), fmt.Sprintf("CC=%s", filepath.Join(cwd, "tools", "zcc")), fmt.Sprintf("CXX=%s", filepath.Join(cwd, "tools", "zxx")), + fmt.Sprintf("CC_FOR_TARGET=%s", filepath.Join(cwd, "tools", "zcc")), + fmt.Sprintf("CXX_FOR_TARGET=%s", filepath.Join(cwd, "tools", "zxx")), ) } From b56ff3eda7ad569284eb567a25064cd134113e9f Mon Sep 17 00:00:00 2001 From: RebeccaMahany Date: Thu, 20 Apr 2023 11:35:47 -0400 Subject: [PATCH 07/10] Link externally for linux cross-compiles --- cmd/make/make.go | 4 ++-- pkg/make/builder.go | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/make/make.go b/cmd/make/make.go index 39e660f39..f3f0862f9 100644 --- a/cmd/make/make.go +++ b/cmd/make/make.go @@ -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()) } @@ -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"), } diff --git a/pkg/make/builder.go b/pkg/make/builder.go index f14fabc71..d4668bab2 100644 --- a/pkg/make/builder.go +++ b/pkg/make/builder.go @@ -173,8 +173,6 @@ func New(opts ...Option) *Builder { fmt.Sprintf("ZIGTARGET=%s", zigTarget(b.os, b.arch)), fmt.Sprintf("CC=%s", filepath.Join(cwd, "tools", "zcc")), fmt.Sprintf("CXX=%s", filepath.Join(cwd, "tools", "zxx")), - fmt.Sprintf("CC_FOR_TARGET=%s", filepath.Join(cwd, "tools", "zcc")), - fmt.Sprintf("CXX_FOR_TARGET=%s", filepath.Join(cwd, "tools", "zxx")), ) } @@ -505,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 { From 776ce5eaf04b1bca781482096b66b8c73e5ab068 Mon Sep 17 00:00:00 2001 From: RebeccaMahany Date: Thu, 20 Apr 2023 14:57:24 -0400 Subject: [PATCH 08/10] Try downgrading zig version to avoid -Wdeprecated-non-prototype build error --- .github/workflows/go.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 99aca75d9..205561f2f 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -63,6 +63,8 @@ jobs: - name: Set up zig if: ${{ contains(matrix.os, 'ubuntu') }} uses: goto-bus-stop/setup-zig@v2 + with: + version: 0.9.1 # Avoiding zig issue 13385 by downgrading -- upgrade to 0.11.0 when available - name: Build run: make -j2 github-build From da8aec800c387405c12cb76395e0cadaaf18dac0 Mon Sep 17 00:00:00 2001 From: RebeccaMahany Date: Thu, 20 Apr 2023 15:15:07 -0400 Subject: [PATCH 09/10] Try Wno-deprecated-non-prototype --- .github/workflows/go.yml | 2 -- tools/zcc | 2 +- tools/zxx | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 205561f2f..99aca75d9 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -63,8 +63,6 @@ jobs: - name: Set up zig if: ${{ contains(matrix.os, 'ubuntu') }} uses: goto-bus-stop/setup-zig@v2 - with: - version: 0.9.1 # Avoiding zig issue 13385 by downgrading -- upgrade to 0.11.0 when available - name: Build run: make -j2 github-build diff --git a/tools/zcc b/tools/zcc index fed97d6c4..0230fc794 100755 --- a/tools/zcc +++ b/tools/zcc @@ -2,4 +2,4 @@ # This is working around a go bug prior to 1.17 # https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho mkdir -p /tmp/zigcache -ZIG_LOCAL_CACHE_DIR="/tmp/zigcache" zig cc -target "$ZIGTARGET" "$@" +ZIG_LOCAL_CACHE_DIR="/tmp/zigcache" zig cc -Wno-deprecated-non-prototype -target "$ZIGTARGET" "$@" diff --git a/tools/zxx b/tools/zxx index d19d9e04c..2bb43d196 100755 --- a/tools/zxx +++ b/tools/zxx @@ -2,5 +2,5 @@ # This is working around a go bug prior to 1.17 # https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho mkdir -p /tmp/zigcache -ZIG_LOCAL_CACHE_DIR="/tmp/zigcache" zig c++ -target "$ZIGTARGET" "$@" +ZIG_LOCAL_CACHE_DIR="/tmp/zigcache" zig c++ -Wno-deprecated-non-prototype -target "$ZIGTARGET" "$@" From 7dfe6f473274e610f22993774aa5317afdc8eab8 Mon Sep 17 00:00:00 2001 From: RebeccaMahany Date: Thu, 20 Apr 2023 16:08:40 -0400 Subject: [PATCH 10/10] Remove flag --- tools/zcc | 2 +- tools/zxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/zcc b/tools/zcc index 0230fc794..fed97d6c4 100755 --- a/tools/zcc +++ b/tools/zcc @@ -2,4 +2,4 @@ # This is working around a go bug prior to 1.17 # https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho mkdir -p /tmp/zigcache -ZIG_LOCAL_CACHE_DIR="/tmp/zigcache" zig cc -Wno-deprecated-non-prototype -target "$ZIGTARGET" "$@" +ZIG_LOCAL_CACHE_DIR="/tmp/zigcache" zig cc -target "$ZIGTARGET" "$@" diff --git a/tools/zxx b/tools/zxx index 2bb43d196..d19d9e04c 100755 --- a/tools/zxx +++ b/tools/zxx @@ -2,5 +2,5 @@ # This is working around a go bug prior to 1.17 # https://dev.to/kristoff/zig-makes-go-cross-compilation-just-work-29ho mkdir -p /tmp/zigcache -ZIG_LOCAL_CACHE_DIR="/tmp/zigcache" zig c++ -Wno-deprecated-non-prototype -target "$ZIGTARGET" "$@" +ZIG_LOCAL_CACHE_DIR="/tmp/zigcache" zig c++ -target "$ZIGTARGET" "$@"