Skip to content

cmake: detect and use libc-provided iconv#4777

Merged
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/cmake-iconv-via-libc
Aug 24, 2018
Merged

cmake: detect and use libc-provided iconv#4777
ethomson merged 1 commit into
libgit2:masterfrom
pks-t:pks/cmake-iconv-via-libc

Conversation

@pks-t

@pks-t pks-t commented Aug 24, 2018

Copy link
Copy Markdown
Member

While most systems provide a separate iconv library against which
applications can link, musl based systems do not provide such a library.
Instead, iconv functions are directly included in the C library. As our
current CMake module to locate the iconv library only checks whether a
library exists somewhere in the typical library directories, we will
never build libgit2 with libiconv support on such systems.

Extend the iconv module to also search whether libc provides iconv
functions, which we do by checking whether the iconv_open function
exists inside of libc. If this is the case, we will default to use the
libc provided one instead of trying to use a separate libiconv. While
this changes which iconv we use on systems where both libc and an
external libiconv exist, to the best of my knowledge common systems only
provide either one or the other.

Note that libiconv support in musl is held kind of basic. To quote musl
libc's page on functional differences from glibc 1:

The iconv implementation musl is very small and oriented towards
being unobtrusive to static link. Its character set/encoding
coverage is very strong for its size, but not comprehensive like
glibc’s.

As we assume iconv to be a lot more capable than what musl provides,
some of our tests will fail if using iconv on musl-based platforms.

While most systems provide a separate iconv library against which
applications can link, musl based systems do not provide such a library.
Instead, iconv functions are directly included in the C library. As our
current CMake module to locate the iconv library only checks whether a
library exists somewhere in the typical library directories, we will
never build libgit2 with libiconv support on such systems.

Extend the iconv module to also search whether libc provides iconv
functions, which we do by checking whether the `iconv_open` function
exists inside of libc. If this is the case, we will default to use the
libc provided one instead of trying to use a separate libiconv. While
this changes which iconv we use on systems where both libc and an
external libiconv exist, to the best of my knowledge common systems only
provide either one or the other.

Note that libiconv support in musl is held kind of basic. To quote musl
libc's page on functional differences from glibc [1]:

    The iconv implementation musl is very small and oriented towards
    being unobtrusive to static link. Its character set/encoding
    coverage is very strong for its size, but not comprehensive like
    glibc’s.

As we assume iconv to be a lot more capable than what musl provides,
some of our tests will fail if using iconv on musl-based platforms.

[1]: https://wiki.musl-libc.org/functional-differences-from-glibc.html
@ethomson

Copy link
Copy Markdown
Member

Seems reasonable to me. My only concern is that if we start running the iconv tests against various, possibly inferior, iconv implementations that we'll start getting reports of test failures with them. (You mentioned that musl's iconv is intentionally incomplete.)

It would be a disappointment to get these reports when we don't actually even use iconv on those platforms. In our (non-test) production code, iconv is only used for filename translation on macOS, IIRC. (Am I misremembering something? I may be.)

I think that I remember hearing suggestions about doing more with charset translations (and thus, iconv) at the last Git Contributor Summit, so I think that this makes sense but let's make sure that if we start failing then we don't spend time fixing tests that don't actually matter.

@ethomson ethomson merged commit 8856337 into libgit2:master Aug 24, 2018
@pks-t pks-t deleted the pks/cmake-iconv-via-libc branch August 24, 2018 10:18
@pks-t

pks-t commented Aug 24, 2018

Copy link
Copy Markdown
Member Author

I share your concerns. I decided to just go ahead though because

  1. We do not build with libiconv support by default, so this doesn't change anything per se
  2. As soon as we get reports regarding the tests I will fix them like I said, by dynamically determining whether we have "complete" iconv support. If not, we'll then just skip the tests
  3. I think people running musl libc are generally aware that a lot of things don't quite work (at least I am). This cannot really be blamed on musl libc, as their goal is to be as POSIX conform as possible. This can rather be blamed on glibc, which is not POSIX conform in quite a lot of places and has many extensions that aren't standardized.

So, yeah. It's basically a "Let's see what happens. And if something happens, some things cannot be blamed on us and the others can trivially be fixed."

@ethomson

Copy link
Copy Markdown
Member

So, yeah. It's basically a "Let's see what happens. And if something happens, some things cannot be blamed on us and the others can trivially be fixed."

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants