From 2f066aeb51c9968a0b9e68277e53c67d9a4d03e0 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Fri, 29 Mar 2019 18:01:47 +0530 Subject: [PATCH 1/3] meson: Add autodetection to the iconv combo option Instead of requiring the user to specify which option to use, which they will not really know, nor should they need to know. Search for each type of iconv (in the C library, as a separate native library, as the GNU implementation) by default. Fixes https://gitlab.gnome.org/GNOME/glib/issues/1557 --- meson.build | 45 ++++++++++++++++++++++----------------------- meson_options.txt | 6 +++--- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/meson.build b/meson.build index b80264759..0ec80c177 100644 --- a/meson.build +++ b/meson.build @@ -1693,39 +1693,38 @@ glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack) # USE_LIBICONV_GNU: Using GNU libiconv # USE_LIBICONV_NATIVE: Using a native impl of iconv in a separate library # -# We should never use the MinGW C library's iconv. On Windows we use the -# GNU implementation that ships with MinGW. - -# On Windows, just always use the built-in implementation +# We should never use the MinGW C library's iconv because it may not be +# available in the actual runtime environment. On Windows, we always use +# the built-in implementation +iconv_opt = get_option('iconv') if host_system == 'windows' libiconv = [] + # We have a #include "win_iconv.c" in gconvert.c on Windows, so we don't need + # any external library for it glib_conf.set('USE_LIBICONV_NATIVE', true) + if iconv_opt != 'auto' + warning('-Diconv was set to @0@, which was ignored') + endif else found_iconv = false - iconv_opt = get_option('iconv') - if iconv_opt == 'libc' - if cc.has_function('iconv_open') - libiconv = [] - found_iconv = true - endif - elif iconv_opt == 'gnu' - if cc.has_header_symbol('iconv.h', 'libiconv_open') - glib_conf.set('USE_LIBICONV_GNU', true) - libiconv = [cc.find_library('iconv')] - found_iconv = true - endif - elif iconv_opt == 'native' - if cc.has_header_symbol('iconv.h', 'iconv_open') - glib_conf.set('USE_LIBICONV_NATIVE', true) - libiconv = [cc.find_library('iconv')] - found_iconv = true - endif + if ['auto', 'libc'].contains(iconv_opt) and cc.has_function('iconv_open') + libiconv = [] + found_iconv = true + endif + if not found_iconv and ['auto', 'native'].contains(iconv_opt) and cc.has_header_symbol('iconv.h', 'iconv_open') + glib_conf.set('USE_LIBICONV_NATIVE', true) + libiconv = [cc.find_library('iconv')] + found_iconv = true + endif + if not found_iconv and ['auto', 'gnu'].contains(iconv_opt) and cc.has_header_symbol('iconv.h', 'libiconv_open') + glib_conf.set('USE_LIBICONV_GNU', true) + libiconv = [cc.find_library('iconv')] + found_iconv = true endif if not found_iconv error('iconv implementation "@0@" not found'.format(iconv_opt)) endif - endif if get_option('internal_pcre') diff --git a/meson_options.txt b/meson_options.txt index 897d06607..0841f6bfe 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -5,9 +5,9 @@ option('runtime_libdir', option('iconv', type : 'combo', - choices : ['libc', 'gnu', 'native'], - value : 'libc', - description : 'iconv implementation to use (\'libc\' = \'Part of the C stdlib\'; \'gnu\' = \'GNU\'s iconv\'; \'native\' = \'A separate iconv\')') + choices : ['auto', 'libc', 'native', 'gnu'], + value : 'auto', + description : 'iconv implementation to use (\'libc\' = \'Part of the C stdlib\'; \'gnu\' = \'GNU\'s iconv\'; \'native\' = \'A separate iconv\'; \'auto\' = \'Auto-detect which iconv is available\')') option('charsetalias_dir', type : 'string', From ace32cd8e2a012f33ebd780e53631b5a2cd03c23 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 4 Apr 2019 05:12:35 +0530 Subject: [PATCH 2/3] gconvert: Don't differentiate between GNU iconv and macOS iconv Both provide iconv_open, and in fact, we weren't using the difference anywhere in glib at all. --- glib/gconvert.c | 8 -------- meson.build | 12 +----------- meson_options.txt | 4 ++-- 3 files changed, 3 insertions(+), 21 deletions(-) diff --git a/glib/gconvert.c b/glib/gconvert.c index 707867951..c5857df1c 100644 --- a/glib/gconvert.c +++ b/glib/gconvert.c @@ -52,14 +52,6 @@ #include "glibintl.h" -#if defined(USE_LIBICONV_GNU) && !defined (_LIBICONV_H) -#error GNU libiconv in use but included iconv.h not from libiconv -#endif -#if !defined(USE_LIBICONV_GNU) && defined (_LIBICONV_H) \ - && !defined (__APPLE_CC__) && !defined (__LP_64__) -#error GNU libiconv not in use but included iconv.h is from libiconv -#endif - /** * SECTION:conversions diff --git a/meson.build b/meson.build index 0ec80c177..85433fb3b 100644 --- a/meson.build +++ b/meson.build @@ -1690,9 +1690,6 @@ glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack) # Tests for iconv # -# USE_LIBICONV_GNU: Using GNU libiconv -# USE_LIBICONV_NATIVE: Using a native impl of iconv in a separate library -# # We should never use the MinGW C library's iconv because it may not be # available in the actual runtime environment. On Windows, we always use # the built-in implementation @@ -1701,7 +1698,6 @@ if host_system == 'windows' libiconv = [] # We have a #include "win_iconv.c" in gconvert.c on Windows, so we don't need # any external library for it - glib_conf.set('USE_LIBICONV_NATIVE', true) if iconv_opt != 'auto' warning('-Diconv was set to @0@, which was ignored') endif @@ -1711,13 +1707,7 @@ else libiconv = [] found_iconv = true endif - if not found_iconv and ['auto', 'native'].contains(iconv_opt) and cc.has_header_symbol('iconv.h', 'iconv_open') - glib_conf.set('USE_LIBICONV_NATIVE', true) - libiconv = [cc.find_library('iconv')] - found_iconv = true - endif - if not found_iconv and ['auto', 'gnu'].contains(iconv_opt) and cc.has_header_symbol('iconv.h', 'libiconv_open') - glib_conf.set('USE_LIBICONV_GNU', true) + if not found_iconv and ['auto', 'external'].contains(iconv_opt) and cc.has_header_symbol('iconv.h', 'iconv_open') libiconv = [cc.find_library('iconv')] found_iconv = true endif diff --git a/meson_options.txt b/meson_options.txt index 0841f6bfe..2c831e37e 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -5,9 +5,9 @@ option('runtime_libdir', option('iconv', type : 'combo', - choices : ['auto', 'libc', 'native', 'gnu'], + choices : ['auto', 'libc', 'external'], value : 'auto', - description : 'iconv implementation to use (\'libc\' = \'Part of the C stdlib\'; \'gnu\' = \'GNU\'s iconv\'; \'native\' = \'A separate iconv\'; \'auto\' = \'Auto-detect which iconv is available\')') + description : 'iconv implementation to use (\'libc\' = \'Part of the C library\'; \'external\' = \'External libiconv\'; \'auto\' = \'Auto-detect which iconv is available\')') option('charsetalias_dir', type : 'string', From 17823fa82033dbac16e7ef7a746be7ca46892a85 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 4 Apr 2019 05:25:58 +0530 Subject: [PATCH 3/3] ci: The iconv combo option values have changed --- .gitlab-ci.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8897da3e1..c9cd70f32 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -95,7 +95,9 @@ cross-android_api21_arm64: <<: *cross-template script: # FIXME: add --werror - - meson ${MESON_COMMON_OPTIONS} --cross-file=/opt/cross_file_android_arm64_21.txt -Diconv=gnu -Dinternal_pcre=true _build + # We use -Diconv=auto to test that we successfully detect that iconv is not + # provided by android api 21, and detect the external iconv instead. + - meson ${MESON_COMMON_OPTIONS} --cross-file=/opt/cross_file_android_arm64_21.txt -Diconv=auto -Dinternal_pcre=true _build - ninja -C _build cross-android_api28_arm64: @@ -173,10 +175,10 @@ freebsd-11-x86_64: LANG: en_US.UTF-8 script: # We cannot use -Wl,--no-undefined because GLib uses 'environ' variable. - # FreeBSD iconv doesn't handle transliteration, so we use GNU libiconv here. + # FreeBSD iconv doesn't handle transliteration, so we use (external) GNU libiconv here. # FreeBSD supports xattr, but its API is different from Linux xattr. # FIXME: extattr(2) support: https://gitlab.gnome.org/GNOME/glib/issues/1404 - - meson ${MESON_COMMON_OPTIONS} -Db_lundef=false -Diconv=gnu -Dxattr=false _build + - meson ${MESON_COMMON_OPTIONS} -Db_lundef=false -Diconv=external -Dxattr=false _build - ninja -C _build - bash -x ./.gitlab-ci/run-tests.sh except: