Skip to content

Commit

Permalink
Don't unconditionally link libiconv on macOS.
Browse files Browse the repository at this point in the history
This adds `#[link(name = "iconv")]` to just the iconv symbols so that the
library is only linked if the symbols are used.
  • Loading branch information
goffrie committed Apr 28, 2021
1 parent 50af40e commit 28f07a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
7 changes: 0 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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)> {
Expand Down
23 changes: 13 additions & 10 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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;
Expand Down

0 comments on commit 28f07a4

Please sign in to comment.