From 24ec80cfb4522d9819dbf5fd117665fef20b6418 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Tue, 7 Jun 2022 16:14:04 -0400 Subject: [PATCH] meson: simplify iconv lookups using Meson's builtin dependency lookup iconv is complicated to look up. That complexity now resides in Meson, since 0.60.0, via a `dependency('iconv')` lookup, so use that instead. No effort is made to support the old option for which type of iconv to use. It was a false choice, because if only one was available, then that's the only one you can use, and if both are available, the external iconv shadows the builtin one and renders the builtin one unusable, so there is still only one you can use. This meant that when configuring glib with -Diconv=libc on systems that had an external iconv, the configure check would detect a valid libc iconv, try to use it, and then fail during the build because iconv.h belongs to the external iconv and generates machine code using the external iconv ABI, but fails to link to the iconv `find_library()`. Meson handles this transparently. --- .gitlab-ci.yml | 5 ++--- docs/reference/glib/building.xml | 18 +++++++----------- meson.build | 20 ++------------------ meson_options.txt | 4 ++-- 4 files changed, 13 insertions(+), 34 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6673c237b..518b53e0f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -386,11 +386,10 @@ freebsd-12-x86_64: - bash .gitlab-ci/show-execution-environment.sh script: # We cannot use -Wl,--no-undefined because GLib uses 'environ' variable. - # 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 # localstatedir is needed for access to /var/lib/dbus/machine-id - - meson ${MESON_COMMON_OPTIONS} --localstatedir=/var -Db_lundef=false -Diconv=external -Dxattr=false _build + - meson ${MESON_COMMON_OPTIONS} --localstatedir=/var -Db_lundef=false -Dxattr=false _build - ninja -C _build - bash -x ./.gitlab-ci/run-tests.sh artifacts: @@ -417,7 +416,7 @@ freebsd-13-x86_64: before_script: - bash .gitlab-ci/show-execution-environment.sh script: - - meson ${MESON_COMMON_OPTIONS} --localstatedir=/var -Db_lundef=false -Diconv=external -Dxattr=false _build + - meson ${MESON_COMMON_OPTIONS} --localstatedir=/var -Db_lundef=false -Dxattr=false _build - ninja -C _build - bash -x ./.gitlab-ci/run-tests.sh artifacts: diff --git a/docs/reference/glib/building.xml b/docs/reference/glib/building.xml index d165c5c23..62f1c3bc2 100644 --- a/docs/reference/glib/building.xml +++ b/docs/reference/glib/building.xml @@ -29,7 +29,7 @@ On FreeBSD: - env CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib -Wl,--disable-new-dtags" meson -Dxattr=false -Dinstalled_tests=true -Diconv=external -Db_lundef=false _build + env CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib -Wl,--disable-new-dtags" meson -Dxattr=false -Dinstalled_tests=true -Db_lundef=false _build ninja -C _build @@ -98,16 +98,12 @@ If your system has an iconv() implementation but - you want to use libiconv instead, you can pass the - option to meson. This - forces libiconv to be used. - - - Note that if you have libiconv installed in your default include - search path (for instance, in /usr/local/), but - don't enable it, you will get an error while compiling GLib because - the iconv.h that libiconv installs hides the - system iconv. + you want to use libiconv instead, make sure it is installed to the + default compiler header/library search path (for instance, in + /usr/local/). The iconv.h + that libiconv installs hides the system iconv. Meson then detects + this, recognizes that the system iconv is unusable and the external + one is mandatory, and automatically forces it to be used. If you are using the native iconv implementation on Solaris diff --git a/meson.build b/meson.build index ee0a6234c..424aede80 100644 --- a/meson.build +++ b/meson.build @@ -1976,28 +1976,12 @@ glibconfig_conf.set10('G_HAVE_GROWING_STACK', growing_stack) # 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 - if iconv_opt != 'auto' - warning('-Diconv was set to @0@, which was ignored') - endif + libiconv = [] else - found_iconv = false - if ['auto', 'libc'].contains(iconv_opt) and cc.has_function('iconv_open') - libiconv = [] - found_iconv = true - endif - 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 - - if not found_iconv - error('iconv implementation "@0@" not found'.format(iconv_opt)) - endif + libiconv = dependency('iconv') endif pcre = dependency('libpcre', version: '>= 8.31', required : false) # Should check for Unicode support, too. FIXME diff --git a/meson_options.txt b/meson_options.txt index d1859e939..a52eed9d2 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -7,7 +7,7 @@ option('iconv', type : 'combo', choices : ['auto', 'libc', 'external'], value : 'auto', - description : 'iconv implementation to use (\'libc\' = \'Part of the C library\'; \'external\' = \'External libiconv\'; \'auto\' = \'Auto-detect which iconv is available\')') + deprecated: true,) option('charsetalias_dir', type : 'string', @@ -116,4 +116,4 @@ option('glib_checks', option('libelf', type : 'feature', value : 'auto', - description : 'Enable support for listing and extracting from ELF resource files with gresource tool') \ No newline at end of file + description : 'Enable support for listing and extracting from ELF resource files with gresource tool')