Skip to content

Commit 9451504

Browse files
committed
Hide iconv functions on Apple devices behind a feature flag
1 parent 1689b94 commit 9451504

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ align = []
2828
rustc-dep-of-std = ['align', 'rustc-std-workspace-core']
2929
extra_traits = []
3030
const-extern-fn = []
31+
iconv-apple = []
3132
# use_std is deprecated, use `std` instead
3233
use_std = [ 'std' ]
3334

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ libc = "0.2"
3838
If you use Rust >= 1.62, this feature is implicitly enabled.
3939
Otherwise it requires a nightly rustc.
4040

41+
* `iconv-apple`: Enables usage of `iconv_open`, `iconv`, and `iconv_close` on Apple devices.
42+
4143
* **deprecated**: `use_std` is deprecated, and is equivalent to `std`.
4244

4345
## Rust version support

src/unix/bsd/apple/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -5908,9 +5908,15 @@ cfg_if! {
59085908
}
59095909

59105910
// These require a dependency on `libiconv`, and including this when built as
5911-
// part of `std` means every Rust program gets it. Ideally we would have a link
5912-
// modifier to only include these if they are used, but we do not.
5913-
#[cfg_attr(not(feature = "rustc-dep-of-std"), link(name = "iconv"))]
5911+
// part of `std` means every Rust program gets it. Additionally, when not built
5912+
// as part of `std`, merely using `libc` on an Apple target will pull in `libiconv`.
5913+
//
5914+
// Therefore, due to these functions very low usage numbers on the platform, we hide it
5915+
// behind a feature flag.
5916+
//
5917+
// Ideally we would have a link modifier to only include these if they are used, but we do not.
5918+
#[cfg(feature = "iconv-apple")]
5919+
#[link(name = "iconv")]
59145920
extern "C" {
59155921
pub fn iconv_open(tocode: *const ::c_char, fromcode: *const ::c_char) -> iconv_t;
59165922
pub fn iconv(

0 commit comments

Comments
 (0)