Skip to content

Commit 15ee9db

Browse files
committed
fix: Get the import library file extension from dlltool
The import library file extension is determined by the linker flavor, not the target environment per se. `zig cc` uses `lld` even when targeting `x86_64-windows-gnu`, so the import library should get the standard `.lib` extension. The `.dll.a` libraries are only understood by the MinGW (GNU) `ld`.
1 parent 04ef28f commit 15ee9db

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/lib.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,15 @@ impl ImportLibraryGenerator {
148148
create_dir_all(out_dir)?;
149149

150150
let defpath = self.write_def_file(out_dir)?;
151-
let implib_file = self.implib_file_path(out_dir);
152151

153152
// Try to guess the `dlltool` executable name from the target triple.
154153
let dlltool_command = DllToolCommand::find_for_target(&self.arch, &self.env)?;
155154

155+
// Get the import library file extension from the used `dlltool` flavor.
156+
let implib_ext = dlltool_command.implib_file_ext();
157+
158+
let implib_file = self.implib_file_path(out_dir, implib_ext);
159+
156160
// Build the complete `dlltool` command with all required arguments.
157161
let mut command = dlltool_command.build(&defpath, &implib_file);
158162

@@ -194,14 +198,10 @@ impl ImportLibraryGenerator {
194198

195199
/// Builds the generated import library file name.
196200
///
201+
/// The output file extension is passed in `libext`.
202+
///
197203
/// Returns the full import library file path under `out_dir`.
198-
fn implib_file_path(&self, out_dir: &Path) -> PathBuf {
199-
let libext = if self.env == "msvc" {
200-
IMPLIB_EXT_MSVC
201-
} else {
202-
IMPLIB_EXT_GNU
203-
};
204-
204+
fn implib_file_path(&self, out_dir: &Path, libext: &str) -> PathBuf {
205205
let libname = match self.version {
206206
Some((major, minor)) => {
207207
format!("python{}{}{}", major, minor, libext)
@@ -300,6 +300,16 @@ impl DllToolCommand {
300300
}
301301
}
302302

303+
/// Returns the import library file extension used by
304+
/// this `dlltool` flavor.
305+
fn implib_file_ext(&self) -> &'static str {
306+
if let DllToolCommand::Mingw { .. } = self {
307+
IMPLIB_EXT_GNU
308+
} else {
309+
IMPLIB_EXT_MSVC
310+
}
311+
}
312+
303313
/// Generates the complete `dlltool` executable invocation command.
304314
fn build(self, defpath: &Path, libpath: &Path) -> Command {
305315
match self {

0 commit comments

Comments
 (0)