diff options
author | bors <bors@rust-lang.org> | 2021-04-29 00:50:00 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2021-04-29 00:50:00 +0000 |
commit | e584862835eeb71f6cb479d357e5d3dfca885c7f (patch) | |
tree | 8848ebc8138d758aa8a95397422580f419128b92 | |
parent | 50af40e2776fa3573bdf8071a3fe98cea41206da (diff) | |
parent | 28f07a44ce9d0470c1f5d595c7f8cf4e621b48d8 (diff) | |
download | rust-libc-e584862835eeb71f6cb479d357e5d3dfca885c7f.tar.gz |
Auto merge of #2150 - goffrie:master, r=Amanieu
Don't unconditionally link libiconv on macOS.
This adds `#[link(name = "iconv")]` to just the iconv symbols so that the
library is only linked if the symbols are used.
#2037 added a build.rs directive to always link libiconv on Apple platforms,
but that shouldn't be necessary. With this change, we can see using `otool -L`
that a binary that uses an `iconv` symbol links libiconv, but other binaries
don't.
Note that this can only be seen with a rustc prior to nightly-2021-03-09, as
nightly-2021-03-10 includes https://github.com/rust-lang/rust/pull/82731 which
includes #2037, therefore unconditionally linking all Rust binaries to
libiconv.
-rw-r--r-- | build.rs | 7 | ||||
-rw-r--r-- | src/unix/bsd/apple/mod.rs | 23 |
2 files changed, 13 insertions, 17 deletions
@@ -11,7 +11,6 @@ fn main() { let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok(); let const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok(); let libc_ci = env::var("LIBC_CI").is_ok(); - let target = env::var("TARGET").unwrap(); if env::var("CARGO_FEATURE_USE_STD").is_ok() { println!( @@ -84,12 +83,6 @@ fn main() { } println!("cargo:rustc-cfg=libc_const_extern_fn"); } - - // For unknown reason, libiconv can't be linked by adding #[link(name = iconv)] to - // a macOS-specific struct, so we do the linking here. - if target.contains("-apple-") { - println!("cargo:rustc-link-lib=iconv"); - } } fn rustc_minor_nightly() -> Option<(u32, bool)> { diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index a5703ef5d6..3955354ff2 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -3826,16 +3826,6 @@ extern "C" { )] pub fn getfsstat(mntbufp: *mut statfs, bufsize: ::c_int, flags: ::c_int) -> ::c_int; - pub fn iconv_open(tocode: *const ::c_char, fromcode: *const ::c_char) -> iconv_t; - pub fn iconv( - cd: iconv_t, - inbuf: *mut *mut ::c_char, - inbytesleft: *mut ::size_t, - outbuf: *mut *mut ::c_char, - outbytesleft: *mut ::size_t, - ) -> ::size_t; - pub fn iconv_close(cd: iconv_t) -> ::c_int; - // Copy-on-write functions. // According to the man page `flags` is an `int` but in the header // this is a `uint32_t`. @@ -3855,6 +3845,19 @@ extern "C" { ) -> ::c_int; } +#[link(name = "iconv")] +extern "C" { + pub fn iconv_open(tocode: *const ::c_char, fromcode: *const ::c_char) -> iconv_t; + pub fn iconv( + cd: iconv_t, + inbuf: *mut *mut ::c_char, + inbytesleft: *mut ::size_t, + outbuf: *mut *mut ::c_char, + outbytesleft: *mut ::size_t, + ) -> ::size_t; + pub fn iconv_close(cd: iconv_t) -> ::c_int; +} + cfg_if! { if #[cfg(any(target_arch = "arm", target_arch = "x86"))] { mod b32; |