Bootloader: Add Dockerfile to cross compile Linux bootloaders for abnormal architectures. #5995
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.
Add a Dockerfile which leverages the 'dockcross' family of cross compiler base images to build the Linux bootloaders for almost any architecture.
This required a few preliminary changes:
The waf script now always assumes it's building for the C compiler's reported target architecture if the target OS is Linux. Previously, it was determined from the host machine which of course is wrong in a cross compile setup.
To avoid bootloaders of different architectures clobbering each other if present in the same installation or git clone, append an architecture family name in the path to the bootloader. e.g. A
ppc64le
(Power PC, 64 bit, little endian) bootloader would be saved underPyInstaller/bootloader/Linux-64bit-ppc/run
. This change was already half implemented as a special case for ARM andsw_64
. This change only applies to Linux. All other OSs either don't need this change or, in the case of macOS, have their own special requirements and handling. This use of a loose family name for architectures rather than the exact output fromplatform.machine()
is needed so that waf can predict this name based only on the target reported by the C compiler which is considerably less exact than that ofuname -m
orplatform.machine()
. For example, whenplatform.machine()
isarmv5l
,armv6l
orarmv7h
, the C compiler simply reportsarm
in all cases. The mapping should go fromarmv7h
toarm
rather than the other way around.A couple of unintended bonuses of this approach:
dockcross provide manylinux2014 compatible compilers (see PEPs 513 and 599) to avoid the glibc symbol runtime errors that crop up if you don't keep glibc requirements lower than your target's version. This commit can also be used to build native
x86_64
binaries using a non-cross variant which conform to the manylinux2014 standard (which, as of setup: Build per-platform wheels. #5787, is advertised by our wheel tags).dockcross also includes cross compilers for alternative libc implementations meaning that we could use this to build
musl
bootloaders for Alpine orBionic
bootloaders for Android if we wanted to. However, they'd be difficult to distribute because PyPI currently only allows glibc Linux binaries.