From ac0a783953832205372cb6b6982f2071f9170964 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sat, 19 Sep 2020 16:39:31 -0700 Subject: 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. --- src/lib.rs | 2 +- src/unix/mod.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 2be57129f0..421631711c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,7 +19,7 @@ // Attributes needed when building as part of the standard library #![cfg_attr( feature = "rustc-dep-of-std", - feature(cfg_target_vendor, link_cfg, no_core) + feature(cfg_target_vendor, link_cfg, no_core, static_nobundle) )] #![cfg_attr(libc_thread_local, feature(thread_local))] // Enable extra lints: diff --git a/src/unix/mod.rs b/src/unix/mod.rs index e8d9108698..3b2cc3f2ad 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -298,6 +298,26 @@ cfg_if! { } else if #[cfg(feature = "std")] { // cargo build, don't pull in anything extra as the libstd dep // already pulls in all libs. + } else if #[cfg(all(target_os = "linux", + target_env = "gnu", + feature = "rustc-dep-of-std"))] { + #[link(name = "rt", kind = "static-nobundle", + cfg(target_feature = "crt-static"))] + #[link(name = "pthread", kind = "static-nobundle", + cfg(target_feature = "crt-static"))] + #[link(name = "m", kind = "static-nobundle", + cfg(target_feature = "crt-static"))] + #[link(name = "c", kind = "static-nobundle", + cfg(target_feature = "crt-static"))] + #[link(name = "gcc_eh", kind = "static-nobundle", + cfg(target_feature = "crt-static"))] + #[link(name = "gcc", kind = "static-nobundle", + cfg(target_feature = "crt-static"))] + #[link(name = "rt", cfg(not(target_feature = "crt-static")))] + #[link(name = "pthread", cfg(not(target_feature = "crt-static")))] + #[link(name = "m", cfg(not(target_feature = "crt-static")))] + #[link(name = "c", cfg(not(target_feature = "crt-static")))] + extern {} } else if #[cfg(target_env = "musl")] { #[cfg_attr(feature = "rustc-dep-of-std", link(name = "c", kind = "static", -- cgit v1.2.1 From e005f4cad598c7278dfcef52ac7cbe1203c963f2 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sat, 19 Sep 2020 20:38:54 -0700 Subject: Consolidate handling of libutil, and handle crt-static The two library blocks that specify `#[link(name = "util")]` do not actually reference any functions in `libutil`; the functions that do use `libutil` don't have any reference to it. And having two library blocks specify it results in two separate inclusions of `-lutil` on the linker command line. Move the link lines up to `src/unix/mod.rs`, making it easier to see all the libraries `libc` links to. This also makes `libutil` respect `target-feature=+crt-static`. --- src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs | 1 - src/unix/linux_like/linux/gnu/mod.rs | 1 - src/unix/mod.rs | 3 +++ 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs b/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs index 64a6de9c67..56170c4ea7 100644 --- a/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs +++ b/src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs @@ -410,7 +410,6 @@ pub const SYS_pkey_alloc: ::c_long = 330; pub const SYS_pkey_free: ::c_long = 331; pub const SYS_statx: ::c_long = 332; -#[link(name = "util")] extern "C" { pub fn sysctl( name: *mut ::c_int, diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index 44232e98cb..9ea34dec38 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -1362,7 +1362,6 @@ extern "C" { ) -> ::c_int; } -#[link(name = "util")] extern "C" { pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int; pub fn backtrace(buf: *mut *mut ::c_void, sz: ::c_int) -> ::c_int; diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 3b2cc3f2ad..32e8d932bb 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -301,6 +301,8 @@ cfg_if! { } else if #[cfg(all(target_os = "linux", target_env = "gnu", feature = "rustc-dep-of-std"))] { + #[link(name = "util", kind = "static-nobundle", + cfg(target_feature = "crt-static"))] #[link(name = "rt", kind = "static-nobundle", cfg(target_feature = "crt-static"))] #[link(name = "pthread", kind = "static-nobundle", @@ -313,6 +315,7 @@ cfg_if! { cfg(target_feature = "crt-static"))] #[link(name = "gcc", kind = "static-nobundle", cfg(target_feature = "crt-static"))] + #[link(name = "util", cfg(not(target_feature = "crt-static")))] #[link(name = "rt", cfg(not(target_feature = "crt-static")))] #[link(name = "pthread", cfg(not(target_feature = "crt-static")))] #[link(name = "m", cfg(not(target_feature = "crt-static")))] -- cgit v1.2.1 From 5bf6ee5d8e06aea64a2b20c47afe5062da1a7848 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sat, 19 Sep 2020 20:46:25 -0700 Subject: Consolidate handling of libdl, and handle crt-static Move the link line for `libdl` up to `src/unix/mod.rs`, making it easier to see all the libraries `libc` links to. This also makes `libdl` respect `target-feature=+crt-static`. --- src/unix/linux_like/linux/gnu/mod.rs | 1 - src/unix/mod.rs | 3 +++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index 9ea34dec38..6ead42fee6 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -1435,7 +1435,6 @@ extern "C" { ) -> ::c_int; } -#[link(name = "dl")] extern "C" { pub fn dlmopen( lmid: Lmid_t, diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 32e8d932bb..21439c8a49 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -309,6 +309,8 @@ cfg_if! { cfg(target_feature = "crt-static"))] #[link(name = "m", kind = "static-nobundle", cfg(target_feature = "crt-static"))] + #[link(name = "dl", kind = "static-nobundle", + cfg(target_feature = "crt-static"))] #[link(name = "c", kind = "static-nobundle", cfg(target_feature = "crt-static"))] #[link(name = "gcc_eh", kind = "static-nobundle", @@ -319,6 +321,7 @@ cfg_if! { #[link(name = "rt", cfg(not(target_feature = "crt-static")))] #[link(name = "pthread", cfg(not(target_feature = "crt-static")))] #[link(name = "m", cfg(not(target_feature = "crt-static")))] + #[link(name = "dl", cfg(not(target_feature = "crt-static")))] #[link(name = "c", cfg(not(target_feature = "crt-static")))] extern {} } else if #[cfg(target_env = "musl")] { -- cgit v1.2.1