Re: meson: pass OpenSSL/ICU include dirs to extensions

From: Aidar Imamov <imamovaj22(at)gmail(dot)com>
To: Grigorev Jurij <ju(dot)grigorev(at)ftdata(dot)ru>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: meson: pass OpenSSL/ICU include dirs to extensions
Date: 2026-10-14 15:08:36
Message-ID: 0D9E3874-1AE2-4179-A8F3-6BF1AE2D192E@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Sep 30, 2026, at 07:53, Grigorev Jurij <ju(dot)grigorev(at)ftdata(dot)ru> wrote:
>
> Hi Aidar,
>
> Thanks for the quick update. v2 looks much closer to me!
>
> I like that both pkgconfig and cmake are covered now, and that all include dirs are kept.
> Placement still looks right too: OpenSSL in CPPFLAGS and ICU in ICU_CFLAGS,
> matching Makefile.global and autoconf.
>
> Three small worries, all about cases where flags end up silently empty:
>
> First, the hand-rolled pkg-config call:
>> if ssl.type_name() == 'pkgconfig' and pkg_config.found()
>> openssl_cflags = run_command(pkg_config, '--cflags', 'openssl',
>> check: false).stdout().strip()
>
> Could we check returncode() here, use native: true, and query "icu-uc icu-i18n" together like configure does?
> Right now a failed pkg-config just gives empty flags, and the extension fails much later with a missing header.
>
>
> Second, pkg_config is defined in one file but used in another:
>> src/include/meson.build:
>> pkg_config = find_program( 'pkg-config', required: false)
>
>> src/makefiles/meson.build:
>> if icu.type_name() == 'pkgconfig' and pkg_config.found()
>
> It works today because of subdir ordering, but it is fragile.
> Maybe move it up or look it up locally?
>
>
> Third, the cmake branch:
>> foreach d : ssl.get_variable(cmake: 'OPENSSL_INCLUDE_DIR',
>> default_value: '').split(';')
>
> Are OPENSSL_INCLUDE_DIR and ICU_INCLUDE_DIRS valid for
> both Find-modules and upstream config files? With default_value: ''
> a wrong name just means empty flags. Same for find_library deps --
> I agree extra_include_dirs is a separate gap, but a short comment would help.
>
> One question, not a blocker: with this split, pg_config --cppflags still misses ICU,
> unlike autoconf. PGXS make is fine through $(ICU_CFLAGS), but direct
> pg_config users are not. Is that an acceptable divergence, or should ICU
> go to var_cppflags as well?
>
> Btw the fake .pc test idea sounds good as a follow-up! No need to block v3 on it from my side.
> Thanks again for picking this up!
>
> Kind regards,
> Yuriy

Hi Yuriy,

Thanks for the careful review. v3 attached.

> Could we check returncode(), use native: true, and query
> "icu-uc icu-i18n" together like configure does?

returncode() is checked now, and a failure is a hard error carrying
pkg-config's stderr, same as python_includespec effectively does. ICU is
queried as "icu-uc icu-i18n" in one call. While there I made the call
mirror Meson's own pkg-config invocation: it sets PKG_CONFIG_PATH from
the pkg_config_path option, and PKG_CONFIG_SYSROOT_DIR /
PKG_CONFIG_LIBDIR from the sys_root / pkg_config_libdir properties.
v2 silently used the shell environment instead, so with
-Dpkg_config_path=... it could query a different .pc than Meson used.
This also covers the sysroot concern from your first review.

I did not use native: true, though. Meson looks up pkg-config for host
dependencies on the host machine (cross-file entry, then PKG_CONFIG,
then PATH). native: true would skip the cross-file entry and query the
build machine's .pc files. The default find_program() lookup is the
same one Meson uses.

> pkg_config is defined in one file but used in another

All flag extraction now lives in one block in the top-level meson.build,
after all dependencies are resolved. src/include and src/makefiles only
consume the result.

> Are OPENSSL_INCLUDE_DIR and ICU_INCLUDE_DIRS valid for both
> Find-modules and upstream config files?

Good catch, and the answer was "no" for OpenSSL. Meson's CMake trace
only records set() calls, and FindOpenSSL assigns OPENSSL_INCLUDE_DIR
via find_path() only, so in the default module mode v2 always produced
empty flags. Only OpenSSL's upstream OpenSSLConfig.cmake set()s it.
v3 uses PACKAGE_INCLUDE_DIRS instead, which Meson's CMake wrapper
derives from <Name>_INCLUDE_DIRS / _INCLUDES / _INCLUDE_DIR. I checked
it against FindOpenSSL, OpenSSLConfig.cmake and FindICU (ICU ships no
config files). It's internal to Meson, but has been there since at
least 0.57.2. If it ever comes up empty, setup emits a warning instead
of silently producing nothing. A comment now explains the 'system'
method (headers already on the default path) and the find_library /
extra_include_dirs gap.

> should ICU go to var_cppflags as well?

pg_config --cppflags now includes ICU, for parity with autoconf. It's
added to VAL_CPPFLAGS only, not Makefile.global's CPPFLAGS, so PGXS
doesn't get it twice. One note: since af2d4ca191a no installed header
includes ICU anymore, so on master the ICU part is about autoconf
parity and extensions using ICU themselves.

Regards,
Aidar Imamov

Attachment Content-Type Size
v3-0001-meson-Expose-OpenSSL-and-ICU-compiler-flags-to-PG.patch application/octet-stream 7.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Melanie Plageman 2026-10-14 15:08:40 Re: PG19: two RI fast-path issues found while testing the batching revert
Previous Message Tom Lane 2026-10-14 15:07:39 Re: Fix numeric log() with an infinite value and 0<base<=1