-
Notifications
You must be signed in to change notification settings - Fork 761
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
Add abi3-py* features #1263
Add abi3-py* features #1263
Changes from all commits
597119d
93282e9
eae0d86
1b83850
6da6bc9
4914372
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,10 @@ use std::{ | |
str::FromStr, | ||
}; | ||
|
||
const PY3_MIN_MINOR: u8 = 5; | ||
/// Minimum required Python version. | ||
const PY3_MIN_MINOR: u8 = 6; | ||
/// Maximum Python version that can be used as minimum required Python version with abi3. | ||
const ABI3_MAX_MINOR: u8 = 9; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Binaries trying to link against a higher python version than the actual installed (And even worse, only extension modules on linux - because on windows they always link!) This would mean that an extension module which uses the |
||
const CFG_KEY: &str = "py_sys_config"; | ||
|
||
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>; | ||
|
@@ -770,12 +773,25 @@ fn configure(interpreter_config: &InterpreterConfig) -> Result<String> { | |
bail!("Python 2 is not supported"); | ||
} | ||
|
||
if env::var_os("CARGO_FEATURE_ABI3").is_some() { | ||
let minor = if env::var_os("CARGO_FEATURE_ABI3").is_some() { | ||
println!("cargo:rustc-cfg=Py_LIMITED_API"); | ||
} | ||
// Check any `abi3-py3*` feature is set. If not, use the interpreter version. | ||
let abi3_minor = (PY3_MIN_MINOR..=ABI3_MAX_MINOR) | ||
.find(|i| env::var_os(format!("CARGO_FEATURE_ABI3_PY3{}", i)).is_some()); | ||
match (abi3_minor, interpreter_config.version.minor) { | ||
(Some(abi3_minor), Some(interpreter_minor)) if abi3_minor > interpreter_minor => bail!( | ||
"You cannot set a mininimum Python version {} higher than the interpreter version {}", | ||
abi3_minor, | ||
interpreter_minor | ||
), | ||
_ => abi3_minor.or(interpreter_config.version.minor), | ||
} | ||
} else { | ||
interpreter_config.version.minor | ||
}; | ||
|
||
if let Some(minor) = interpreter_config.version.minor { | ||
for i in 6..=minor { | ||
if let Some(minor) = minor { | ||
for i in PY3_MIN_MINOR..=minor { | ||
println!("cargo:rustc-cfg=Py_3_{}", i); | ||
flags += format!("CFG_Py_3_{},", i).as_ref(); | ||
} | ||
|
@@ -820,7 +836,26 @@ fn check_target_architecture(interpreter_config: &InterpreterConfig) -> Result<( | |
Ok(()) | ||
} | ||
|
||
fn abi3_without_interpreter() -> Result<()> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a good start, in the future I think we can replace this with something more flexible. See this discussion with the PyOxidiser maintainer who suggested if PyOxidiser used PyO3 they would like the ability to set an environment variable with a path to a JSON file which configures PyO3: indygreg/PyOxidizer#324 (comment) |
||
println!("cargo:rustc-cfg=Py_LIMITED_API"); | ||
let mut flags = "FLAG_WITH_THREAD=1".to_string(); | ||
for minor in PY3_MIN_MINOR..=ABI3_MAX_MINOR { | ||
println!("cargo:rustc-cfg=Py_3_{}", minor); | ||
flags += &format!(",CFG_Py_3_{}", minor); | ||
} | ||
println!("cargo:rustc-cfg=py_sys_config=\"WITH_THREAD\""); | ||
println!("cargo:python_flags={}", flags); | ||
Ok(()) | ||
} | ||
|
||
fn main() -> Result<()> { | ||
// If PYO3_NO_PYTHON is set with abi3, we can build PyO3 without calling Python (UNIX only). | ||
// We only check for the abi3-py3{ABI3_MAX_MINOR} because lower versions depend on it. | ||
if env::var_os("PYO3_NO_PYTHON").is_some() | ||
&& env::var_os(format!("CARGO_FEATURE_ABI3_PY3{}", ABI3_MAX_MINOR)).is_some() | ||
{ | ||
return abi3_without_interpreter(); | ||
} | ||
// 1. Setup cfg variables so we can do conditional compilation in this library based on the | ||
// python interpeter's compilation flags. This is necessary for e.g. matching the right unicode | ||
// and threading interfaces. First check if we're cross compiling, if so, we cannot run the | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR, but we dropped 3.5 support in #1250.