Skip to content

Commit

Permalink
Consolidate handling of libutil, and handle crt-static
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
joshtriplett committed Sep 20, 2020
1 parent f03aca0 commit 618b55b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/unix/linux_like/linux/gnu/b64/x86_64/not_x32.rs
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/unix/linux_like/linux/gnu/mod.rs
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/unix/mod.rs
Expand Up @@ -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",
Expand All @@ -309,6 +311,7 @@ cfg_if! {
cfg(target_feature = "crt-static"))]
#[link(name = "c", 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")))]
Expand Down

0 comments on commit 618b55b

Please sign in to comment.