Skip to content

Commit 05244cf

Browse files
authored
Add builtin sysconfigs for GraalPy (#2716)
Add sysconfigs to allow building GraalPy wheels in common maturin-action workflows.
1 parent c01299d commit 05244cf

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ classifiers = [
2424
"Programming Language :: Rust",
2525
"Programming Language :: Python :: Implementation :: CPython",
2626
"Programming Language :: Python :: Implementation :: PyPy",
27+
"Programming Language :: Python :: Implementation :: GraalPy",
2728
]
2829
dependencies = ["tomli>=1.1.0 ; python_version<'3.11'"]
2930
dynamic = ["version"]

src/python_interpreter/config.rs

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,21 @@ use std::io::{BufRead, BufReader};
1212
use std::path::Path;
1313

1414
const PYPY_ABI_TAG: &str = "pp73";
15-
const GRAALPY_ABI_TAG: &str = "graalpy230_310_native";
15+
16+
fn graalpy_version_for_python_version(major: usize, minor: usize) -> Option<(usize, usize)> {
17+
match (major, minor) {
18+
(3, 10) => Some((24, 0)),
19+
(3, 11) => Some((24, 2)),
20+
// Since 25.0, GraalPy should only change the major release number for feature releases.
21+
// Additionally, it promises that only the autumn (oddly-numbered) releases are
22+
// allowed to break ABI compatibility, so only those can change the Python version.
23+
// The even-numbered releases will report the ABI version of the previous release.
24+
// So assuming that GraalPy doesn't fall terribly behind on updating Python version,
25+
// the version used in the ABI should follow this formula
26+
(3, 12..) => Some((25 + (minor - 12) * 2, 0)),
27+
(_, _) => None,
28+
}
29+
}
1630

1731
/// Some of the sysconfigdata of Python interpreter we care about
1832
#[derive(Debug, Clone, Deserialize, Eq, PartialEq)]
@@ -92,6 +106,20 @@ impl InterpreterConfig {
92106
gil_disabled,
93107
})
94108
}
109+
(Os::Linux, GraalPy) => {
110+
let (graalpy_major, graalpy_minor) =
111+
graalpy_version_for_python_version(major, minor)?;
112+
let ext_suffix = format!(".graalpy{graalpy_major}{graalpy_minor}-{major}{minor}-native-{python_ext_arch}-linux.so");
113+
Some(Self {
114+
major,
115+
minor,
116+
interpreter_kind: GraalPy,
117+
abiflags: String::new(),
118+
ext_suffix,
119+
pointer_width: Some(target.pointer_width()),
120+
gil_disabled,
121+
})
122+
}
95123
(Os::Macos, CPython) => {
96124
let abiflags = if python_version < (3, 8) {
97125
"m".to_string()
@@ -122,6 +150,20 @@ impl InterpreterConfig {
122150
gil_disabled,
123151
})
124152
}
153+
(Os::Macos, GraalPy) => {
154+
let (graalpy_major, graalpy_minor) =
155+
graalpy_version_for_python_version(major, minor)?;
156+
let ext_suffix = format!(".graalpy{graalpy_major}{graalpy_minor}-{major}{minor}-native-{python_ext_arch}-darwin.so");
157+
Some(Self {
158+
major,
159+
minor,
160+
interpreter_kind: GraalPy,
161+
abiflags: String::new(),
162+
ext_suffix,
163+
pointer_width: Some(target.pointer_width()),
164+
gil_disabled,
165+
})
166+
}
125167
(Os::Windows, CPython) => {
126168
let abiflags = if python_version < (3, 8) {
127169
"m".to_string()
@@ -319,7 +361,11 @@ impl InterpreterConfig {
319361
}
320362
}
321363
InterpreterKind::PyPy => abi_tag.unwrap_or_else(|| PYPY_ABI_TAG.to_string()),
322-
InterpreterKind::GraalPy => abi_tag.unwrap_or_else(|| GRAALPY_ABI_TAG.to_string()),
364+
InterpreterKind::GraalPy => abi_tag.unwrap_or_else(|| {
365+
let (graalpy_major, graalpy_minor) =
366+
graalpy_version_for_python_version(major, minor).unwrap_or((23, 0));
367+
format!("graalpy{graalpy_major}{graalpy_minor}_{major}{minor}_native")
368+
}),
323369
};
324370
let file_ext = if target.is_windows() { "pyd" } else { "so" };
325371
let ext_suffix = if target.is_linux() || target.is_macos() || target.is_hurd() {

src/python_interpreter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ impl fmt::Display for InterpreterKind {
325325
match *self {
326326
InterpreterKind::CPython => write!(f, "CPython"),
327327
InterpreterKind::PyPy => write!(f, "PyPy"),
328-
InterpreterKind::GraalPy => write!(f, "GraalPy"),
328+
InterpreterKind::GraalPy => write!(f, "GraalVM"),
329329
}
330330
}
331331
}

0 commit comments

Comments
 (0)