Skip to content

Commit d3794f5

Browse files
authored
Merge pull request #17 from messense/fix-mingw
refactor: cleanup code
2 parents ac9a080 + 0c08987 commit d3794f5

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/lib.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,25 +148,29 @@ impl ImportLibraryGenerator {
148148

149149
write(&defpath, def_file_content)?;
150150

151+
let impllib_ext = if self.env == "msvc" {
152+
IMPLIB_EXT_MSVC
153+
} else {
154+
IMPLIB_EXT_GNU
155+
};
156+
let implib_file = match self.version {
157+
Some((major, minor)) => {
158+
format!("python{}{}{}", major, minor, impllib_ext)
159+
}
160+
None => format!("python3{}", impllib_ext),
161+
};
151162
// Try to guess the `dlltool` executable name from the target triple.
152163
let mut command = match (self.arch.as_str(), self.env.as_str()) {
153164
// 64-bit MinGW-w64 (aka x86_64-pc-windows-gnu)
154-
("x86_64", "gnu") => self.build_dlltool_command(
155-
DLLTOOL_GNU,
156-
&def_file.replace(".def", IMPLIB_EXT_GNU),
157-
&defpath,
158-
out_dir,
159-
),
165+
("x86_64", "gnu") => {
166+
self.build_dlltool_command(DLLTOOL_GNU, &implib_file, &defpath, out_dir)
167+
}
160168
// 32-bit MinGW-w64 (aka i686-pc-windows-gnu)
161-
("x86", "gnu") => self.build_dlltool_command(
162-
DLLTOOL_GNU_32,
163-
&def_file.replace(".def", IMPLIB_EXT_GNU),
164-
&defpath,
165-
out_dir,
166-
),
169+
("x86", "gnu") => {
170+
self.build_dlltool_command(DLLTOOL_GNU_32, &implib_file, &defpath, out_dir)
171+
}
167172
// MSVC ABI (multiarch)
168173
(_, "msvc") => {
169-
let implib_file = def_file.replace(".def", IMPLIB_EXT_MSVC);
170174
if let Some(command) = find_lib_exe(&self.arch) {
171175
self.build_dlltool_command(
172176
command.get_program(),
@@ -188,7 +192,10 @@ impl ImportLibraryGenerator {
188192
};
189193

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

193200
if status.success() {
194201
Ok(())

0 commit comments

Comments
 (0)