-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add bindings for iconv calls #2037
Conversation
r? @JohnTitor (rust-highfive has picked a reviewer for you, use r? to override) |
Already looking into the macOS failure! |
Sorry, I need a bit of help with this — I either misunderstand The original commit, ac6ec1c, failed to build on macOS because it didn't link with macOS build links with It feels like I'm adding the |
99202f7 implements a new approach: build.rs emits |
src/unix/mod.rs
Outdated
@@ -298,6 +299,7 @@ cfg_if! { | |||
} else if #[cfg(feature = "std")] { | |||
// cargo build, don't pull in anything extra as the libstd dep | |||
// already pulls in all libs. | |||
extern {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you clarify why you've added this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, it's a leftover from one of the experiments, 3553014. Will remove this in a second.
Even though this PR passes CI, I'd really like some discussion on whether this even belongs to libc. On one hand it definitely does, since iconv calls are part of POSIX, and are widely implemented. On the other hand, the situation is a bit complicated since BDSs can have two implementations at once: one from libc.so (implementing POSIX), the other from libiconv.so (GNU libiconv implementing POSIX plus GNU extensions). libiconv uses different symbol names ( I doubt it's the crate's job to decide which iconv implementation my app should link to, and so there are a few possible solutions:
I only discovered all these complications once I opened the PR; if I knew of them in advance, I'd open an issue first. Sorry about that! Happy to close this and re-report as an issue if that's what you'd prefer. |
at least on OpenBSD (but I think it is true for several others OS), iconv isn't part of system libc (neither part of libraries provided by the system). iconv is only available as third party library. |
☔ The latest upstream changes (presumably #2052) made this pull request unmergeable. Please resolve the merge conflicts. |
I still want to have the discussion, so I'll hold off making any changes until it's decided if these bindings have a place in this crate. |
Thanks for clarifying, hmm, then I doubt we should this to the UNIX module. And the tweak for Apple targets is tricky, as you said, so it should have some comments at least, I believe. /cc @Amanieu Any thoughts on this? |
I'm thinking option 4 might be the best:
However we should only provide bindings if this API is actually provided by libc. So for example this wouldn't be present on OpenBSD. EDIT: Just to clarify, by "libc" I mean that the library is provided as part of the base OS. So we would still support it on Apple even though it is in libiconv instead of libc. |
FreeBSD-likes all implement iconv: - DragonflyBSD: https://github.com/DragonFlyBSD/DragonFlyBSD/blob/bbb35c81f71fe2a0880a1f8bb77876ee98b63338/include/iconv.h - FreeBSD: https://github.com/freebsd/freebsd-src/blob/a6dc68c0e0f8a24ffaf0b4e78e58141ef7897047/include/iconv.h NetBSD-likes: - NetBSD: https://github.com/NetBSD/src/blob/81a39f60870b617d7fca299c126de6553d78cc5a/include/iconv.h - OpenBSD doesn't implement it macOS: apparently ships a conforming implementation as a separate library: https://stackoverflow.com/questions/57734434/libiconv-or-iconv-undefined-symbol-on-mac-osx/57734435#57734435 Linux: - glibc: https://sourceware.org/git/?p=glibc.git;a=blob;f=iconv/iconv.h;h=fdddf53d99c3046ef9c280db01a425c2f499043e;hb=HEAD - musl: https://git.musl-libc.org/cgit/musl/tree/include/iconv.h?id=455f96857f91d14e193219ca00969354a981c09c
5d81ae2
to
3e4d684
Compare
All done, please take a look. |
@bors r+ |
📌 Commit 3e4d684 has been approved by |
☀️ Test successful - checks-actions, checks-cirrus-freebsd-11, checks-cirrus-freebsd-12, checks-cirrus-freebsd-13 |
@@ -360,6 +361,7 @@ fn test_openbsd(target: &str) { | |||
"pthread_np.h", | |||
"sys/syscall.h", | |||
"sys/shm.h", | |||
"iconv.h", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this break the test on OpenBSD : no iconv.h
file here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just made #2067 to unbreak OpenBSD
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, sorry — that's leftovers from the time when the bindings were in the unix mod. The similar problem affects Android, Solari-sh, Redox and a few other targets, I'll submit a PR fixing that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done: #2068
Remove unused iconv.h includes These are left over from 3e4d684, which added includes to *all* platforms despite adding bindings only to *some* of them. This already broke OpenBSD which doesn't have iconv.h (fixed by 915d8fa), and is just distasteful, so down with those unused includes. (This is a continuation to #2037 and #2067.)
Don't unconditionally link libiconv on macOS. This adds `#[link(name = "iconv")]` to just the iconv symbols so that the library is only linked if the symbols are used. #2037 added a build.rs directive to always link libiconv on Apple platforms, but that shouldn't be necessary. With this change, we can see using `otool -L` that a binary that uses an `iconv` symbol links libiconv, but other binaries don't. Note that this can only be seen with a rustc prior to nightly-2021-03-09, as nightly-2021-03-10 includes rust-lang/rust#82731 which includes #2037, therefore unconditionally linking all Rust binaries to libiconv.
No description provided.