-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pyo3-build-config: Add
python3-dll-a
crate support
Automatically generate `python3.dll` import libraries for Windows compile targets in the build script. Adds a new PyO3 crate feature `auto-abi3-import-lib` enabling automatic import library generation. Closes PyO3#2231
- Loading branch information
Showing
4 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//! Additional functionality enabled by crate features | ||
#![allow(clippy::unnecessary_wraps)] | ||
|
||
use super::Triple; | ||
use crate::errors::Result; | ||
|
||
/// Generates `python3.dll` import library for Windows targets. | ||
/// | ||
/// Places the import library into the build script output directory | ||
/// and returns the full library directory path. | ||
/// | ||
/// Does nothing if the target OS is not Windows. | ||
#[cfg(feature = "python3-dll-a")] | ||
pub(super) fn generate_abi3_import_lib(target: &Triple) -> Result<Option<String>> { | ||
use super::{Architecture, OperatingSystem}; | ||
use crate::errors::Context; | ||
|
||
if target.operating_system != OperatingSystem::Windows { | ||
return Ok(None); | ||
} | ||
|
||
let out_dir = std::env::var_os("OUT_DIR") | ||
.expect("generate_abi3_import_lib() must be called from a build script"); | ||
|
||
// Put the import library into the build script output directory. | ||
let mut out_lib_dir = std::path::PathBuf::from(out_dir); | ||
out_lib_dir.push("lib"); | ||
|
||
// Convert `Architecture` to rustc `target_arch` format. | ||
let arch = match target.architecture { | ||
// i686, i586, etc. | ||
Architecture::X86_32(_) => "x86".to_string(), | ||
other => other.to_string(), | ||
}; | ||
|
||
let env = target.environment.to_string(); | ||
|
||
python3_dll_a::generate_implib_for_target(&out_lib_dir, &arch, &env) | ||
.context("failed to generate python3.dll import library")?; | ||
|
||
let out_lib_dir_string = out_lib_dir | ||
.to_str() | ||
.ok_or("build directory is not a valid UTF-8 string")? | ||
.to_owned(); | ||
|
||
Ok(Some(out_lib_dir_string)) | ||
} | ||
|
||
/// Generates `python3.dll` import library for Windows targets. | ||
/// | ||
/// Places the import library into the build script output directory | ||
/// and returns the full library directory path. | ||
/// | ||
/// Does nothing if the target OS is not Windows. | ||
#[cfg(not(feature = "python3-dll-a"))] | ||
pub(super) fn generate_abi3_import_lib(_target: &Triple) -> Result<Option<String>> { | ||
Ok(None) | ||
} |