Skip to content

Commit 5270a86

Browse files
committed
docs: Document MSVC ABI environment support
Update the crate level docstrings and README file.
1 parent 08690f5 commit 5270a86

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@ Standalone `python3.dll` import library generator
22
=================================================
33

44
Generates import libraries for the Stable ABI Python DLL
5-
for MinGW-w64 cross-compile targets.
5+
for MinGW-w64 and MSVC (cross-)compile targets.
66

77
See <https://docs.python.org/3/c-api/stable.html> for details.
88

99
This crate **does not require** Python 3 distribution files
10-
to be present on the cross-compile host system.
10+
to be present on the (cross-)compile host system.
11+
12+
**Note:** MSVC (cross-)compile targets require LLVM binutils
13+
to be available on the host system.
14+
More specifically, `python3-dll-a` requires `llvm-dlltool` executable
15+
to be present in `PATH` when targeting `*-pc-windows-msvc`.
1116

1217
Example `build.rs` script
1318
-------------------------
1419

1520
The following script can be used to cross-compile Stable ABI
16-
PyO3 extension modules for Windows:
21+
PyO3 extension modules for Windows (64-bit MinGW-w64):
1722

1823
```rust
1924
fn main() {
@@ -29,18 +34,19 @@ fn main() {
2934
A compatible `python3.dll` import library will be automatically created in
3035
the directory pointed by `PYO3_CROSS_LIB_DIR` environment variable.
3136

32-
If both 64-bit and 32-bit Windows cross-compile targets support is needed,
33-
the more generic `generate_implib_for_target()` function must be used:
37+
If both 64-bit and 32-bit or GNU and MSVC ABI (cross-)compile target
38+
support is needed, the more generic `generate_implib_for_target()`
39+
function must be used:
40+
3441

3542
```rust
3643
fn main() {
37-
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows"
38-
&& std::env::var("CARGO_CFG_TARGET_ENV").unwrap() == "gnu"
39-
{
44+
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
4045
let libdir = std::env::var("PYO3_CROSS_LIB_DIR")
4146
.expect("PYO3_CROSS_LIB_DIR is not set when cross-compiling");
4247
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
43-
python3_dll_a::generate_implib_for_target(&libdir, &arch, "gnu")
48+
let env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
49+
python3_dll_a::generate_implib_for_target(&libdir, &arch, &env)
4450
.expect("python3.dll import library generator failed");
4551
}
4652
}

src/lib.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@
22
//! =================================================
33
//!
44
//! Generates import libraries for the Stable ABI Python DLL
5-
//! for MinGW-w64 cross-compile targets.
5+
//! for MinGW-w64 and MSVC (cross-)compile targets.
66
//!
77
//! See <https://docs.python.org/3/c-api/stable.html> for details.
88
//!
99
//! This crate **does not require** Python 3 distribution files
10-
//! to be present on the cross-compile host system.
10+
//! to be present on the (cross-)compile host system.
11+
//!
12+
//! **Note:** MSVC (cross-)compile targets require LLVM binutils
13+
//! to be available on the host system.
14+
//! More specifically, `python3-dll-a` requires `llvm-dlltool` executable
15+
//! to be present in `PATH` when targeting `*-pc-windows-msvc`.
1116
//!
1217
//! Example `build.rs` script
1318
//! -------------------------
1419
//!
1520
//! The following script can be used to cross-compile Stable ABI
16-
//! PyO3 extension modules for Windows (64-bit):
21+
//! PyO3 extension modules for Windows (64-bit MinGW-w64):
1722
//!
1823
//! ```no_run
1924
//! fn main() {
@@ -29,18 +34,18 @@
2934
//! A compatible `python3.dll` import library will be automatically created in
3035
//! the directory pointed by `PYO3_CROSS_LIB_DIR` environment variable.
3136
//!
32-
//! If both 64-bit and 32-bit Windows cross-compile targets support is needed,
33-
//! the more generic `generate_implib_for_target()` function must be used:
37+
//! If both 64-bit and 32-bit or GNU and MSVC ABI (cross-)compile target
38+
//! support is needed, the more generic `generate_implib_for_target()`
39+
//! function must be used:
3440
//!
3541
//! ```no_run
3642
//! fn main() {
37-
//! if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows"
38-
//! && std::env::var("CARGO_CFG_TARGET_ENV").unwrap() == "gnu"
39-
//! {
43+
//! if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
4044
//! let libdir = std::env::var("PYO3_CROSS_LIB_DIR")
4145
//! .expect("PYO3_CROSS_LIB_DIR is not set when cross-compiling");
4246
//! let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
43-
//! python3_dll_a::generate_implib_for_target(&libdir, &arch, "gnu")
47+
//! let env = std::env::var("CARGO_CFG_TARGET_ENV").unwrap();
48+
//! python3_dll_a::generate_implib_for_target(&libdir, &arch, &env)
4449
//! .expect("python3.dll import library generator failed");
4550
//! }
4651
//! }

0 commit comments

Comments
 (0)