From 0777ba8108a121fb8ba12eb032f000605d953e0f Mon Sep 17 00:00:00 2001 From: messense Date: Tue, 10 May 2022 22:45:12 +0800 Subject: [PATCH 1/2] refactor: cleanup implib file name code --- src/lib.rs | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 070702a..fe18bb7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(), From 0c089874ad37178c343ca750359c2db8a27b053f Mon Sep 17 00:00:00 2001 From: messense Date: Tue, 10 May 2022 23:00:27 +0800 Subject: [PATCH 2/2] fix: improve error message when dlltool is not found --- src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index fe18bb7..3ebc396 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -192,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(())