-
Notifications
You must be signed in to change notification settings - Fork 668
[WIP] made cross compile instead of qemu #1103
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
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: SergeyKanzhelev The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
now it is a different segfault. Still a segfault though |
I am curious if this is also flaky: /retest |
d2263cf
to
4b3baa5
Compare
experimenting here, any binary that compiles first out of three we compile, will fail with segfault. So it doesn't look like it is binary-specific. |
build.log
Outdated
@@ -0,0 +1,1066 @@ | |||
Docker in Docker enabled, initializing... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably this wasn't meant to be checked in?
4b3baa5
to
55b2a8e
Compare
Gemini generated:
The Problem
The build was failing specifically when creating the arm64 version of the container image. The build log showed a segmentation fault from the C compiler
(aarch64-linux-gnu-gcc).
This happens because the build machine is an amd64 architecture, but it's being asked to build an image for arm64. To do this, Docker's build system (BuildKit)
uses QEMU to emulate an arm64 environment. Running a compiler inside this emulated environment is often slow and can be unreliable, sometimes leading to crashes
like the one we saw.
The Solution: Native Cross-Compilation
The standard and much more reliable solution is to use native cross-compilation. Instead of emulating the target architecture, we run the compiler on the native
architecture of the build machine (amd64) and tell it to produce binaries for the target architecture (arm64). This is faster and avoids the instability of
emulation.
This is achieved with a multi-stage Dockerfile. The first stage (the builder) runs on the native build platform, compiles the code for all target platforms, and
the final stage copies the compiled binaries into the target platform's image.
Detailed Dockerfile Changes
FROM --platform=$BUILDPLATFORM builder-base AS builder
performing the build (e.g., linux/amd64). This flag forces the builder stage to always run natively on the build machine, completely avoiding QEMU
emulation during the compilation step. The TARGETARCH variable (e.g., arm64) is still available inside this stage, so we can use it to tell our tools what
architecture to build for.
RUN apt-get ... install ... gcc-x86-64-linux-gnu
corresponding amd64 C compiler to ensure the toolchain is complete for both target architectures within our native amd64 builder.
The rest of the Dockerfile and the Makefile already worked correctly with this setup, as the Makefile uses the GOARCH=${TARGETARCH} variable to select the
appropriate C compiler (CC).