Skip to content

Commit

Permalink
Add default value for ext_suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed May 5, 2022
1 parent ebe8267 commit 164f888
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/build_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ pub fn find_interpreter(
});
} else if let Some(config_file) = env::var_os("PYO3_CONFIG_FILE") {
let interpreter_config =
InterpreterConfig::from_pyo3_config(config_file.as_ref())
InterpreterConfig::from_pyo3_config(config_file.as_ref(), target)
.context("Invalid PYO3_CONFIG_FILE")?;
interpreters.push(PythonInterpreter::from_config(interpreter_config));
} else {
Expand Down
49 changes: 43 additions & 6 deletions src/python_interpreter/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::InterpreterKind;
use crate::target::{Arch, Os};
use crate::Target;
use anyhow::{format_err, Context, Result};
use fs_err as fs;
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -67,7 +68,7 @@ impl InterpreterConfig {
}

/// Construct a new InterpreterConfig from a pyo3 config file
pub fn from_pyo3_config(config_file: &Path) -> Result<Self> {
pub fn from_pyo3_config(config_file: &Path, target: &Target) -> Result<Self> {
let config_file = fs::File::open(config_file)?;
let reader = BufReader::new(config_file);
let lines = reader.lines();
Expand Down Expand Up @@ -125,24 +126,60 @@ impl InterpreterConfig {
})?;
let implementation = implementation.unwrap_or_else(|| "cpython".to_string());
let interpreter_kind = implementation.parse().map_err(|e| format_err!("{}", e))?;
let ext_suffix = ext_suffix.context("missing value for ext_suffix")?;
let abi_tag = match interpreter_kind {
InterpreterKind::CPython => {
if (major, minor) >= (3, 8) {
abi_tag.or_else(|| Some(format!("{}{}", major, minor)))
abi_tag.unwrap_or_else(|| format!("{}{}", major, minor))
} else {
abi_tag.or_else(|| Some(format!("{}{}m", major, minor)))
abi_tag.unwrap_or_else(|| format!("{}{}m", major, minor))
}
}
InterpreterKind::PyPy => abi_tag.or_else(|| Some("pp73".to_string())),
InterpreterKind::PyPy => abi_tag.unwrap_or_else(|| "pp73".to_string()),
};
let file_ext = if target.is_windows() { "pyd" } else { "so" };
let ext_suffix = if target.is_linux() || target.is_macos() {
// See https://github.com/pypa/auditwheel/issues/349
let target_env = if (major, minor) >= (3, 11) {
target.target_env().to_string()
} else {
"gnu".to_string()
};
match interpreter_kind {
InterpreterKind::CPython => ext_suffix.unwrap_or_else(|| {
// Eg: .cpython-38-x86_64-linux-gnu.so
format!(
".cpython-{}-{}-{}-{}.{}",
abi_tag,
target.get_python_arch(),
target.get_python_os(),
target_env,
file_ext,
)
}),
InterpreterKind::PyPy => ext_suffix.unwrap_or_else(|| {
// Eg: .pypy38-pp73-x86_64-linux-gnu.so
format!(
".pypy{}{}-{}-{}-{}-{}.{}",
major,
minor,
abi_tag,
target.get_python_arch(),
target.get_python_os(),
target_env,
file_ext,
)
}),
}
} else {
ext_suffix.context("missing value for ext_suffix")?
};
Ok(Self {
major,
minor,
interpreter_kind,
abiflags: abiflags.unwrap_or_default(),
ext_suffix,
abi_tag,
abi_tag: Some(abi_tag),
pointer_width,
})
}
Expand Down
18 changes: 18 additions & 0 deletions src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,19 @@ impl Target {
Ok(tag)
}

/// Returns the name python uses in `sys.platform` for this architecture.
pub fn get_python_arch(&self) -> &str {
match self.arch {
Arch::Aarch64 => "aarch64",
Arch::Armv7L => "armv7l",
Arch::Powerpc64Le => "powerpc64le",
Arch::Powerpc64 => "powerpc64",
Arch::X86 => "i386",
Arch::X86_64 => "x86_64",
Arch::S390X => "s390x",
}
}

/// Returns the name python uses in `sys.platform` for this os
pub fn get_python_os(&self) -> &str {
match self.os {
Expand Down Expand Up @@ -364,6 +377,11 @@ impl Target {
self.arch
}

/// Returns target environment
pub fn target_env(&self) -> Environment {
self.env
}

/// Returns true if the current platform is linux
pub fn is_linux(&self) -> bool {
self.os == Os::Linux
Expand Down

0 comments on commit 164f888

Please sign in to comment.