pkg/pillar: fix dhcpcd cross-compilation#5830
Draft
rucoder wants to merge 1 commit intolf-edge:masterfrom
Draft
Conversation
Cross-compiling pillar for a non-native architecture (e.g. `make
ZARCH=arm64 pkg/pillar` on an amd64 host) failed in the dhcpcd build
stage with:
Deriving operating system from ... x86_64-unknown-linux
...
No suitable user found for Priviledge Separation!
Using compiler .. aarch64-alpine-linux-musl-gcc
aarch64-alpine-linux-musl-gcc does not create executables
dhcpcd uses a hand-rolled ./configure script (not autotools) that:
1. Derives the target triplet from the build host's `uname -m` when
--build/--host are not supplied, so it never realizes this is a
cross build and produces a host-arch test executable using the
cross compiler.
2. Looks up the dhcpcd privsep user in the build host's /etc/passwd,
which does not contain that user (it is only added to the runtime
image later).
Even with those two flags fixed, the cross gcc itself still fails to
link because it was built with --with-sysroot=/home/builder/sysroot-...
(a path baked into the toolchain at its own build time) which does not
exist in this image. The Alpine target libs/headers are copied to
/usr/${EVE_TARGET_ARCH}-alpine-linux-musl by the build-cross-target
stage, so we point gcc at that sysroot via --sysroot in CC.
Detecting the cross build via EVE_TARGET_ARCH does not work because
the eve-alpine base image already exports that variable in its own
environment, so it would also be set in native builds. CROSS_COMPILE_ENV
is set only by the cross build stages and is the correct signal.
Signed-off-by: Mikhail Malyshev <mike.malyshev@gmail.com>
7747732 to
97a437a
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5830 +/- ##
==========================================
+ Coverage 19.52% 24.36% +4.83%
==========================================
Files 19 24 +5
Lines 3021 5314 +2293
==========================================
+ Hits 590 1295 +705
- Misses 2310 3799 +1489
- Partials 121 220 +99 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
THIS PR IS JSUT TO DEMONSTRATE HOW CROSS COMPILATION IS BROKEN
Cross-compiling pillar for a non-native architecture (e.g.
make ZARCH=arm64 pkg/pillaron an amd64 host) fails in thedhcpcdbuild stage with:
dhcpcdupstream uses a hand-rolled./configurescript (not autotools) that:uname -mwhen--build/--hostare not supplied, so it never realises this is a cross build and tries to produce a host-arch test executable using the cross compiler.dhcpcdprivsep user in the build host's/etc/passwd, which does not contain that user (it is only added to the runtime image later).Even after fixing those two, the cross gcc itself still fails to link because it was built with
--with-sysroot=/home/builder/sysroot-...(a path baked into the toolchain at its own build time) which does not exist in this image. The Alpine target libs/headers are copied to/usr/${EVE_TARGET_ARCH}-alpine-linux-muslby thebuild-cross-targetstage, so we point gcc at that sysroot via--sysrootinCC. The same fix unblocks Go cgo builds further down the Dockerfile (which were silently broken too — they failed withstdlib.h: No such file or directory).Detecting the cross build via
EVE_TARGET_ARCHdoes not work because theeve-alpinebase image already exports that variable in its own environment, so it would also be set in native builds. This PR usesCROSS_COMPILE_ENV, which is set only by the cross build stages, as the cross-compile signal.How to test and validate this PR
On an amd64 host:
Both should build to completion. The dhcpcd configure step should
print
Configuring dhcpcd for ... linuxwith the correct targettriplet, and the Go vet / build steps should succeed.
I have verified locally:
make ZARCH=arm64 pkg/pillar(amd64 host → arm64 target): OKmake ZARCH=amd64 pkg/pillar(amd64 host → amd64 target): OKChangelog notes
No user-facing changes (build-system fix only).
PR Backports
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.