Skip to content

Commit 17e2a48

Browse files
committed
docs: Update crate doc comments and README
Add doctests for `ImportLibraryGenerator`.
1 parent 67a653d commit 17e2a48

File tree

2 files changed

+59
-10
lines changed

2 files changed

+59
-10
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ Generates import libraries for the Python DLL
55
(either `python3.dll` or `python3y.dll`)
66
for MinGW-w64 and MSVC (cross-)compile targets.
77

8-
See <https://docs.python.org/3/c-api/stable.html> for the Stable ABI details.
9-
108
This crate **does not require** Python 3 distribution files
119
to be present on the (cross-)compile host system.
1210

13-
**Note:** MSVC cross-compile targets require LLVM binutils
14-
to be available on the host system.
11+
**Note:** MSVC cross-compile targets require either LLVM binutils
12+
or Zig to be available on the host system.
1513
More specifically, `python3-dll-a` requires `llvm-dlltool` executable
1614
to be present in `PATH` when targeting `*-pc-windows-msvc` from Linux.
1715

16+
Alternatively, `ZIG_COMMAND` environment variable may be set to e.g. "zig"
17+
or "python -m ziglang", then `zig dlltool` will be used in place
18+
of `llvm-dlltool` (or MinGW binutils).
19+
1820
PyO3 integration
1921
----------------
2022

@@ -42,7 +44,7 @@ from the crate build script.
4244

4345
The examples below assume using an older version of PyO3.
4446

45-
### Example `build.rs` script
47+
### Example `build.rs` script for an `abi3` PyO3 extension
4648

4749
The following cargo build script can be used to cross-compile Stable ABI
4850
PyO3 extension modules for Windows (64/32-bit x86 or 64-bit ARM)
@@ -73,6 +75,14 @@ pointed by the `PYO3_CROSS_LIB_DIR` environment variable.
7375
PYO3_CROSS_LIB_DIR=target/python3-dll cargo build --target x86_64-pc-windows-gnu
7476
```
7577

78+
Generating version-specific `python3y.dll` import libraries
79+
-----------------------------------------------------------
80+
81+
As an advanced feature, `python3-dll-a` can generate Python version
82+
specific import libraries such as `python39.lib`.
83+
84+
See the `ImportLibraryGenerator` builder API description for details.
85+
7686
Maintenance
7787
-----------
7888

src/lib.rs

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
//! (either `python3.dll` or `python3y.dll`)
66
//! for MinGW-w64 and MSVC (cross-)compile targets.
77
//!
8-
//! See <https://docs.python.org/3/c-api/stable.html> for the Stable ABI details.
9-
//!
108
//! This crate **does not require** Python 3 distribution files
119
//! to be present on the (cross-)compile host system.
1210
//!
13-
//! **Note:** MSVC cross-compile targets require LLVM binutils
14-
//! to be available on the host system.
11+
//! **Note:** MSVC cross-compile targets require either LLVM binutils
12+
//! or Zig to be available on the host system.
1513
//! More specifically, `python3-dll-a` requires `llvm-dlltool` executable
1614
//! to be present in `PATH` when targeting `*-pc-windows-msvc` from Linux.
1715
//!
16+
//! Alternatively, `ZIG_COMMAND` environment variable may be set to e.g. "zig"
17+
//! or "python -m ziglang", then `zig dlltool` will be used in place
18+
//! of `llvm-dlltool` (or MinGW binutils).
19+
//!
1820
//! PyO3 integration
1921
//! ----------------
2022
//!
@@ -42,7 +44,7 @@
4244
//!
4345
//! The examples below assume using an older version of PyO3.
4446
//!
45-
//! ### Example `build.rs` script
47+
//! ### Example `build.rs` script for an `abi3` PyO3 extension
4648
//!
4749
//! The following cargo build script can be used to cross-compile Stable ABI
4850
//! PyO3 extension modules for Windows (64/32-bit x86 or 64-bit ARM)
@@ -72,6 +74,14 @@
7274
//! ```sh
7375
//! PYO3_CROSS_LIB_DIR=target/python3-dll cargo build --target x86_64-pc-windows-gnu
7476
//! ```
77+
//!
78+
//! Generating version-specific `python3y.dll` import libraries
79+
//! -----------------------------------------------------------
80+
//!
81+
//! As an advanced feature, `python3-dll-a` can generate Python version
82+
//! specific import libraries such as `python39.lib`.
83+
//!
84+
//! See the [`ImportLibraryGenerator`] builder API description for details.
7585
7686
#![deny(missing_docs)]
7787
#![allow(clippy::needless_doctest_main)]
@@ -105,6 +115,35 @@ const LIB_MSVC: &str = "lib.exe";
105115
///
106116
/// Generates `python3.dll` or `pythonXY.dll` import library directly from the
107117
/// embedded Python ABI definitions data for the specified compile target.
118+
///
119+
/// Example usage
120+
/// -------------
121+
///
122+
/// ```no_run
123+
/// # use std::path::Path;
124+
/// # use python3_dll_a::ImportLibraryGenerator;
125+
/// // Generate `python3.dll.a` in "target/python3-dll-a"
126+
/// ImportLibraryGenerator::new("x86_64", "gnu")
127+
/// .generate(Path::new("target/python3-dll-a"))
128+
/// .unwrap();
129+
///
130+
/// // Generate `python3.lib` in "target/python3-lib"
131+
/// ImportLibraryGenerator::new("x86_64", "msvc")
132+
/// .generate(Path::new("target/python3-lib"))
133+
/// .unwrap();
134+
///
135+
/// // Generate `python39.dll.a` in "target/python3-dll-a"
136+
/// ImportLibraryGenerator::new("x86_64", "gnu")
137+
/// .version(Some((3, 9)))
138+
/// .generate(Path::new("target/python3-dll-a"))
139+
/// .unwrap();
140+
///
141+
/// // Generate `python38.lib` in "target/python3-lib"
142+
/// ImportLibraryGenerator::new("x86_64", "msvc")
143+
/// .version(Some((3, 8)))
144+
/// .generate(Path::new("target/python3-lib"))
145+
/// .unwrap();
146+
/// ```
108147
#[derive(Debug, Clone)]
109148
pub struct ImportLibraryGenerator {
110149
/// The compile target architecture name (as in `CARGO_CFG_TARGET_ARCH`)

0 commit comments

Comments
 (0)