Skip to content

Commit 980a529

Browse files
authored
Rollup merge of #138233 - smmalis37:no-advapi32, r=ChrisDenton
Windows: Don't link std (and run-make) against advapi32, except on win7 Std no longer depends on any functionality provided by advapi32, so we can remove it from the list of external libraries we link against. Except, the win7 targets do still rely on advapi32-provided functionality. This PR therefore moves linking against it to only occur on win7 targets, so that no new uses of it slip in without being noticed.
2 parents 2460fc6 + 31e22c6 commit 980a529

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

library/windows_targets/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub macro link {
3434
}
3535

3636
#[cfg(not(feature = "windows_raw_dylib"))]
37-
#[link(name = "advapi32")]
37+
#[cfg_attr(target_vendor = "win7", link(name = "advapi32"))]
3838
#[link(name = "ntdll")]
3939
#[link(name = "userenv")]
4040
#[link(name = "ws2_32")]

src/bootstrap/src/core/build_steps/dist.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,10 @@ fn make_win_dist(
230230
"libiconv.a",
231231
"libmoldname.a",
232232
"libpthread.a",
233-
//Windows import libs
234-
//This should contain only the set of libraries necessary to link the standard library.
233+
// Windows import libs
234+
// This *should* contain only the set of libraries necessary to link the standard library,
235+
// however we've had problems with people accidentally depending on extra libs being here,
236+
// so we can't easily remove entries.
235237
"libadvapi32.a",
236238
"libbcrypt.a",
237239
"libcomctl32.a",

src/tools/run-make-support/src/external_deps/c_cxx_compiler/extras.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
use crate::{is_msvc, is_windows, uname};
1+
use crate::{is_msvc, is_win7, is_windows, uname};
22

33
/// `EXTRACFLAGS`
44
pub fn extra_c_flags() -> Vec<&'static str> {
55
if is_windows() {
66
if is_msvc() {
7-
vec![
8-
"ws2_32.lib",
9-
"userenv.lib",
10-
"advapi32.lib",
11-
"bcrypt.lib",
12-
"ntdll.lib",
13-
"synchronization.lib",
14-
]
7+
let mut libs =
8+
vec!["ws2_32.lib", "userenv.lib", "bcrypt.lib", "ntdll.lib", "synchronization.lib"];
9+
if is_win7() {
10+
libs.push("advapi32.lib");
11+
}
12+
libs
1513
} else {
1614
vec!["-lws2_32", "-luserenv", "-lbcrypt", "-lntdll", "-lsynchronization"]
1715
}

src/tools/run-make-support/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub use run::{cmd, run, run_fail, run_with_args};
8484

8585
/// Helpers for checking target information.
8686
pub use targets::{
87-
apple_os, is_aix, is_darwin, is_msvc, is_windows, is_windows_gnu, llvm_components_contain,
87+
apple_os, is_aix, is_darwin, is_msvc, is_windows, is_windows_gnu, is_win7, llvm_components_contain,
8888
target, uname,
8989
};
9090

src/tools/run-make-support/src/targets.rs

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ pub fn is_windows_gnu() -> bool {
2828
target().ends_with("windows-gnu")
2929
}
3030

31+
/// Check if target is win7.
32+
#[must_use]
33+
pub fn is_win7() -> bool {
34+
target().contains("win7")
35+
}
36+
3137
/// Check if target uses macOS.
3238
#[must_use]
3339
pub fn is_darwin() -> bool {

0 commit comments

Comments
 (0)