Skip to content

Commit e584862

Browse files
committed
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 rust-lang/rust#82731 which includes #2037, therefore unconditionally linking all Rust binaries to libiconv.
2 parents 50af40e + 28f07a4 commit e584862

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

build.rs

-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ fn main() {
1111
let align_cargo_feature = env::var("CARGO_FEATURE_ALIGN").is_ok();
1212
let const_extern_fn_cargo_feature = env::var("CARGO_FEATURE_CONST_EXTERN_FN").is_ok();
1313
let libc_ci = env::var("LIBC_CI").is_ok();
14-
let target = env::var("TARGET").unwrap();
1514

1615
if env::var("CARGO_FEATURE_USE_STD").is_ok() {
1716
println!(
@@ -84,12 +83,6 @@ fn main() {
8483
}
8584
println!("cargo:rustc-cfg=libc_const_extern_fn");
8685
}
87-
88-
// For unknown reason, libiconv can't be linked by adding #[link(name = iconv)] to
89-
// a macOS-specific struct, so we do the linking here.
90-
if target.contains("-apple-") {
91-
println!("cargo:rustc-link-lib=iconv");
92-
}
9386
}
9487

9588
fn rustc_minor_nightly() -> Option<(u32, bool)> {

src/unix/bsd/apple/mod.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -3826,16 +3826,6 @@ extern "C" {
38263826
)]
38273827
pub fn getfsstat(mntbufp: *mut statfs, bufsize: ::c_int, flags: ::c_int) -> ::c_int;
38283828

3829-
pub fn iconv_open(tocode: *const ::c_char, fromcode: *const ::c_char) -> iconv_t;
3830-
pub fn iconv(
3831-
cd: iconv_t,
3832-
inbuf: *mut *mut ::c_char,
3833-
inbytesleft: *mut ::size_t,
3834-
outbuf: *mut *mut ::c_char,
3835-
outbytesleft: *mut ::size_t,
3836-
) -> ::size_t;
3837-
pub fn iconv_close(cd: iconv_t) -> ::c_int;
3838-
38393829
// Copy-on-write functions.
38403830
// According to the man page `flags` is an `int` but in the header
38413831
// this is a `uint32_t`.
@@ -3855,6 +3845,19 @@ extern "C" {
38553845
) -> ::c_int;
38563846
}
38573847

3848+
#[link(name = "iconv")]
3849+
extern "C" {
3850+
pub fn iconv_open(tocode: *const ::c_char, fromcode: *const ::c_char) -> iconv_t;
3851+
pub fn iconv(
3852+
cd: iconv_t,
3853+
inbuf: *mut *mut ::c_char,
3854+
inbytesleft: *mut ::size_t,
3855+
outbuf: *mut *mut ::c_char,
3856+
outbytesleft: *mut ::size_t,
3857+
) -> ::size_t;
3858+
pub fn iconv_close(cd: iconv_t) -> ::c_int;
3859+
}
3860+
38583861
cfg_if! {
38593862
if #[cfg(any(target_arch = "arm", target_arch = "x86"))] {
38603863
mod b32;

0 commit comments

Comments
 (0)