Skip to content

Commit 1eb6b06

Browse files
committed
graalpy: Bail out if graalpy version is less than what we support
1 parent 366a3b2 commit 1eb6b06

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pyo3-build-config/src/impl_.rs

+31
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ use crate::{
3232
/// Minimum Python version PyO3 supports.
3333
const MINIMUM_SUPPORTED_VERSION: PythonVersion = PythonVersion { major: 3, minor: 7 };
3434

35+
/// GraalPy may implement the same CPython version over multiple releases.
36+
const MINIMUM_SUPPORTED_VERSION_GRAALPY: PythonVersion = PythonVersion {
37+
major: 24,
38+
minor: 0,
39+
};
40+
3541
/// Maximum Python version that can be used as minimum required Python version with abi3.
3642
const ABI3_MAX_MINOR: u8 = 12;
3743

@@ -204,6 +210,11 @@ from sysconfig import get_config_var, get_platform
204210
PYPY = platform.python_implementation() == "PyPy"
205211
GRAALPY = platform.python_implementation() == "GraalVM"
206212
213+
if GRAALPY:
214+
graalpy_ver = map(int, __graalpython__.get_graalvm_version().split('.'));
215+
print("graalpy_major", next(graalpy_ver))
216+
print("graalpy_minor", next(graalpy_ver))
217+
207218
# sys.base_prefix is missing on Python versions older than 3.3; this allows the script to continue
208219
# so that the version mismatch can be reported in a nicer way later.
209220
base_prefix = getattr(sys, "base_prefix", None)
@@ -250,6 +261,26 @@ print("ext_suffix", get_config_var("EXT_SUFFIX"))
250261
interpreter.as_ref().display()
251262
);
252263

264+
match map.get("graalpy_major") {
265+
Some(value) => {
266+
let graalpy_version = PythonVersion {
267+
major: value
268+
.parse()
269+
.context("failed to parse GraalPy major version")?,
270+
minor: map["graalpy_minor"]
271+
.parse()
272+
.context("failed to parse GraalPy minor version")?,
273+
};
274+
ensure!(
275+
graalpy_version >= MINIMUM_SUPPORTED_VERSION_GRAALPY,
276+
"At least GraalPy version {} needed, got {}",
277+
MINIMUM_SUPPORTED_VERSION_GRAALPY,
278+
graalpy_version
279+
);
280+
}
281+
None => (),
282+
};
283+
253284
let shared = map["shared"].as_str() == "True";
254285

255286
let version = PythonVersion {

0 commit comments

Comments
 (0)