Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ align = []
rustc-dep-of-std = ['align', 'rustc-std-workspace-core']
extra_traits = []
const-extern-fn = []
iconv-apple = []
# use_std is deprecated, use `std` instead
use_std = [ 'std' ]

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ libc = "0.2"
If you use Rust >= 1.62, this feature is implicitly enabled.
Otherwise it requires a nightly rustc.

* `iconv-apple`: Enables usage of `iconv_open`, `iconv`, and `iconv_close` on Apple devices.

* **deprecated**: `use_std` is deprecated, and is equivalent to `std`.

## Rust version support
Expand Down
11 changes: 11 additions & 0 deletions src/unix/bsd/apple/iconv.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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;
}
26 changes: 13 additions & 13 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5908,19 +5908,19 @@ cfg_if! {
}

// These require a dependency on `libiconv`, and including this when built as
// part of `std` means every Rust program gets it. Ideally we would have a link
// modifier to only include these if they are used, but we do not.
#[cfg_attr(not(feature = "rustc-dep-of-std"), 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;
// part of `std` means every Rust program gets it. Additionally, when not built
// as part of `std`, merely using `libc` on an Apple target will pull in `libiconv`.
//
// Therefore, due to these functions very low usage numbers on the platform, we hide it
// behind a feature flag.
//
// Ideally we would have a link modifier to only include these if they are used, but we do not.
cfg_if! {
if #[cfg(feature = "iconv-apple")] {
#[link(name = "iconv")]
mod iconv;
pub use self::iconv::*;
}
}

cfg_if! {
Expand Down