python3.dll
import library generatorGenerates import libraries for the Stable ABI Python DLL for MinGW-w64 and MSVC (cross-)compile targets.
See https://docs.python.org/3/c-api/stable.html for details.
This crate does not require Python 3 distribution files to be present on the (cross-)compile host system.
Note: MSVC (cross-)compile targets require LLVM binutils
to be available on the host system.
More specifically, python3-dll-a
requires llvm-dlltool
executable
to be present in PATH
when targeting *-pc-windows-msvc
.
build.rs
scriptThe following Cargo build script can be used to cross-compile Stable ABI PyO3 extension modules for Windows (64/32-bit x86 or 64-bit ARM) using either MinGW-w64 or MSVC target environment ABI:
```rust fn main() { if std::env::var("CARGOCFGTARGETOS").unwrap() == "windows" { let crosslibdir = std::env::varos("PYO3CROSSLIBDIR") .expect("PYO3CROSSLIBDIR is not set when cross-compiling"); let arch = std::env::var("CARGOCFGTARGETARCH").unwrap(); let env = std::env::var("CARGOCFGTARGETENV").unwrap();
let libdir = std::path::Path::new(&cross_lib_dir);
python3_dll_a::generate_implib_for_target(libdir, &arch, &env)
.expect("python3.dll import library generator failed");
}
} ```
A compatible python3.dll
import library file named python3.dll.a
or python3.lib
will be automatically created in the directory
pointed by the PYO3_CROSS_LIB_DIR
environment variable.
cargo build
invocationsh
PYO3_CROSS_LIB_DIR=target/python3-dll cargo build --target x86_64-pc-windows-gnu