Fix cross-compiling librt by enabling x86_64 optimisations with pragmas#20815
Open
chewi wants to merge 1 commit intopython:masterfrom
Open
Fix cross-compiling librt by enabling x86_64 optimisations with pragmas#20815chewi wants to merge 1 commit intopython:masterfrom
chewi wants to merge 1 commit intopython:masterfrom
Conversation
86b9baf to
b9a9e73
Compare
Author
|
Okay, so it isn't normally built with |
Contributor
I suggest surrounding the pramas with checks for the appropriate compiler |
Although Python still lacks a supported method to cross-compile packages, many downstreams do it anyway, so librt should allow this. The current approach of enabling x86_64 optimisations after checking platform.machine() is broken. When building on x86_64 for another architecture, the build fails because the optimisations get enabled when they shouldn't. Conversely, when building on another architecture for x86_64, the build fails because the optimisations don't get enabled when they should. GCC supports enabling an optimisation with a pragma from that line onwards. Clang requires the optimisation to be pushed on and popped off the stack. Unfortunately, MSVC does not have an equivalent feature, but it is unlikely anyone would cross-compile to x86_64 with that. The remaining logic for MSVC could be simplified, but it looks like other compilers like Borland are potentially supported? I considered checking for x86_64 using CCompiler's preprocess() instead, but this seemed awkward. This has been tested with GCC and Clang, including with AVX512 enabled.
b9a9e73 to
d0bf832
Compare
Author
|
Okay, done that. |
mr-c
approved these changes
Feb 16, 2026
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.
Although Python still lacks a supported method to cross-compile packages, many downstreams do it anyway, so librt should allow this.
The current approach of enabling x86_64 optimisations after checking
platform.machine()is broken. When building on x86_64 for another architecture, the build fails because the optimisations get enabled when they shouldn't. Conversely, when building on another architecture for x86_64, the build fails because the optimisations don't get enabled when they should.GCC supports enabling an optimisation with a pragma from that line onwards. Clang requires the optimisation to be pushed on and popped off the stack. Unfortunately, MSVC does not have an equivalent feature, but it is unlikely anyone would cross-compile to x86_64 with that.
The remaining logic for MSVC could be simplified, but it looks like other compilers like Borland are potentially supported?
I considered checking for x86_64 using CCompiler's
preprocess()instead, but this seemed awkward.This has been tested with GCC and Clang, including with AVX512 enabled.
Supersedes mypyc/librt#32.