-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support custom encodings on Windows through GNU libiconv #11480
Support custom encodings on Windows through GNU libiconv #11480
Conversation
Co-authored-by: Oleh Prypin <[email protected]>
require "c/stddef" | ||
|
||
{% if flag?(:without_iconv) %} | ||
{% raise "The `without_iconv` flag is preventing you to use the LibIconv module" %} |
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.
{% raise "The `without_iconv` flag is preventing you to use the LibIconv module" %} | |
{% raise "The `without_iconv` flag is preventing you from using the LibIconv module" %} |
…vil/crystal into feature/windows-libiconv
Every invocation of Crystal now gives a warning
https://github.com/crystal-lang/crystal/runs/4338209730?check_suite_focus=true#step:37:34 Currently that disrupts compilation of Shards |
This PR adds support for
IO
s with custom encodings on Windows, using https://github.com/pffang/libiconv-for-Windows, which wraps GNU libiconv in an MSVC project.To make things work more generically across platforms, there is now a new flag
-Dwithout_iconv
which disables both libiconv and the built-iniconv_*
functions from the C library, plus all the associated tests; any attempt to use custom encodings will raise during runtime, similar to Windows before this PR. This is useful when the target platform has a poor iconv implementation (e.g. Android NDK) and libiconv is not yet available on that platform. The code below is all that is needed to select between libiconv and iconv at the moment:Thus Windows is hardcoded to use libiconv, and other platforms will continue to use iconv, but it is easy to change this in the future. If
-Dwithout_iconv
is provided thensrc/crystal/iconv.cr
itself would not be required.The decision to distinguish
LibIconv
fromLibC
is intentional, because they are not strictly API-compatible (e.g. FreeBSD has__iconv
, GNU libiconv hasiconvctl
).Related: #5430