Skip to content

Commit 337a6e3

Browse files
committed
Initial support for abi3t, depends on unreleased PyO3 features.
1 parent da71d84 commit 337a6e3

4 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/binding_generator/pyo3_binding.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ pub struct Pyo3BindingGenerator<'a> {
3838

3939
enum BindingType<'a> {
4040
Abi3(Option<&'a PythonInterpreter>),
41+
Abi3t(Option<&'a PythonInterpreter>),
4142
VersionSpecific(&'a PythonInterpreter),
4243
}
4344

@@ -50,6 +51,7 @@ impl<'a> Pyo3BindingGenerator<'a> {
5051
let binding_type = match stable_abi {
5152
Some(kind) => match kind {
5253
StableAbiKind::Abi3 => BindingType::Abi3(interpreter),
54+
StableAbiKind::Abi3t => BindingType::Abi3t(interpreter),
5355
},
5456
None => {
5557
let interpreter = interpreter.ok_or_else(|| {
@@ -102,6 +104,7 @@ impl<'a> BindingGenerator for Pyo3BindingGenerator<'a> {
102104

103105
let so_filename = match self.binding_type {
104106
BindingType::Abi3(interpreter) => ext_suffix(target, interpreter, ext_name, "abi3"),
107+
BindingType::Abi3t(interpreter) => ext_suffix(target, interpreter, ext_name, "abi3t"),
105108
BindingType::VersionSpecific(interpreter) => interpreter.get_library_name(ext_name),
106109
};
107110
let artifact_target = ArtifactTarget::ExtensionModule(module.join(so_filename));

src/bridge/detection.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ fn has_stable_abi(
184184
if abi3.is_some() {
185185
return Ok(abi3);
186186
}
187-
Ok(None)
187+
has_stable_abi_from_kind(deps, extra_features, StableAbiKind::Abi3t)
188188
}
189189

190190
/// pyo3 supports building stable abi wheels if the unstable-api feature is not selected

src/bridge/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ impl StableAbi {
131131
version: StableAbiVersion::Version(major, minor),
132132
}
133133
}
134+
135+
/// Create a StableAbi instance from a known abi3t version
136+
pub fn from_abi3t_version(major: u8, minor: u8) -> StableAbi {
137+
StableAbi {
138+
kind: StableAbiKind::Abi3t,
139+
version: StableAbiVersion::Version(major, minor),
140+
}
141+
}
134142
}
135143

136144
/// Python version to use as the abi3/abi3t target.
@@ -145,7 +153,7 @@ pub enum StableAbiVersion {
145153
}
146154

147155
impl StableAbiVersion {
148-
/// Convert `StableAbiVersion` into an Option, where CurrentPython maps None
156+
/// Convert `StableAbiVersion` into an Option, where CurrentPython maps to None
149157
pub fn min_version(&self) -> Option<(u8, u8)> {
150158
match self {
151159
StableAbiVersion::CurrentPython => None,
@@ -159,12 +167,15 @@ impl StableAbiVersion {
159167
pub enum StableAbiKind {
160168
/// The original stable ABI, supporting Python 3.2 and up
161169
Abi3,
170+
/// The free-threaded stable ABI, supporting Python 3.15 and up
171+
Abi3t,
162172
}
163173

164174
impl fmt::Display for StableAbiKind {
165175
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
166176
match self {
167177
StableAbiKind::Abi3 => write!(f, "abi3"),
178+
StableAbiKind::Abi3t => write!(f, "abi3t"),
168179
}
169180
}
170181
}
@@ -174,6 +185,7 @@ impl StableAbiKind {
174185
pub fn wheel_tag(&self) -> &str {
175186
match self {
176187
StableAbiKind::Abi3 => "abi3",
188+
StableAbiKind::Abi3t => "abi3.abi3t",
177189
}
178190
}
179191
}
@@ -341,6 +353,7 @@ impl BridgeModel {
341353
.and_then(|pyo3| match pyo3.stable_abi {
342354
Some(stable_abi) => match stable_abi.kind {
343355
StableAbiKind::Abi3 => Some(true),
356+
_ => None,
344357
},
345358
None => None,
346359
})

src/build_orchestrator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,15 +286,15 @@ impl<'a> BuildOrchestrator<'a> {
286286
let interp = &self.context.python.interpreter[0];
287287
match bindings.stable_abi {
288288
Some(stable_abi) => {
289-
let wheel_tag = stable_abi.kind.wheel_tag();
289+
let abi_tag = stable_abi.kind.abi_tag();
290290

291291
match stable_abi.version {
292292
StableAbiVersion::Version(major, minor) => {
293-
vec![format!("cp{major}{minor}-{wheel_tag}-{platform}")]
293+
vec![format!("cp{major}{minor}-{abi_tag}-{platform}")]
294294
}
295295
StableAbiVersion::CurrentPython => {
296296
vec![format!(
297-
"cp{major}{minor}-{wheel_tag}-{platform}",
297+
"cp{major}{minor}-{abi_tag}-{platform}",
298298
major = interp.major,
299299
minor = interp.minor
300300
)]

0 commit comments

Comments
 (0)