Rollup merge of #134918 - ChrisDenton:issue-70093, r=jieyouxu

Windows: Enable issue 70093 link tests

Tracking issue for `-Z link-native-libraries`: #134948
Tracking issue for `-Z link-directives`: #134947

`-Zlink-native-libraries=no` and `-Zlink-directives=no` *should* work on Windows, at least for msvc. The fly in ointment is that `default-linker-libraries` doesn't. On unixy platforms rustc calls another compiler which in turn calls the linker along with the default libraries. On MSVC rustc calls the linker directly therefore it would need to be the one to implement `default-linker-libraries`. Except it doesn't so we workaround that in the test by using `-C link-arg` to talk to the linker.
This commit is contained in:
Matthias Krüger 2024-12-31 14:30:43 +01:00 committed by GitHub
commit d08d132524
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 40 additions and 22 deletions

View File

@ -2710,8 +2710,6 @@ ui/limits/issue-75158-64.rs
ui/link-native-libs/issue-109144.rs
ui/link-native-libs/issue-43925.rs
ui/link-native-libs/issue-43926.rs
ui/link-native-libs/issue-70093/issue-70093-link-directives.rs
ui/link-native-libs/issue-70093/issue-70093.rs
ui/linkage-attr/auxiliary/issue-12133-dylib.rs
ui/linkage-attr/auxiliary/issue-12133-dylib2.rs
ui/linkage-attr/auxiliary/issue-12133-rlib.rs

View File

@ -1,10 +0,0 @@
//@ run-pass
//@ compile-flags: -Zlink-directives=no
//@ ignore-windows - this will probably only work on unixish systems
//@ ignore-fuchsia - missing __libc_start_main for some reason (#84733)
//@ ignore-cross-compile - default-linker-libraries=yes doesn't play well with cross compiling
#[link(name = "some-random-non-existent-library", kind = "static")]
extern "C" {}
fn main() {}

View File

@ -1,10 +0,0 @@
//@ run-pass
//@ compile-flags: -Zlink-native-libraries=no -Cdefault-linker-libraries=yes
//@ ignore-windows - this will probably only work on unixish systems
//@ ignore-fuchsia - missing __libc_start_main for some reason (#84733)
//@ ignore-cross-compile - default-linker-libraries=yes doesn't play well with cross compiling
#[link(name = "some-random-non-existent-library", kind = "static")]
extern "C" {}
fn main() {}

View File

@ -0,0 +1,14 @@
// Ensure that `#[link]` attributes are entirely ignore when using `-Zlink-directives=no`.
//@ run-pass
//@ compile-flags: -Zlink-directives=no
//@ ignore-fuchsia - missing __libc_start_main for some reason (#84733)
//@ ignore-cross-compile - default-linker-libraries=yes doesn't play well with cross compiling
// Usually these `#[link]` attribute would cause `libsome-random-non-existent-library`
// to be passed to the linker, causing it to fail because the file doesn't exist.
// However, with -Zlink-directives=no, the `#[link]` is ignored.
#[link(name = "some-random-non-existent-library", kind = "static")]
extern "C" {}
fn main() {}

View File

@ -0,0 +1,26 @@
// Ensure that rust does not pass native libraries to the linker when
// `-Zlink-native-libraries=no` is used.
//@ run-pass
//@ compile-flags: -Zlink-native-libraries=no -Cdefault-linker-libraries=yes
//@ ignore-fuchsia - missing __libc_start_main for some reason (#84733)
//@ ignore-cross-compile - default-linker-libraries=yes doesn't play well with cross compiling
//@ revisions: other
//@[other] ignore-msvc
//@ revisions: msvc
// On Windows MSVC, default-linker-libraries=yes doesn't work because
// rustc drives the linker directly instead of going through another compiler.
// Therefore rustc would need to implement default-linker-libraries itself but doesn't.
// So instead we use -Clink-arg to directly set the required msvcrt.lib as a link arg.
//@[msvc] compile-flags: -Clink-arg=msvcrt.lib
//@[msvc] only-msvc
// Usually these `#[link]` attribute would cause `libsome-random-non-existent-library`
// to be passed to the linker, causing it to fail because the file doesn't exist.
// However, -Zlink-native-libraries=no disables that.
#[link(name = "some-random-non-existent-library", kind = "static")]
extern "C" {}
fn main() {}