Skip to content

Commit

Permalink
Hide iconv functions on Apple devices behind a feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
winterqt committed Jan 31, 2023
1 parent 1689b94 commit 9b7457b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
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 = []
libiconv-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.

* `libiconv-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: 8 additions & 3 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5908,9 +5908,14 @@ 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"))]
// 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_attr(eature = "libiconv-apple", link(name = "iconv"))]
extern "C" {
pub fn iconv_open(tocode: *const ::c_char, fromcode: *const ::c_char) -> iconv_t;
pub fn iconv(
Expand Down

0 comments on commit 9b7457b

Please sign in to comment.