Fix build of llvmjit_types.bc with meson
Thread notes
1 note#bug
hackorum-bot#bug
@global #bug
Hi,
When building on mac with both NLS and LLVM enabled using meson:
meson setup --prefix=$HOME/.local/ -Dbuildtype=debug -Dllvm=enabled
-Dicu=enabled -Dnls=enabled -Dextra_lib_dirs=/opt/homebrew/lib
-Dextra_include_dirs=/opt/homebrew/include ../
Compilation fails with the following error:
clang -c -o src/backend/jit/llvm/llvmjit_types.bc
../src/backend/jit/llvm/llvmjit_types.c -flto=thin -emit-llvm -MD -MQ
src/backend/jit/llvm/llvmjit_types.bc -MF
src/backend/jit/llvm/llvmjit_types.c.bc.d -O2 -Wno-ignored-attributes
-Wno-empty-body -fno-strict-aliasing -fwrapv
-I/opt/homebrew/opt/openssl@3/include
-I./src/include -I./src/backend/utils/misc -I../src/include
In file included from ../src/backend/jit/llvm/llvmjit_types.c:27:
In file included from ../src/include/postgres.h:48:
../src/include/c.h:82:10: fatal error: 'libintl.h' file not found
82 | #include <libintl.h>
| ^~~~~~~~~~~
The failure happens in the custom_target llvmjit_types.bc. The missing
libintl.h header is available in /opt/homebrew/include/libintl.h which is
provided as an extra_include_dirs. However, it won't be used by the
custom_target which hardcodes the include path.
This patch modifies llvmjit_types.bc's include paths to use postgres_inc_d
which includes paths provided in extra_include_dirs.
The code relies on meson's '/' behaviour[1]https://mesonbuild.com/Syntax.html#string-path-building which drops all segments before
an absolute path. With /opt/homebrew/include as an extra include dir,
'meson.project_source_root() / inc_d' will yield /opt/homebrew/include.
I've also removed the include of src/backend/utils/misc which doesn't seem
necessary? The only header there is guc_internal.h which is only used by
files in the same directory.
BUILD_ROOT and SOURCE_ROOT were also replaced by meson.project_build_root
and meson.project_source_root. BUILD_ROOT and SOURCE_ROOT provide the
source root of the main project if called from a subproject, preventing the
use of postgres as a subproject.
If you test with LLVM21, you will need to apply the patch provided in [2]/messages/by-id/44718204-61a5-91b1-5574-154ff7a019f6@applied-asynchrony.com
as compilation will fail without this patch.
[1]: https://mesonbuild.com/Syntax.html#string-path-building
[2]: /messages/by-id/44718204-61a5-91b1-5574-154ff7a019f6@applied-asynchrony.com
/messages/by-id/44718204-61a5-91b1-5574-154ff7a019f6@applied-asynchrony.com
On Mon, Nov 17, 2025 at 11:09 PM Anthonin Bonnefoy
<anthonin.bonnefoy@datadoghq.com> wrote:
The failure happens in the custom_target llvmjit_types.bc. The missing libintl.h header is available in /opt/homebrew/include/libintl.h which is provided as an extra_include_dirs. However, it won't be used by the custom_target which hardcodes the include path.
Right. I noticed that problem too. There are a couple of related
proposals over here:
/messages/by-id/CA+hUKGKispvxLyrBn3=3mp0BB1N+RBYR5eE2guCOksnwEoOcPQ@mail.gmail.com
I think Andres and Tristan are probably right that extra_include_dirs
should go into cppflags. I would additionally also like to continue
my struggle to make it so that you don't even need extra_include_dirs
on a Mac or similar as long as pkg_config can find everything, but the
sticking point is libintl, which lacks a .pc file. I think my attempt
at that might not work for Brew though...