Skip to content

Commit 6f3872a

Browse files
committed
Make the libstd build script smaller
Remove all rustc-link-lib from the std build script. Also remove use of feature = "restricted-std" where not necessary.
1 parent cf9cf7c commit 6f3872a

File tree

5 files changed

+86
-58
lines changed

5 files changed

+86
-58
lines changed

library/std/build.rs

+14-57
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,23 @@ use std::env;
33
fn main() {
44
println!("cargo:rerun-if-changed=build.rs");
55
let target = env::var("TARGET").expect("TARGET was not set");
6-
if target.contains("linux") {
7-
if target.contains("android") {
8-
println!("cargo:rustc-link-lib=dl");
9-
println!("cargo:rustc-link-lib=log");
10-
println!("cargo:rustc-link-lib=gcc");
11-
}
12-
} else if target.contains("freebsd") {
13-
println!("cargo:rustc-link-lib=execinfo");
14-
println!("cargo:rustc-link-lib=pthread");
6+
if target.contains("freebsd") {
157
if env::var("RUST_STD_FREEBSD_12_ABI").is_ok() {
168
println!("cargo:rustc-cfg=freebsd12");
179
}
18-
} else if target.contains("netbsd") {
19-
println!("cargo:rustc-link-lib=pthread");
20-
println!("cargo:rustc-link-lib=rt");
21-
} else if target.contains("dragonfly") || target.contains("openbsd") {
22-
println!("cargo:rustc-link-lib=pthread");
23-
} else if target.contains("solaris") {
24-
println!("cargo:rustc-link-lib=socket");
25-
println!("cargo:rustc-link-lib=posix4");
26-
println!("cargo:rustc-link-lib=pthread");
27-
println!("cargo:rustc-link-lib=resolv");
28-
} else if target.contains("illumos") {
29-
println!("cargo:rustc-link-lib=socket");
30-
println!("cargo:rustc-link-lib=posix4");
31-
println!("cargo:rustc-link-lib=pthread");
32-
println!("cargo:rustc-link-lib=resolv");
33-
println!("cargo:rustc-link-lib=nsl");
34-
// Use libumem for the (malloc-compatible) allocator
35-
println!("cargo:rustc-link-lib=umem");
36-
} else if target.contains("apple-darwin") {
37-
println!("cargo:rustc-link-lib=System");
38-
39-
// res_init and friends require -lresolv on macOS/iOS.
40-
// See #41582 and http://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html
41-
println!("cargo:rustc-link-lib=resolv");
42-
} else if target.contains("apple-ios") {
43-
println!("cargo:rustc-link-lib=System");
44-
println!("cargo:rustc-link-lib=objc");
45-
println!("cargo:rustc-link-lib=framework=Security");
46-
println!("cargo:rustc-link-lib=framework=Foundation");
47-
println!("cargo:rustc-link-lib=resolv");
48-
} else if target.contains("uwp") {
49-
println!("cargo:rustc-link-lib=ws2_32");
50-
// For BCryptGenRandom
51-
println!("cargo:rustc-link-lib=bcrypt");
52-
} else if target.contains("windows") {
53-
println!("cargo:rustc-link-lib=advapi32");
54-
println!("cargo:rustc-link-lib=ws2_32");
55-
println!("cargo:rustc-link-lib=userenv");
56-
} else if target.contains("fuchsia") {
57-
println!("cargo:rustc-link-lib=zircon");
58-
println!("cargo:rustc-link-lib=fdio");
59-
} else if target.contains("cloudabi") {
60-
if cfg!(feature = "backtrace") {
61-
println!("cargo:rustc-link-lib=unwind");
62-
}
63-
println!("cargo:rustc-link-lib=c");
64-
println!("cargo:rustc-link-lib=compiler_rt");
65-
} else if (target.contains("sgx") && target.contains("fortanix"))
10+
} else if target.contains("linux")
11+
|| target.contains("netbsd")
12+
|| target.contains("dragonfly")
13+
|| target.contains("openbsd")
14+
|| target.contains("solaris")
15+
|| target.contains("illumos")
16+
|| target.contains("apple-darwin")
17+
|| target.contains("apple-ios")
18+
|| target.contains("uwp")
19+
|| target.contains("windows")
20+
|| target.contains("fuchsia")
21+
|| target.contains("cloudabi")
22+
|| (target.contains("sgx") && target.contains("fortanix"))
6623
|| target.contains("hermit")
6724
|| target.contains("l4re")
6825
|| target.contains("redox")

library/std/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -563,5 +563,5 @@ include!("keyword_docs.rs");
563563
// This is required to avoid an unstable error when `restricted-std` is not
564564
// enabled. The use of #![feature(restricted_std)] in rustc-std-workspace-std
565565
// is unconditional, so the unstable feature needs to be defined somewhere.
566-
#[cfg_attr(not(feature = "restricted-std"), unstable(feature = "restricted_std", issue = "none"))]
566+
#[unstable(feature = "restricted_std", issue = "none")]
567567
mod __restricted_std_workaround {}

library/std/src/sys/cloudabi/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,8 @@ pub fn hashmap_random_keys() -> (u64, u64) {
6666
v.assume_init()
6767
}
6868
}
69+
70+
#[cfg_attr(feature = "backtrace", link(name = "unwind"))]
71+
#[link(name = "c")]
72+
#[link(name = "compiler_rt")]
73+
extern "C" {}

