Skip to content

Commit

Permalink
Merge pull request #1991 from messense/pypy-abi3
Browse files Browse the repository at this point in the history
Don't emit `Py_LIMITED_API` cfg for PyPy
  • Loading branch information
davidhewitt committed Nov 15, 2021
2 parents 9ae7e31 + f015951 commit 8e41483
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -211,6 +211,10 @@ jobs:
- name: Build (all additive features)
run: cargo build --lib --tests --no-default-features --features "${{ steps.settings.outputs.all_additive_features }}"

- if: ${{ startsWith(matrix.python-version, 'pypy') }}
name: Build PyPy (abi3-py36)
run: cargo build --lib --tests --no-default-features --features "abi3-py36 ${{ steps.settings.outputs.all_additive_features }}"

# Run tests (except on PyPy, because no embedding API).
- if: ${{ !startsWith(matrix.python-version, 'pypy') }}
name: Test
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix creating `#[classattr]` by functions with the name of a known magic method. [#1969](https://github.com/PyO3/pyo3/pull/1969)
- Fix build failure on PyPy when abi3 features are activated. [#1991](https://github.com/PyO3/pyo3/pull/1991)
- Fix mingw platform detection. [#1993](https://github.com/PyO3/pyo3/pull/1993)

## [0.15.0] - 2021-11-03
Expand Down
69 changes: 56 additions & 13 deletions pyo3-build-config/src/impl_.rs
Expand Up @@ -135,10 +135,6 @@ impl InterpreterConfig {
println!("cargo:rustc-cfg=Py_3_{}", i);
}

if self.abi3 {
println!("cargo:rustc-cfg=Py_LIMITED_API");
}

if self.implementation.is_pypy() {
println!("cargo:rustc-cfg=PyPy");
if self.abi3 {
Expand All @@ -147,7 +143,9 @@ impl InterpreterConfig {
See https://foss.heptapod.net/pypy/pypy/-/issues/3397 for more information."
);
}
};
} else if self.abi3 {
println!("cargo:rustc-cfg=Py_LIMITED_API");
}

for flag in &self.build_flags.0 {
println!("cargo:rustc-cfg=py_sys_config=\"{}\"", flag)
Expand Down Expand Up @@ -221,7 +219,12 @@ print("mingw", get_platform().startswith("mingw"))
let implementation = map["implementation"].parse()?;

let lib_name = if cfg!(windows) {
default_lib_name_windows(version, abi3, map["mingw"].as_str() == "True")
default_lib_name_windows(
version,
implementation,
abi3,
map["mingw"].as_str() == "True",
)
} else {
default_lib_name_unix(
version,
Expand Down Expand Up @@ -989,7 +992,12 @@ fn windows_hardcoded_cross_compile(
version,
shared: true,
abi3,
lib_name: Some(default_lib_name_windows(version, abi3, false)),
lib_name: Some(default_lib_name_windows(
version,
PythonImplementation::CPython,
abi3,
false,
)),
lib_dir: cross_compile_config.lib_dir.to_str().map(String::from),
executable: None,
pointer_width: None,
Expand Down Expand Up @@ -1028,8 +1036,13 @@ fn load_cross_compile_config(
// This contains only the limited ABI symbols.
const WINDOWS_ABI3_LIB_NAME: &str = "python3";

fn default_lib_name_windows(version: PythonVersion, abi3: bool, mingw: bool) -> String {
if abi3 {
fn default_lib_name_windows(
version: PythonVersion,
implementation: PythonImplementation,
abi3: bool,
mingw: bool,
) -> String {
if abi3 && !implementation.is_pypy() {
WINDOWS_ABI3_LIB_NAME.to_owned()
} else if mingw {
// https://packages.msys2.org/base/mingw-w64-python
Expand Down Expand Up @@ -1389,22 +1402,52 @@ mod tests {

#[test]
fn default_lib_name_windows() {
use PythonImplementation::*;
assert_eq!(
super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, false, false),
super::default_lib_name_windows(
PythonVersion { major: 3, minor: 6 },
CPython,
false,
false
),
"python36",
);
assert_eq!(
super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, true, false),
super::default_lib_name_windows(
PythonVersion { major: 3, minor: 6 },
CPython,
true,
false
),
"python3",
);
assert_eq!(
super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, false, true),
super::default_lib_name_windows(
PythonVersion { major: 3, minor: 6 },
CPython,
false,
true
),
"python3.6",
);
assert_eq!(
super::default_lib_name_windows(PythonVersion { major: 3, minor: 6 }, true, true),
super::default_lib_name_windows(
PythonVersion { major: 3, minor: 6 },
CPython,
true,
true
),
"python3",
);
assert_eq!(
super::default_lib_name_windows(
PythonVersion { major: 3, minor: 6 },
PyPy,
true,
false
),
"python36",
);
}

#[test]
Expand Down

0 comments on commit 8e41483

Please sign in to comment.