Skip to content

Commit

Permalink
Merge pull request #17 from messense/fix-mingw
Browse files Browse the repository at this point in the history
refactor: cleanup code
  • Loading branch information
ravenexp authored May 11, 2022
2 parents ac9a080 + 0c08987 commit d3794f5
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,29 @@ impl ImportLibraryGenerator {

write(&defpath, def_file_content)?;

let impllib_ext = if self.env == "msvc" {
IMPLIB_EXT_MSVC
} else {
IMPLIB_EXT_GNU
};
let implib_file = match self.version {
Some((major, minor)) => {
format!("python{}{}{}", major, minor, impllib_ext)
}
None => format!("python3{}", impllib_ext),
};
// Try to guess the `dlltool` executable name from the target triple.
let mut command = match (self.arch.as_str(), self.env.as_str()) {
// 64-bit MinGW-w64 (aka x86_64-pc-windows-gnu)
("x86_64", "gnu") => self.build_dlltool_command(
DLLTOOL_GNU,
&def_file.replace(".def", IMPLIB_EXT_GNU),
&defpath,
out_dir,
),
("x86_64", "gnu") => {
self.build_dlltool_command(DLLTOOL_GNU, &implib_file, &defpath, out_dir)
}
// 32-bit MinGW-w64 (aka i686-pc-windows-gnu)
("x86", "gnu") => self.build_dlltool_command(
DLLTOOL_GNU_32,
&def_file.replace(".def", IMPLIB_EXT_GNU),
&defpath,
out_dir,
),
("x86", "gnu") => {
self.build_dlltool_command(DLLTOOL_GNU_32, &implib_file, &defpath, out_dir)
}
// MSVC ABI (multiarch)
(_, "msvc") => {
let implib_file = def_file.replace(".def", IMPLIB_EXT_MSVC);
if let Some(command) = find_lib_exe(&self.arch) {
self.build_dlltool_command(
command.get_program(),
Expand All @@ -188,7 +192,10 @@ impl ImportLibraryGenerator {
};

// Run the selected `dlltool` executable to generate the import library.
let status = command.status()?;
let status = command.status().map_err(|e| {
let msg = format!("{:?} failed with {}", command, e);
Error::new(e.kind(), msg)
})?;

if status.success() {
Ok(())
Expand Down

0 comments on commit d3794f5

Please sign in to comment.