From 68c22a16bcfdfa9a7e5d1936fb24a37beba9a381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Wed, 17 Apr 2019 15:49:07 +0200 Subject: [PATCH 1/2] Add implib to the stamp files This was already done when targetting msvc, but it needs to be done for all targets to allow rustc to link with shared libraries when using llvm -l is only supported by gcc, while llvm needs an import library to link indirectly with a dll --- src/cargo/core/compiler/build_context/target_info.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 39346b34ccb..7bf15d9bee0 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -258,6 +258,17 @@ impl TargetInfo { should_replace_hyphens: false, }) } + else if target_triple.ends_with("windows-gnu") + && crate_type.ends_with("dylib") + && suffix == ".dll" + { + ret.push(FileType { + suffix: ".dll.a".to_string(), + prefix: "lib".to_string(), + flavor: FileFlavor::Normal, + should_replace_hyphens: false, + }) + } // See rust-lang/cargo#4535. if target_triple.starts_with("wasm32-") && crate_type == "bin" && suffix == ".js" { From b19d6ac2a7f9abfe267c38c5cf7652c63e01d908 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 21 Apr 2020 10:52:46 -0700 Subject: [PATCH 2/2] Update tests and comments for testing windows-gnu. --- src/cargo/core/compiler/build_context/target_info.rs | 8 ++++---- tests/testsuite/build.rs | 3 +-- tests/testsuite/build_script.rs | 1 - tests/testsuite/out_dir.rs | 3 +-- tests/testsuite/plugins.rs | 3 +-- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 7bf15d9bee0..5b7dac40bab 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -257,11 +257,11 @@ impl TargetInfo { flavor: FileFlavor::Normal, should_replace_hyphens: false, }) - } - else if target_triple.ends_with("windows-gnu") - && crate_type.ends_with("dylib") - && suffix == ".dll" + } else if target_triple.ends_with("windows-gnu") + && crate_type.ends_with("dylib") + && suffix == ".dll" { + // LD can link DLL directly, but LLD requires the import library. ret.push(FileType { suffix: ".dll.a".to_string(), prefix: "lib".to_string(), diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index b116635b3d9..dc987c6e602 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -3810,8 +3810,7 @@ fn cdylib_final_outputs() { if cfg!(target_env = "msvc") { vec!["foo_bar.dll.lib", "foo_bar.dll"] } else { - // FIXME https://github.com/rust-lang/cargo/pull/6875 - vec!["foo_bar.dll"] + vec!["foo_bar.dll", "libfoo_bar.dll.a"] } } else if cfg!(target_os = "macos") { vec!["libfoo_bar.dylib"] diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index eb79675f79b..caaf45a968c 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -1663,7 +1663,6 @@ fn build_script_with_dynamic_native_dependency() { let src = root.join(&file); let dst = out_dir.join(&file); fs::copy(src, dst).unwrap(); - // FIXME https://github.com/rust-lang/cargo/pull/6875 if cfg!(target_env = "msvc") { fs::copy(root.join("builder.dll.lib"), out_dir.join("builder.dll.lib")).unwrap(); diff --git a/tests/testsuite/out_dir.rs b/tests/testsuite/out_dir.rs index d68bf27bdb7..15b26f61980 100644 --- a/tests/testsuite/out_dir.rs +++ b/tests/testsuite/out_dir.rs @@ -92,8 +92,7 @@ fn dynamic_library_with_debug() { &["libfoo.so"], &["libfoo.dylib"], &["foo.dll", "foo.dll.lib"], - // FIXME https://github.com/rust-lang/cargo/pull/6875 - &["foo.dll"], + &["foo.dll", "libfoo.dll.a"], ); } diff --git a/tests/testsuite/plugins.rs b/tests/testsuite/plugins.rs index f714399f892..0035e20315e 100644 --- a/tests/testsuite/plugins.rs +++ b/tests/testsuite/plugins.rs @@ -180,8 +180,7 @@ fn plugin_with_dynamic_native_dependency() { let src = root.join(&file); let dst = out_dir.join(&file); fs::copy(src, dst).unwrap(); - // FIXME https://github.com/rust-lang/cargo/pull/6875 - if cfg!(target_env = "msvc") { + if cfg!(target_env = "msvc") { fs::copy(root.join("builder.dll.lib"), out_dir.join("builder.dll.lib")).unwrap(); }