Skip to content

Fix Go package cross-compilation and add parallel builds#5811

Merged
rene merged 6 commits intolf-edge:masterfrom
rucoder:rucoder/go-cross-builds
Apr 22, 2026
Merged

Fix Go package cross-compilation and add parallel builds#5811
rene merged 6 commits intolf-edge:masterfrom
rucoder:rucoder/go-cross-builds

Conversation

@rucoder
Copy link
Copy Markdown
Contributor

@rucoder rucoder commented Apr 16, 2026

Description

these commits are cherry-picked from #5730 and will be removed from that PR.

Fix cross-compilation for several pure-Go EVE packages by adding --platform=$BUILDPLATFORM so the Go compiler runs natively on the host instead of under QEMU emulation. Cross-compilation is achieved with
GOARCH=$TARGETARCH and CGO_ENABLED=0. Runtime dependencies are installed in separate stages without --platform so they resolve to the correct target architecture.

Packages fixed:

  • recovertpm
  • measure-config
  • newlog
  • edgeview

Additionally:

  • debug: add parallel make (-j) for lshw and hexedit builds, with a workaround for lshw's Makefile race condition.
  • Package hashes updated to reflect the Dockerfile changes.

How to test and validate this PR

  1. Build EVE for both amd64 and arm64:
    make ZARCH=amd64 pkgs
    make ZARCH=arm64 pkgs
    
  2. Verify that the affected packages (recovertpm, measure-config, newlog, edgeview, debug) build successfully for both architectures without QEMU emulation errors.
  3. Boot the resulting image and verify that the services start correctly.

Changelog notes

Speedup cross-compilation of GO applications on CI and MacOS

PR Backports

  • 16.0-stable: No, build-only improvement
  • 14.5-stable: No, build-only improvement
  • 13.4-stable: No, build-only improvement

Checklist

  • I've provided a proper description

  • I've added the proper documentation

  • I've tested my PR on amd64 device

  • I've tested my PR on arm64 device

  • I've written the test verification instructions

  • I've set the proper labels to this PR

  • I've checked the boxes above, or I've provided a good reason why I didn't
    check them.

@europaul
Copy link
Copy Markdown
Contributor

europaul commented Apr 16, 2026

PR Backports

16.0-stable: No, build-only improvement
14.5-stable: No, build-only improvement
13.4-stable: No, build-only improvement

be careful with the backport section written by claude - 9 out of 10 times it's garbage

build improvements should be backported

@rucoder
Copy link
Copy Markdown
Contributor Author

rucoder commented Apr 16, 2026

PR Backports

16.0-stable: No, build-only improvement
14.5-stable: No, build-only improvement
13.4-stable: No, build-only improvement

be careful with the backport section written by claude - 9 out of 10 times it's garbage

build improvements need to be backported

this is no Claude :) and I always instruct manually about backports. and since when we backport build improvements? @rene ?

@rucoder rucoder requested a review from rene April 16, 2026 12:25
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 26.56%. Comparing base (2281599) to head (02016dc).
⚠️ Report is 500 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5811      +/-   ##
==========================================
+ Coverage   19.52%   26.56%   +7.03%     
==========================================
  Files          19       24       +5     
  Lines        3021     4213    +1192     
==========================================
+ Hits          590     1119     +529     
- Misses       2310     2872     +562     
- Partials      121      222     +101     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

rucoder added 5 commits April 17, 2026 10:21
Add --platform=$BUILDPLATFORM so the Go build runs natively on the
host instead of under QEMU emulation. Cross-compile with
GOARCH=$TARGETARCH. The build is pure Go with CGO_ENABLED=0, so no
C toolchain is needed.

Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
Add --platform=$BUILDPLATFORM so the Go build runs natively on the
host instead of under QEMU emulation. Cross-compile with
GOARCH=$TARGETARCH. The build is pure Go with CGO_ENABLED=0, so no
C toolchain is needed.

Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
Add --platform=$BUILDPLATFORM so the Go build runs natively on the
host instead of under QEMU emulation. Cross-compile with
GOARCH=$TARGETARCH. The build is pure Go with CGO_ENABLED=0, so no
C toolchain is needed.

Runtime packages (coreutils) are installed in a separate stage without
--platform so they resolve to the correct target architecture.

Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
lshw's Makefile has a race condition with parallel builds: the "static"
target depends on both the "core" phony target and "core/liblshw.a"
file. With -j, make starts building liblshw.a via the "core" target
while simultaneously looking for the liblshw.a file which doesn't exist
yet. Work around this by building the "core" target first in a separate
make invocation, then building "static" once the library is available.

Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
Add --platform=$BUILDPLATFORM so the Go build runs natively on the
host instead of under QEMU emulation. Cross-compile with
GOARCH=$TARGETARCH. The build is pure Go with CGO_ENABLED=0, so no
C toolchain is needed.

Runtime packages (iproute2, iptables, etc.) are installed in a separate
stage without --platform so they resolve to the correct target
architecture.

Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
@rucoder rucoder force-pushed the rucoder/go-cross-builds branch from 02016dc to d9ee4ae Compare April 17, 2026 10:31
- update hashes in dependent packages

Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
Copy link
Copy Markdown
Contributor

@rene rene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rene rene merged commit 3d2b692 into lf-edge:master Apr 22, 2026
38 of 44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants