Skip to content

Commit aafb62a

Browse files
committed
docs: Add multi-arch build.rs examples
Add new `generate_implib_for_target()` function usage examples to both the crate docstrings and the project README file.
1 parent 845e117 commit aafb62a

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ fn main() {
2929
A compatible `python3.dll` import library will be automatically created in
3030
the directory pointed by `PYO3_CROSS_LIB_DIR` environment variable.
3131

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:
34+
35+
```rust
36+
fn main() {
37+
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows"
38+
&& std::env::var("CARGO_CFG_TARGET_ENV").unwrap() == "gnu"
39+
{
40+
let libdir = std::env::var("PYO3_CROSS_LIB_DIR")
41+
.expect("PYO3_CROSS_LIB_DIR is not set when cross-compiling");
42+
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
43+
python3_dll_a::generate_implib_for_target(&libdir, &arch, "gnu")
44+
.expect("python3.dll import library generator failed");
45+
}
46+
}
47+
```
48+
3249
Example `cargo build` invocation
3350
--------------------------------
3451

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@
2929
//! A compatible `python3.dll` import library will be automatically created in
3030
//! the directory pointed by `PYO3_CROSS_LIB_DIR` environment variable.
3131
//!
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:
34+
//!
35+
//! ```no_run
36+
//! fn main() {
37+
//! if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows"
38+
//! && std::env::var("CARGO_CFG_TARGET_ENV").unwrap() == "gnu"
39+
//! {
40+
//! let libdir = std::env::var("PYO3_CROSS_LIB_DIR")
41+
//! .expect("PYO3_CROSS_LIB_DIR is not set when cross-compiling");
42+
//! let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
43+
//! python3_dll_a::generate_implib_for_target(&libdir, &arch, "gnu")
44+
//! .expect("python3.dll import library generator failed");
45+
//! }
46+
//! }
47+
//! ```
48+
//!
3249
//! Example `cargo build` invocation
3350
//! --------------------------------
3451
//!

0 commit comments

Comments
 (0)