Skip to content

Commit d76f0d0

Browse files
committed
Add support for building with static glibc
This will need corresponding changes in rust-lang/rust to activate, but this will make it possible to make those changes. Note that despite the apparent redundancy in config directives, the link directives cannot be simplified any further. Attempting to factor out the checks for `target_feature = "crt-static"` does not work.
1 parent 999e5e1 commit d76f0d0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// Attributes needed when building as part of the standard library
2020
#![cfg_attr(
2121
feature = "rustc-dep-of-std",
22-
feature(cfg_target_vendor, link_cfg, no_core)
22+
feature(cfg_target_vendor, link_cfg, no_core, static_nobundle)
2323
)]
2424
#![cfg_attr(libc_thread_local, feature(thread_local))]
2525
// Enable extra lints:

src/unix/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,22 @@ cfg_if! {
298298
} else if #[cfg(feature = "std")] {
299299
// cargo build, don't pull in anything extra as the libstd dep
300300
// already pulls in all libs.
301+
} else if #[cfg(all(target_os = "linux",
302+
target_env = "gnu",
303+
feature = "rustc-dep-of-std"))] {
304+
#[link(name = "c", kind = "static-nobundle",
305+
cfg(target_feature = "crt-static"))]
306+
#[link(name = "m", kind = "static-nobundle",
307+
cfg(target_feature = "crt-static"))]
308+
#[link(name = "pthread", kind = "static-nobundle",
309+
cfg(target_feature = "crt-static"))]
310+
#[link(name = "rt", kind = "static-nobundle",
311+
cfg(target_feature = "crt-static"))]
312+
#[link(name = "c", cfg(not(target_feature = "crt-static")))]
313+
#[link(name = "m", cfg(not(target_feature = "crt-static")))]
314+
#[link(name = "pthread", cfg(not(target_feature = "crt-static")))]
315+
#[link(name = "rt", cfg(not(target_feature = "crt-static")))]
316+
extern {}
301317
} else if #[cfg(target_env = "musl")] {
302318
#[cfg_attr(feature = "rustc-dep-of-std",
303319
link(name = "c", kind = "static",

0 commit comments

Comments
 (0)