Skip to content

Commit

Permalink
error when building with limited api and Py_GIL_DISABLED
Browse files Browse the repository at this point in the history
  • Loading branch information
ngoldbaum committed Aug 6, 2024
1 parent e74ab2e commit a654993
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 8 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import shutil
import subprocess
import sys
import sysconfig
import tempfile
from functools import lru_cache
from glob import glob
Expand Down Expand Up @@ -32,6 +33,7 @@
PYO3_DOCS_TARGET = PYO3_TARGET / "doc"
PY_VERSIONS = ("3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13")
PYPY_VERSIONS = ("3.7", "3.8", "3.9", "3.10")
IS_FREE_THREADED = bool(sysconfig.get_config_var("Py_GIL_DISABLED"))


@nox.session(venv_backend="none")
Expand Down Expand Up @@ -783,6 +785,12 @@ def _get_rust_default_target() -> str:
def _get_feature_sets() -> Tuple[Tuple[str, ...], ...]:
"""Returns feature sets to use for clippy job"""
cargo_target = os.getenv("CARGO_BUILD_TARGET", "")
if IS_FREE_THREADED:
# abi3 and free-threaded builds are incompatible
return (
("--no-default-features",),
("--features=full multiple-pymethods",),
)
if "wasm32-wasi" not in cargo_target:
# multiple-pymethods not supported on wasm
return (
Expand Down
18 changes: 15 additions & 3 deletions pyo3-build-config/src/impl_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,12 @@ print("ext_suffix", get_config_var("EXT_SUFFIX"))
.parse()
.context("failed to parse calcsize_pointer")?;

let build_flags: BuildFlags = BuildFlags::from_interpreter(interpreter)?;

if build_flags.0.contains(&BuildFlag::Py_GIL_DISABLED) && abi3 {
bail!("Cannot set Py_LIMITED_API and Py_GIL_DISABLED at the same time")
}

Ok(InterpreterConfig {
version,
implementation,
Expand All @@ -334,7 +340,7 @@ print("ext_suffix", get_config_var("EXT_SUFFIX"))
lib_dir,
executable: map.get("executable").cloned(),
pointer_width: Some(calcsize_pointer * 8),
build_flags: BuildFlags::from_interpreter(interpreter)?,
build_flags,
suppress_build_script_link_lines: false,
extra_build_script_lines: vec![],
})
Expand Down Expand Up @@ -488,6 +494,12 @@ print("ext_suffix", get_config_var("EXT_SUFFIX"))
}
});

let build_flags: BuildFlags = build_flags.unwrap_or_default();

if build_flags.0.contains(&BuildFlag::Py_GIL_DISABLED) && abi3 {
bail!("Cannot set Py_LIMITED_API and Py_GIL_DISABLED at the same time")
}

Ok(InterpreterConfig {
implementation,
version,
Expand All @@ -497,7 +509,7 @@ print("ext_suffix", get_config_var("EXT_SUFFIX"))
lib_dir,
executable,
pointer_width,
build_flags: build_flags.unwrap_or_default(),
build_flags,
suppress_build_script_link_lines: suppress_build_script_link_lines.unwrap_or(false),
extra_build_script_lines,
})
Expand Down Expand Up @@ -2753,7 +2765,7 @@ mod tests {
lib_dir: None,
executable: None,
pointer_width: None,
build_flags: build_flags,
build_flags,
suppress_build_script_link_lines: false,
extra_build_script_lines: vec![],
};
Expand Down

0 comments on commit a654993

Please sign in to comment.