Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide iconv functions on Apple devices behind a feature flag #3097

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
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
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
@@ -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
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