library/std/src/sys/unix/mod.rs

+52
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,55 @@ pub fn cvt_nz(error: libc::c_int) -> crate::io::Result<()> {
234234
pub fn abort_internal() -> ! {
235235
unsafe { libc::abort() }
236236
}
237+
238+
cfg_if::cfg_if! {
239+
if #[cfg(target_os = "android")] {
240+
#[link(name = "dl")]
241+
#[link(name = "log")]
242+
#[link(name = "gcc")]
243+
extern "C" {}
244+
} else if #[cfg(target_os = "freebsd")] {
245+
#[link(name = "execinfo")]
246+
#[link(name = "pthread")]
247+
extern "C" {}
248+
} else if #[cfg(target_os = "netbsd")] {
249+
#[link(name = "pthread")]
250+
#[link(name = "rt")]
251+
extern "C" {}
252+
} else if #[cfg(any(target_os = "dragonfly", target_os = "openbsd"))] {
253+
#[link(name = "pthread")]
254+
extern "C" {}
255+
} else if #[cfg(target_os = "solaris")] {
256+
#[link(name = "socket")]
257+
#[link(name = "posix4")]
258+
#[link(name = "pthread")]
259+
#[link(name = "resolv")]
260+
extern "C" {}
261+
} else if #[cfg(target_os = "illumos")] {
262+
#[link(name = "socket")]
263+
#[link(name = "posix4")]
264+
#[link(name = "pthread")]
265+
#[link(name = "resolv")]
266+
#[link(name = "nsl")]
267+
// Use libumem for the (malloc-compatible) allocator
268+
#[link(name = "umem")]
269+
extern "C" {}
270+
} else if #[cfg(target_os = "macos")] {
271+
#[link(name = "System")]
272+
// res_init and friends require -lresolv on macOS/iOS.
273+
// See #41582 and http://blog.achernya.com/2013/03/os-x-has-silly-libsystem.html
274+
#[link(name = "resolv")]
275+
extern "C" {}
276+
} else if #[cfg(target_os = "ios")] {
277+
#[link(name = "System")]
278+
#[link(name = "objc")]
279+
#[link(name = "Security", kind = "framework")]
280+
#[link(name = "Foundation", kind = "framework")]
281+
#[link(name = "resolv")]
282+
extern "C" {}
283+
} else if #[cfg(target_os = "fuchsia")] {
284+
#[link(name = "zircon")]
285+
#[link(name = "fdio")]
286+
extern "C" {}
287+
}
288+
}

library/std/src/sys/windows/mod.rs

+14
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,17 @@ pub fn abort_internal() -> ! {
270270
}
271271
crate::intrinsics::abort();
272272
}
273+
274+
cfg_if::cfg_if! {
275+
if #[cfg(target_vendor = "uwp")] {
276+
#[link(name = "ws2_32")]
277+
// For BCryptGenRandom
278+
#[link(name = "bcrypt")]
279+
extern "C" {}
280+
} else {
281+
#[link(name = "advapi32")]
282+
#[link(name = "ws2_32")]
283+
#[link(name = "userenv")]
284+
extern "C" {}
285+
}
286+
}

0 commit comments

Comments
 (0)