Skip to content

Commit 151fe7f

Browse files
committed
feat: Add ImportLibraryGenerator::abiflags() method
Allow specifying the generated import library ABI flags as well as the interpreter version. Only `"t"` is currently supported as the ABI flags parameter value and only for CPython v3.13.
1 parent 8e9b33b commit 151fe7f

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/lib.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ pub struct ImportLibraryGenerator {
175175
version: Option<(u8, u8)>,
176176
/// Python interpreter implementation
177177
implementation: PythonImplementation,
178+
/// Optional Python ABI flags
179+
///
180+
/// For example, `"t"` stands for the free-threaded CPython v3.13 build
181+
/// aka CPython `3.13t`.
182+
abiflags: Option<String>,
178183
}
179184

180185
impl ImportLibraryGenerator {
@@ -186,11 +191,12 @@ impl ImportLibraryGenerator {
186191
/// The compile target environment ABI name (as in `CARGO_CFG_TARGET_ENV`)
187192
/// is passed in `env`.
188193
pub fn new(arch: &str, env: &str) -> Self {
189-
Self {
194+
ImportLibraryGenerator {
190195
arch: arch.to_string(),
191196
env: env.to_string(),
192197
version: None,
193198
implementation: PythonImplementation::CPython,
199+
abiflags: None,
194200
}
195201
}
196202

@@ -202,6 +208,19 @@ impl ImportLibraryGenerator {
202208
self
203209
}
204210

211+
/// Sets the ABI flags for the `pythonXY<abi>.dll` import library.
212+
///
213+
/// For example, `"t"` stands for the free-threaded CPython v3.13 build
214+
/// aka CPython `3.13t`.
215+
/// In this case, `python313t.dll` import library will be generated.
216+
///
217+
/// The untagged versioned `pythonXY.dll` import library
218+
/// is generated by default.
219+
pub fn abiflags(&mut self, flags: Option<&str>) -> &mut Self {
220+
self.abiflags = flags.map(ToOwned::to_owned);
221+
self
222+
}
223+
205224
/// Sets Python interpreter implementation
206225
pub fn implementation(&mut self, implementation: PythonImplementation) -> &mut Self {
207226
self.implementation = implementation;
@@ -256,7 +275,11 @@ impl ImportLibraryGenerator {
256275
Some((3, 10)) => ("python310.def", include_str!("python310.def")),
257276
Some((3, 11)) => ("python311.def", include_str!("python311.def")),
258277
Some((3, 12)) => ("python312.def", include_str!("python312.def")),
259-
Some((3, 13)) => ("python313.def", include_str!("python313.def")),
278+
Some((3, 13)) => match self.abiflags.as_deref() {
279+
Some("t") => ("python313t.def", include_str!("python313t.def")),
280+
None => ("python313.def", include_str!("python313.def")),
281+
_ => return Err(Error::new(ErrorKind::Other, "Unsupported Python ABI flags")),
282+
},
260283
_ => return Err(Error::new(ErrorKind::Other, "Unsupported Python version")),
261284
},
262285
PythonImplementation::PyPy => match self.version {

0 commit comments

Comments
 (0)