Skip to content

Commit eff2283

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

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
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/iconv.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extern "C" {
2+
pub fn iconv_open(tocode: *const ::c_char, fromcode: *const ::c_char) -> iconv_t;
3+
pub fn iconv(
4+
cd: iconv_t,
5+
inbuf: *mut *mut ::c_char,
6+
inbytesleft: *mut ::size_t,
7+
outbuf: *mut *mut ::c_char,
8+
outbytesleft: *mut ::size_t,
9+
) -> ::size_t;
10+
pub fn iconv_close(cd: iconv_t) -> ::c_int;
11+
}

src/unix/bsd/apple/mod.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -5908,19 +5908,19 @@ 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"))]
5914-
extern "C" {
5915-
pub fn iconv_open(tocode: *const ::c_char, fromcode: *const ::c_char) -> iconv_t;
5916-
pub fn iconv(
5917-
cd: iconv_t,
5918-
inbuf: *mut *mut ::c_char,
5919-
inbytesleft: *mut ::size_t,
5920-
outbuf: *mut *mut ::c_char,
5921-
outbytesleft: *mut ::size_t,
5922-
) -> ::size_t;
5923-
pub fn iconv_close(cd: iconv_t) -> ::c_int;
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_if! {
5919+
if #[cfg(feature = "iconv-apple")] {
5920+
#[link(name = "iconv")]
5921+
mod iconv;
5922+
pub use self::iconv::*;
5923+
}
59245924
}
59255925

59265926
cfg_if! {

0 commit comments

Comments
 (0)