-
Notifications
You must be signed in to change notification settings - Fork 934
Free-threaded build config fixes #4719
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1ba689e
update build config logic and library name generation
ngoldbaum dd0142b
fix free-threaded windows clippy with --features=abi3
ngoldbaum 6098339
use constant
ngoldbaum 1ffd21c
add release note
ngoldbaum d3c7859
apply my self-review comments
ngoldbaum 6100ff3
use ensure and error handling instead of panicking
ngoldbaum 1aa8b1d
skip abi3 fixup on free-threaded build
ngoldbaum 3241d8b
don't support PYO3_USE_ABI3_FORWARD_COMPATIBILITY on free-threaded build
ngoldbaum dd7cca7
don't panic in pyo3-ffi in abi3 check
ngoldbaum 1814015
document lack of limited API support
ngoldbaum 72a12c1
add is_free_threaded() method to InterpreterConfig
ngoldbaum 139950e
implement David's code review suggestions
ngoldbaum efc167f
remove unused imports
ngoldbaum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| * Building extensions for the free-threaded ABI using Pythons ABIs older than 3.13 will now panic. |
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -691,6 +691,14 @@ pub struct PythonVersion { | |||||
| } | ||||||
|
|
||||||
| impl PythonVersion { | ||||||
| pub const PY313: Self = PythonVersion { | ||||||
| major: 3, | ||||||
| minor: 13, | ||||||
| }; | ||||||
| const PY310: Self = PythonVersion { | ||||||
| major: 3, | ||||||
| minor: 10, | ||||||
| }; | ||||||
| const PY37: Self = PythonVersion { major: 3, minor: 7 }; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -1606,11 +1614,9 @@ fn load_cross_compile_config( | |||||
| Ok(config) | ||||||
| } | ||||||
|
|
||||||
| // Link against python3.lib for the stable ABI on Windows. | ||||||
| // See https://www.python.org/dev/peps/pep-0384/#linkage | ||||||
| // | ||||||
| // This contains only the limited ABI symbols. | ||||||
| // These contains only the limited ABI symbols. | ||||||
| const WINDOWS_ABI3_LIB_NAME: &str = "python3"; | ||||||
| const WINDOWS_ABI3_DEBUG_LIB_NAME: &str = "python3_d"; | ||||||
|
|
||||||
| fn default_lib_name_for_target( | ||||||
| version: PythonVersion, | ||||||
|
|
@@ -1642,24 +1648,33 @@ fn default_lib_name_windows( | |||||
| debug: bool, | ||||||
| gil_disabled: bool, | ||||||
| ) -> String { | ||||||
| if debug { | ||||||
| if debug && version < PythonVersion::PY310 { | ||||||
| // CPython bug: linking against python3_d.dll raises error | ||||||
| // https://github.com/python/cpython/issues/101614 | ||||||
| if gil_disabled { | ||||||
| format!("python{}{}t_d", version.major, version.minor) | ||||||
| format!("python{}{}_d", version.major, version.minor) | ||||||
| } else if abi3 && !(implementation.is_pypy() || implementation.is_graalpy()) { | ||||||
| if debug { | ||||||
| WINDOWS_ABI3_DEBUG_LIB_NAME.to_owned() | ||||||
| } else { | ||||||
| format!("python{}{}_d", version.major, version.minor) | ||||||
| WINDOWS_ABI3_LIB_NAME.to_owned() | ||||||
| } | ||||||
| } else if abi3 && !(implementation.is_pypy() || implementation.is_graalpy()) { | ||||||
| WINDOWS_ABI3_LIB_NAME.to_owned() | ||||||
| } else if mingw { | ||||||
| if gil_disabled { | ||||||
| panic!("MinGW free-threaded builds are not currently tested or supported") | ||||||
| } | ||||||
| // https://packages.msys2.org/base/mingw-w64-python | ||||||
| format!("python{}.{}", version.major, version.minor) | ||||||
| } else if gil_disabled { | ||||||
| format!("python{}{}t", version.major, version.minor) | ||||||
| if version < PythonVersion::PY313 { | ||||||
| panic!("Cannot compile C extensions for the free-threaded build on Python versions earlier than 3.13, found {}.{}", version.major, version.minor); | ||||||
| } | ||||||
| if debug { | ||||||
| format!("python{}{}t_d", version.major, version.minor) | ||||||
| } else { | ||||||
| format!("python{}{}t", version.major, version.minor) | ||||||
| } | ||||||
| } else if debug { | ||||||
| format!("python{}{}_d", version.major, version.minor) | ||||||
| } else { | ||||||
| format!("python{}{}", version.major, version.minor) | ||||||
| } | ||||||
|
|
@@ -1678,6 +1693,9 @@ fn default_lib_name_unix( | |||||
| if version > PythonVersion::PY37 { | ||||||
| // PEP 3149 ABI version tags are finally gone | ||||||
| if gil_disabled { | ||||||
| if version < PythonVersion::PY313 { | ||||||
| panic!("Cannot compile C extensions for the free-threaded build on Python versions earlier than 3.13, found {}.{}", version.major, version.minor); | ||||||
| } | ||||||
| format!("python{}.{}t", version.major, version.minor) | ||||||
| } else { | ||||||
| format!("python{}.{}", version.major, version.minor) | ||||||
|
|
@@ -2392,6 +2410,17 @@ mod tests { | |||||
| ), | ||||||
| "python39", | ||||||
| ); | ||||||
| assert!(std::panic::catch_unwind(|| { | ||||||
| super::default_lib_name_windows( | ||||||
| PythonVersion { major: 3, minor: 9 }, | ||||||
| CPython, | ||||||
| false, | ||||||
| false, | ||||||
| false, | ||||||
| true, | ||||||
| ) | ||||||
| }) | ||||||
| .is_err()); | ||||||
| assert_eq!( | ||||||
| super::default_lib_name_windows( | ||||||
| PythonVersion { major: 3, minor: 9 }, | ||||||
|
|
@@ -2447,7 +2476,7 @@ mod tests { | |||||
| ), | ||||||
| "python39_d", | ||||||
| ); | ||||||
| // abi3 debug builds on windows use version-specific lib | ||||||
| // abi3 debug builds on windows use version-specific lib on 3.9 and older | ||||||
| // to workaround https://github.com/python/cpython/issues/101614 | ||||||
| assert_eq!( | ||||||
| super::default_lib_name_windows( | ||||||
|
|
@@ -2460,6 +2489,78 @@ mod tests { | |||||
| ), | ||||||
| "python39_d", | ||||||
| ); | ||||||
| assert_eq!( | ||||||
| super::default_lib_name_windows( | ||||||
| PythonVersion { | ||||||
| major: 3, | ||||||
| minor: 10 | ||||||
| }, | ||||||
| CPython, | ||||||
| true, | ||||||
| false, | ||||||
| true, | ||||||
| false, | ||||||
| ), | ||||||
| "python3_d", | ||||||
| ); | ||||||
| // Python versions older than 3.13 panic if gil_disabled is true | ||||||
|
||||||
| // Python versions older than 3.13 panic if gil_disabled is true | |
| // Python versions older than 3.13 don't support gil_disabled |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,9 +112,16 @@ fn ensure_python_version(interpreter_config: &InterpreterConfig) -> Result<()> { | |
| .0 | ||
| .contains(&BuildFlag::Py_GIL_DISABLED) | ||
| { | ||
| warn!( | ||
| let version = interpreter_config.version; | ||
| if version < PythonVersion::PY313 { | ||
| panic!( | ||
|
||
| "The free-threaded ABI is not defined for versions older than 3.13, tried to build using Python {}.{} ABI", version.major, version.minor | ||
| ); | ||
| } else { | ||
| warn!( | ||
| "The free-threaded build of CPython does not yet support abi3 so the build artifacts will be version-specific." | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| PythonImplementation::PyPy => warn!( | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.