Skip to content
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

Fix wrong EXT_SUFFIX when cross compiling musllinux wheels for Python 3.11 #1560

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Bump MSRV to 1.64.0 in [#1528](https://github.com/PyO3/maturin/pull/1528)
* Add wildcards support to publish/upload commands on Windows in [#1534](https://github.com/PyO3/maturin/pull/1534)
* Add support for configuring macOS deployment target version in `pyproject.toml` in [#1536](https://github.com/PyO3/maturin/pull/1536)
* Fix wrong `EXT_SUFFIX` when cross compiling musllinux wheels for Python 3.11 in [#1560](https://github.com/PyO3/maturin/pull/1560)

## [0.14.16] - 2023-03-26

Expand Down
13 changes: 4 additions & 9 deletions src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1149,15 +1149,10 @@ fn find_interpreter_in_sysconfig(
let ver_minor = ver_minor.parse::<usize>().with_context(|| {
format!("Invalid python interpreter minor version '{ver_minor}', expect a digit")
})?;
let sysconfig = InterpreterConfig::lookup(
target.target_os(),
target.target_arch(),
python_impl,
(ver_major, ver_minor),
)
.with_context(|| {
format!("Failed to find a {python_impl} {ver_major}.{ver_minor} interpreter")
})?;
let sysconfig = InterpreterConfig::lookup(target, python_impl, (ver_major, ver_minor))
.with_context(|| {
format!("Failed to find a {python_impl} {ver_major}.{ver_minor} interpreter")
})?;
debug!(
"Found {} {}.{} in bundled sysconfig",
sysconfig.interpreter_kind, sysconfig.major, sysconfig.minor,
Expand Down
49 changes: 39 additions & 10 deletions src/python_interpreter/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,28 @@ pub struct InterpreterConfig {
impl InterpreterConfig {
/// Lookup a wellknown sysconfig for a given Python interpreter
pub fn lookup(
os: Os,
arch: Arch,
target: &Target,
python_impl: InterpreterKind,
python_version: (usize, usize),
) -> Option<&'static Self> {
) -> Option<Self> {
let (major, minor) = python_version;
if let Some(os_sysconfigs) = WELLKNOWN_SYSCONFIG.get(&os) {
if let Some(sysconfigs) = os_sysconfigs.get(&arch) {
return sysconfigs.iter().find(|s| {
s.interpreter_kind == python_impl && s.major == major && s.minor == minor
if let Some(os_sysconfigs) = WELLKNOWN_SYSCONFIG.get(&target.target_os()) {
if let Some(sysconfigs) = os_sysconfigs.get(&target.target_arch()) {
return sysconfigs.iter().find_map(|s| {
if s.interpreter_kind == python_impl && s.major == major && s.minor == minor {
if python_version >= (3, 11) && target.is_musl_target() {
// See https://github.com/pypa/auditwheel/issues/349
let mut musl_config = s.clone();
musl_config.ext_suffix = s
.ext_suffix
.replace("-gnu", &format!("-{}", target.target_env()));
Some(musl_config)
} else {
Some(s.clone())
}
} else {
None
}
});
}
}
Expand Down Expand Up @@ -255,10 +267,27 @@ mod test {

#[test]
fn test_pyo3_config_file() {
let sysconfig =
InterpreterConfig::lookup(Os::Linux, Arch::X86_64, InterpreterKind::CPython, (3, 10))
.unwrap();
let sysconfig = InterpreterConfig::lookup(
&Target::from_target_triple(Some("x86_64-unknown-linux-gnu".to_string())).unwrap(),
InterpreterKind::CPython,
(3, 10),
)
.unwrap();
assert_eq!(sysconfig.ext_suffix, ".cpython-310-x86_64-linux-gnu.so");
let config_file = sysconfig.pyo3_config_file();
assert_eq!(config_file, "implementation=CPython\nversion=3.10\nshared=true\nabi3=false\nbuild_flags=WITH_THREAD\nsuppress_build_script_link_lines=false\npointer_width=64");
}

#[test]
fn test_pyo3_config_file_musl_python_3_11() {
let sysconfig = InterpreterConfig::lookup(
&Target::from_target_triple(Some("x86_64-unknown-linux-musl".to_string())).unwrap(),
InterpreterKind::CPython,
(3, 11),
)
.unwrap();
assert_eq!(sysconfig.ext_suffix, ".cpython-311-x86_64-linux-musl.so");
let config_file = sysconfig.pyo3_config_file();
assert_eq!(config_file, "implementation=CPython\nversion=3.11\nshared=true\nabi3=false\nbuild_flags=WITH_THREAD\nsuppress_build_script_link_lines=false\npointer_width=64");
}
}