Skip to contentSkip to conversation

meson: disable PCRE2 dependency by default

PATCH Superseded Carlo Marcelo Arenas Belón 6 participants 28 messages Jul 12, 2025 – Jul 24, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 meson: disable PCRE2 dependency by default

Makefile requires the user to provide the USE_LIBPCRE2 flag to enable this dependency, but meson has it enabled by default, which can be problematic, at least in macOS.

While a popular option and matching what was done by cmake (which itself reflects what is preferred by Git for Windows) could result in a broken build or linking with the wrong PCRE2 library.

While not git's fault, macOS provides a PCRE2 library in base that is not usable (even if it would pass the test) and not configured properly, as it installs a pkgconf module that points to a non existent pcre2.h header in /usr/local/include.

Change the default to off, and let the user enable it once a proper dependency is installed or meson instructed to fallback to the wrap.

---
 meson_options.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meson_options.txt +1 -1
index e7f768df24..0a0cac6f99 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'disabled',
   description: 'Support Perl-compatible regular expressions in e.g. git-grep(1).')
 option('perl', type: 'feature', value: 'auto',
   description: 'Build tools written in Perl.')
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw
Quoted 9 lines · Carlo Marcelo Arenas Belón

Makefile requires the user to provide the USE_LIBPCRE2 flag to enable this dependency, but meson has it enabled by default, which can be problematic, at least in macOS.

While a popular option and matching what was done by cmake (which itself reflects what is preferred by Git for Windows) could result in a broken build or linking with the wrong PCRE2 library.

Quoted 8 lines

While not git's fault, macOS provides a PCRE2 library in base that is not usable (even if it would pass the test) and not configured properly, as it installs a pkgconf module that points to a non existent pcre2.h header in /usr/local/include.

Change the default to off, and let the user enable it once a proper dependency is installed or meson instructed to fallback to the wrap.

Can we disable it by default on macOS instead of everywhere? For most builds on Linux, the system libpcre2 is the right one and users will expect to find PCRE support by default.

Signature · 2 lines
brian m. carlson (they/them)
Toronto, Ontario, CA
#2 lore raw
Quoted 16 lines · brian m. carlson
Quoted 14 lines · Carlo Marcelo Arenas Belón

Makefile requires the user to provide the USE_LIBPCRE2 flag to enable this dependency, but meson has it enabled by default, which can be problematic, at least in macOS.

While a popular option and matching what was done by cmake (which itself reflects what is preferred by Git for Windows) could result in a broken build or linking with the wrong PCRE2 library.

While not git's fault, macOS provides a PCRE2 library in base that is not usable (even if it would pass the test) and not configured properly, as it installs a pkgconf module that points to a non existent pcre2.h header in /usr/local/include.

Quoted 5 lines
Quoted 3 lines

Change the default to off, and let the user enable it once a proper dependency is installed or meson instructed to fallback to the wrap.

Can we disable it by default on macOS instead of everywhere?

Yes, but I don't like it much, as it is:

* inconsistent with artifacts created with other build systems
* really an issue that should be fixed by Apple or at least handled better in meson itself.

Quoted 3 lines

For most
builds on Linux, the system libpcre2 is the right one and users will expect to find PCRE support by default.

Agree with you on that, and indeed I think every packager of git (except for NonStop) does enable it at packaging time.

Maybe this is an argument to enable it by default?, one thing that I wonder though, is if we should first isolate the code on its own and link it only with git grep.

I think the rationale behind the current setup was that we will eventually replace all other regex engines with PCRE2, having better performance and retiring compat/regex, but code to do that failed to materialise, and I am not sure how realistic that was.

Carlo

Quoted 3 lines

--
brian m. carlson (they/them)
Toronto, Ontario, CA

#3 lore raw
Quoted 10 lines · Carlo Arenas
Quoted 3 lines

For most
builds on Linux, the system libpcre2 is the right one and users will expect to find PCRE support by default.

Agree with you on that, and indeed I think every packager of git (except for NonStop) does enable it at packaging time.

Maybe this is an argument to enable it by default?, one thing that I wonder though, is if we should first isolate the code on its own and link it only with git grep.

If we decide that PCRE is good enough to do BRE and ERE emulation in compatible enough way more performantly everywhere, it certainly is an option that wrap our calls to platform native regcomp/regexec that we use for our use of BRE/ERE and internally use PCRE for them.

Before that happens, "struct grep_pat" that encapsulates the distinction between using BRE/ERE and PCRE and compile_regexp() that compiles an end-user supplied regular expression string into members of "struct grep_pat" so that it can be used to match against in-core buffer we have, would need to be exposed outside the "grep.[ch]" machinery, and direct uses of regcomp() and regexec() in the rest of the codebase has to be rewritten to work with "struct grep_pat".

And after that happens, teaching "git log --grep=<foo>" and "git blame -L'/<foo>/,/<bar>/'" an equivalent to "git grep -P" option that tells the command that the pattern given is PCRE would come almost for free.

Is that the kind of isolation you are referring to?

#4 lore raw
Quoted 26 lines · Junio C Hamano
Quoted 10 lines · Carlo Arenas
Quoted 3 lines

For most
builds on Linux, the system libpcre2 is the right one and users will expect to find PCRE support by default.

Agree with you on that, and indeed I think every packager of git (except for NonStop) does enable it at packaging time.

Maybe this is an argument to enable it by default?, one thing that I wonder though, is if we should first isolate the code on its own and link it only with git grep.

If we decide that PCRE is good enough to do BRE and ERE emulation in compatible enough way more performantly everywhere, it certainly is an option that wrap our calls to platform native regcomp/regexec that we use for our use of BRE/ERE and internally use PCRE for them.

Before that happens, "struct grep_pat" that encapsulates the distinction between using BRE/ERE and PCRE and compile_regexp() that compiles an end-user supplied regular expression string into members of "struct grep_pat" so that it can be used to match against in-core buffer we have, would need to be exposed outside the "grep.[ch]" machinery, and direct uses of regcomp() and regexec() in the rest of the codebase has to be rewritten to work with "struct grep_pat".

Quoted 6 lines

And after that happens, teaching "git log --grep=<foo>" and "git blame -L'/<foo>/,/<bar>/'" an equivalent to "git grep -P" option that tells the command that the pattern given is PCRE would come almost for free.

Is that the kind of isolation you are referring to?

Thah describes perfectly the probably unrealistic plan I mentioned in the other part of my response that is not quoted above.

This part was more of a: let's assume that we enable PCRE2 by default in the Makefile as well, what is the impact to the libification efforts now that there is a chance that libgit will be linked (probably statically if using meson) with libpcre2?

Sinvce the plan you mentioned above is still dreamware, wouldn't it be better to move all the pcre2 functions out of grep.c, export them back to it through a semi private header and convert git-grep into a standalone binary that might link with pcre2 as needed?

Carlo

#5 lore raw
Quoted 9 lines · Carlo Marcelo Arenas Belón

This part was more of a: let's assume that we enable PCRE2 by default in the Makefile as well, what is the impact to the libification efforts now that there is a chance that libgit will be linked (probably statically if using meson) with libpcre2?

Since the plan you mentioned above is still dreamware, wouldn't it be better to move all the pcre2 functions out of grep.c, export them back to it through a semi private header and convert git-grep into a standalone binary that might link with pcre2 as needed?

The engineering effort that such a move (and encapsulation of "grep_pat" that may or may not have pcre enabled) would go quite a long way and brings us quite a lot close to that "dreamware", I suspect. So it may not be a bad thing.

But even if you move code out of grep.c to a new "abstracted regcomp and regexec that may or may not use pcre" source file, "git grep" would need to run with the code you move to the latter anyway, so unless your plan for libified "git grep" engine is to make the library user responsible for supplying their own "abstracted regcomp and regexec that may or may not use pcre" (and "git grep" brings in its own in that new file), I do not know it changes the picture all that much.

Thanks.

#6 lore raw

PATCH v2 1/1 meson: disable PCRE2 dependency by default in macOS

In reply to Carlo Marcelo Arenas Belón

Makefile requires the user to provide the USE_LIBPCRE2 flag to enable this dependency, but meson has it enabled by default, which can be problematic, at least in macOS.

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non existent pcre2.h header in /usr/local/include.

Add an option that will need to be turned to true once an alternative PCRE2 library is installed (which hopefully provides its own pkgconf module earlier in PKG_CONFIG_PATH) or meson has been instructed to use the wrap by --force-fallback-for=pcre2

---
 meson.build       | 3 ++-
 meson_options.txt | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)
meson.build +2 -1
index 7fea4a34d6..e1475be6c8 100644
@@ -1055,7 +1055,8 @@ else
   build_options_config.set('NO_ICONV', '1')
 endif
 
-pcre2 = dependency('libpcre2-8', required: get_option('pcre2'), default_options: ['default_library=static', 'test=false'])
+pcre2_feature = get_option('pcre2').disable_auto_if(host_machine.system() == 'darwin' and not get_option('macos_workaround_system_pcre2'))
+pcre2 = dependency('libpcre2-8', required: pcre2_feature, default_options: ['default_library=static', 'test=false'])
 if pcre2.found()
   libgit_dependencies += pcre2
   libgit_c_args += '-DUSE_LIBPCRE2'
meson_options.txt +3 -1
index e7f768df24..9c0cb6bbfa 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'auto',
   description: 'Support Perl-compatible regular expressions in e.g. git-grep(1).')
 option('perl', type: 'feature', value: 'auto',
   description: 'Build tools written in Perl.')
@@ -73,6 +73,8 @@ option('breaking_changes', type: 'boolean', value: false,
   description: 'Enable upcoming breaking changes.')
 option('macos_use_homebrew_gettext', type: 'boolean', value: true,
   description: 'Use gettext from Homebrew instead of the slightly-broken system-provided one.')
+option('macos_workaround_system_pcre2', type: 'boolean', value: false,
+  description: 'A working PCRE2 was provided or the fallback to the wrap is being forced.')
 
 # gitweb configuration.
 option('gitweb_config', type: 'string', value: 'gitweb_config.perl')
Signature · 1 line
2.39.5 (Apple Git-154)
#7 lore raw

Re: [PATCH v2] meson: disable PCRE2 dependency by default in macOS

Quoted 4 lines · Carlo Marcelo Arenas Belón

Makefile requires the user to provide the USE_LIBPCRE2 flag to enable this dependency, but meson has it enabled by default, which can be problematic, at least in macOS.

Quoted 8 lines

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non existent pcre2.h header in /usr/local/include.

Add an option that will need to be turned to true once an alternative PCRE2 library is installed (which hopefully provides its own pkgconf module earlier in PKG_CONFIG_PATH) or meson has been instructed to use the wrap by --force-fallback-for=pcre2

Here, and ...

Quoted 34 lines
---
 meson.build       | 3 ++-
 meson_options.txt | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)
meson.build +2 -1
index 7fea4a34d6..e1475be6c8 100644
@@ -1055,7 +1055,8 @@ else
   build_options_config.set('NO_ICONV', '1')
 endif
 
-pcre2 = dependency('libpcre2-8', required: get_option('pcre2'), default_options: ['default_library=static', 'test=false'])
+pcre2_feature = get_option('pcre2').disable_auto_if(host_machine.system() == 'darwin' and not get_option('macos_workaround_system_pcre2'))
+pcre2 = dependency('libpcre2-8', required: pcre2_feature, default_options: ['default_library=static', 'test=false'])
 if pcre2.found()
   libgit_dependencies += pcre2
   libgit_c_args += '-DUSE_LIBPCRE2'
meson_options.txt +1 -1
index e7f768df24..9c0cb6bbfa 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'auto',
   description: 'Support Perl-compatible regular expressions in e.g. git-grep(1).')
 option('perl', type: 'feature', value: 'auto',
   description: 'Build tools written in Perl.')

meson_options.txt option('breaking_changes', type: 'boolean', value: false, · line 77

Quoted 5 lines
meson_options.txt +2 -0
@@ -73,6 +73,8 @@ option('breaking_changes', type: 'boolean', value: false,
   description: 'Enable upcoming breaking changes.')
 option('macos_use_homebrew_gettext', type: 'boolean', value: true,
   description: 'Use gettext from Homebrew instead of the slightly-broken system-provided one.')
+option('macos_workaround_system_pcre2', type: 'boolean', value: false,
+  description: 'A working PCRE2 was provided or the fallback to the wrap is being forced.')

... here, I do not understand what you wanted to refer to with the noun "wrap". Can you please rephrase them to clarify?

Thanks.

Quoted 3 lines
meson_options.txt +0 -0
 # gitweb configuration.
 option('gitweb_config', type: 'string', value: 'gitweb_config.perl')
#8 lore raw

PATCH v3 1/1 meson: disable PCRE2 dependency by default in macOS

In reply to Carlo Marcelo Arenas Belón

Makefile requires the user to provide the USE_LIBPCRE2 flag to enable this dependency, but meson has it enabled by default, which can be problematic, at least in macOS.

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non existent pcre2.h header in /usr/local/include.

Add an option that will need to be turned to true once an alternative PCRE2 library is installed (which hopefully provides its own pkgconf module earlier in PKG_CONFIG_PATH) or meson has been instructed to use its subproject as a suitable dependency by --force-fallback-for=pcre2.

---
 meson.build       | 3 ++-
 meson_options.txt | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)
meson.build +2 -1
index 7fea4a34d6..e1475be6c8 100644
@@ -1055,7 +1055,8 @@ else
   build_options_config.set('NO_ICONV', '1')
 endif
 
-pcre2 = dependency('libpcre2-8', required: get_option('pcre2'), default_options: ['default_library=static', 'test=false'])
+pcre2_feature = get_option('pcre2').disable_auto_if(host_machine.system() == 'darwin' and not get_option('macos_workaround_system_pcre2'))
+pcre2 = dependency('libpcre2-8', required: pcre2_feature, default_options: ['default_library=static', 'test=false'])
 if pcre2.found()
   libgit_dependencies += pcre2
   libgit_c_args += '-DUSE_LIBPCRE2'
meson_options.txt +3 -1
index e7f768df24..f63ff32556 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'auto',
   description: 'Support Perl-compatible regular expressions in e.g. git-grep(1).')
 option('perl', type: 'feature', value: 'auto',
   description: 'Build tools written in Perl.')
@@ -73,6 +73,8 @@ option('breaking_changes', type: 'boolean', value: false,
   description: 'Enable upcoming breaking changes.')
 option('macos_use_homebrew_gettext', type: 'boolean', value: true,
   description: 'Use gettext from Homebrew instead of the slightly-broken system-provided one.')
+option('macos_workaround_system_pcre2', type: 'boolean', value: false,
+  description: 'A working PCRE2 library is available or will be provided by a subproject.')
 
 # gitweb configuration.
 option('gitweb_config', type: 'string', value: 'gitweb_config.perl')
Signature · 1 line
2.39.5 (Apple Git-154)
#9 lore raw

Re: [PATCH v3] meson: disable PCRE2 dependency by default in macOS

Quoted 8 lines · Carlo Marcelo Arenas Belón

Makefile requires the user to provide the USE_LIBPCRE2 flag to enable this dependency, but meson has it enabled by default, which can be problematic, at least in macOS.

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non existent pcre2.h header in /usr/local/include.

Quoted 5 lines

Add an option that will need to be turned to true once an alternative PCRE2 library is installed (which hopefully provides its own pkgconf module earlier in PKG_CONFIG_PATH) or meson has been instructed to use its subproject as a suitable dependency by --force-fallback-for=pcre2.

I cannot possibly agree with any part of this. Right bug report, wrong patch.

Problem:

Meson supports three modes:

- require pcre2 and fail if missing

- automatically, optimistically use it if possible

- disable and reject it even if available

macOS has a problem:

- pcre2 (in modes 1 and 2) is detected as available via a system package, but upon successfully configuring a ninja file, the compile fails

Solution proposed here:

- v1: switch default mode from "enabled" to "disabled", leaving feature broken if anyone tries it out

- v2 / v3: switch default mode from "enabled" to "auto", then ignoring the config setting by default, and permitting users to use an ugly "are you sure" option to get... a failing build.

Nowhere are we checking what we got. Trying to build with pcre2 will fail in confusingly awkward ways at the worst time: compile time. We don't need a build option here to ask for this bad experience -- we should just get it correct. :)

The goal should be, if the pcre2 feature is:

- enabled, meson should *fail early* if the demand cannot be met, providing a clear explanation of what is wrong

- auto, meson should *detect* it cannot work and build without it

Quoted 11 lines
---
 meson.build       | 3 ++-
 meson_options.txt | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)
meson.build +0 -0
index 7fea4a34d6..e1475be6c8 100644

meson.build else · line 1062

Quoted 9 lines
meson.build +2 -1
@@ -1055,7 +1055,8 @@ else
   build_options_config.set('NO_ICONV', '1')
 endif
 
-pcre2 = dependency('libpcre2-8', required: get_option('pcre2'), default_options: ['default_library=static', 'test=false'])
+pcre2_feature = get_option('pcre2').disable_auto_if(host_machine.system() == 'darwin' and not get_option('macos_workaround_system_pcre2'))
+pcre2 = dependency('libpcre2-8', required: pcre2_feature, default_options: ['default_library=static', 'test=false'])
 if pcre2.found()
   libgit_dependencies += pcre2
   libgit_c_args += '-DUSE_LIBPCRE2'

Instead of disable_auto_if, we should simply verify a working install.

if pcre2.found() and pcre2.type_name() != 'internal' and host_machine.system() == 'darwin'
# macOS installs a broken system package, double check if not compiler.has_header('pcre2.h', dependencies: pcre2)
if get_option('pcre2').enabled()
error('broken pcre2 install found but pcre2 is required')
endif
# Replace with not-found-dependency
pcre2 = dependency('', required: false) warning('broken pcre2 install found, disabling pcre2 feature')
endif
endif

if pcre2.found()

    libgit_dependencies += pcre2

[...]

Please double-check my work, that this compiler.has_header() is sufficient on your reproducer system to detect and disable the non-working feature.

meson_options.txt option('gitweb', type: 'feature', value: 'auto', · line 48

Quoted 10 lines
meson_options.txt +1 -1
index e7f768df24..f63ff32556 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'auto',

This part is fine. We shouldn't default-fail if it isn't found, when we can't expect it to be universally available.

Quoted 12 lines
meson_options.txt +2 -0
   description: 'Support Perl-compatible regular expressions in e.g. git-grep(1).')
 option('perl', type: 'feature', value: 'auto',
   description: 'Build tools written in Perl.')
@@ -73,6 +73,8 @@ option('breaking_changes', type: 'boolean', value: false,
   description: 'Enable upcoming breaking changes.')
 option('macos_use_homebrew_gettext', type: 'boolean', value: true,
   description: 'Use gettext from Homebrew instead of the slightly-broken system-provided one.')
+option('macos_workaround_system_pcre2', type: 'boolean', value: false,
+  description: 'A working PCRE2 library is available or will be provided by a subproject.')
 
 # gitweb configuration.
 option('gitweb_config', type: 'string', value: 'gitweb_config.perl')
Signature · 1 line
Eli Schwartz
#10 lore raw

Re: [PATCH v3] meson: disable PCRE2 dependency by default in macOS

Quoted 19 lines · Eli Schwartz
Quoted 5 lines · Carlo Marcelo Arenas Belón
meson.build +0 -0
index 7fea4a34d6..e1475be6c8 100644

meson.build else · line 1062

Quoted 9 lines
meson.build +2 -1
@@ -1055,7 +1055,8 @@ else
   build_options_config.set('NO_ICONV', '1')
 endif
 
-pcre2 = dependency('libpcre2-8', required: get_option('pcre2'), default_options: ['default_library=static', 'test=false'])
+pcre2_feature = get_option('pcre2').disable_auto_if(host_machine.system() == 'darwin' and not get_option('macos_workaround_system_pcre2'))
+pcre2 = dependency('libpcre2-8', required: pcre2_feature, default_options: ['default_library=static', 'test=false'])
 if pcre2.found()
   libgit_dependencies += pcre2
   libgit_c_args += '-DUSE_LIBPCRE2'

Instead of disable_auto_if, we should simply verify a working install.

Quoted 10 lines

if pcre2.found() and pcre2.type_name() != 'internal' and host_machine.system() == 'darwin'
# macOS installs a broken system package, double check if not compiler.has_header('pcre2.h', dependencies: pcre2)
if get_option('pcre2').enabled()
error('broken pcre2 install found but pcre2 is required')
endif
# Replace with not-found-dependency
pcre2 = dependency('', required: false) warning('broken pcre2 install found, disabling pcre2 feature')

Okay. So if the pcre2 feature was explicitly enabled we error out and abort, otherwise we print a warning and disable it. This makes a lot of sense to me.

Quoted 4 lines

endif
endif

if pcre2.found()

Quoted 8 lines
    libgit_dependencies += pcre2

[...]

Please double-check my work, that this compiler.has_header() is sufficient on your reproducer system to detect and disable the non-working feature.

I think auto-detecting such broken PCRE2 libraries is indeed the best way forward, thanks!

Quoted 6 lines
Quoted 6 lines
meson_options.txt +0 -0
index e7f768df24..f63ff32556 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
Quoted 8 lines

meson_options.txt option('gitweb', type: 'feature', value: 'auto', · line 48

Quoted 4 lines
meson_options.txt +1 -1
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'auto',

This part is fine. We shouldn't default-fail if it isn't found, when we can't expect it to be universally available.

Agreed. I guess tha only reason why I picked "enabled" here is because we also got a wrapper in "subprojects/". But with this new workaround in place I agree that it is sensible to switch to "auto".

Patrick

#11 lore raw

Re: [PATCH v3] meson: disable PCRE2 dependency by default in macOS

Quoted 16 lines · Patrick Steinhardt
Quoted 14 lines · Eli Schwartz

On 7/13/25 1:48 PM, Carlo Marcelo Arenas B

meson_options.txt option('gitweb', type: 'feature', value: 'auto', · line 48

Quoted 10 lines
meson_options.txt +1 -1
index e7f768df24..f63ff32556 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'auto',

This part is fine. We shouldn't default-fail if it isn't found, when we can't expect it to be universally available.

Quoted 3 lines

Agreed. I guess tha only reason why I picked "enabled" here is because we also got a wrapper in "subprojects/". But with this new workaround in place I agree that it is sensible to switch to "auto".

AFAIK the "wrapper" fallback still kicks in when the feature is "auto"

Carlo

#12 lore raw

Re: [PATCH v3] meson: disable PCRE2 dependency by default in macOS

Quoted 17 lines · Carlo Arenas
Quoted 16 lines · Patrick Steinhardt
Quoted 14 lines · Eli Schwartz

On 7/13/25 1:48 PM, Carlo Marcelo Arenas B

meson_options.txt option('gitweb', type: 'feature', value: 'auto', · line 48

Quoted 10 lines
meson_options.txt +1 -1
index e7f768df24..f63ff32556 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'auto',

This part is fine. We shouldn't default-fail if it isn't found, when we can't expect it to be universally available.

Quoted 5 lines
Quoted 3 lines

Agreed. I guess tha only reason why I picked "enabled" here is because we also got a wrapper in "subprojects/". But with this new workaround in place I agree that it is sensible to switch to "auto".

AFAIK the "wrapper" fallback still kicks in when the feature is "auto"

It does, yes. But with 'auto' as default it means that we're free to disable PCRE2 if we have detected a broken PCRE2 dependency.

Patrick

#13 lore raw

Re: [PATCH v3] meson: disable PCRE2 dependency by default in macOS

Quoted 19 lines · Patrick Steinhardt
Quoted 17 lines · Carlo Arenas
Quoted 16 lines · Patrick Steinhardt
Quoted 14 lines · Eli Schwartz

On 7/13/25 1:48 PM, Carlo Marcelo Arenas B

meson_options.txt option('gitweb', type: 'feature', value: 'auto', · line 48

Quoted 10 lines
meson_options.txt +1 -1
index e7f768df24..f63ff32556 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'auto',

This part is fine. We shouldn't default-fail if it isn't found, when we can't expect it to be universally available.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Agreed. I guess tha only reason why I picked "enabled" here is because we also got a wrapper in "subprojects/". But with this new workaround in place I agree that it is sensible to switch to "auto".

AFAIK the "wrapper" fallback still kicks in when the feature is "auto"

It does, yes. But with 'auto' as default it means that we're free to disable PCRE2 if we have detected a broken PCRE2 dependency.

My bad, I was mistaken and indeed auto doesn't fallback to the wrap, so this will likely regress in windows if it is not invoked with -Dpcre2=enabled

Carlo

#14 lore raw

Re: [PATCH v3] meson: disable PCRE2 dependency by default in macOS

Quoted 9 lines · Carlo Arenas
Quoted 8 lines · Patrick Steinhardt
Quoted 6 lines · Carlo Arenas
Quoted 3 lines · Patrick Steinhardt

Agreed. I guess tha only reason why I picked "enabled" here is because we also got a wrapper in "subprojects/". But with this new workaround in place I agree that it is sensible to switch to "auto".

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

AFAIK the "wrapper" fallback still kicks in when the feature is "auto"

It does, yes. But with 'auto' as default it means that we're free to disable PCRE2 if we have detected a broken PCRE2 dependency.

My bad, I was mistaken and indeed auto doesn't fallback to the wrap, so this will likely regress in windows if it is not invoked with -Dpcre2=enabled

See
https://mesonbuild.com/Reference-manual_functions.html#dependency_allow_fallback

The default is to fallback to the wrap for *required* dependencies (rather than abort the build). If it's desirable to have "auto" attempt to automatically enable the feature if

system_found || \
(!wrap_mode_nofallback && (have_internet_for_wrap || \
have_locally_downloaded_wrap ))

then you can use that "allow_fallback" kwarg.

Signature · 1 line
Eli Schwartz
#15 lore raw

Re: [PATCH v3] meson: disable PCRE2 dependency by default in macOS

In reply to Eli Schwartz
Quoted 4 lines · Eli Schwartz

Please double-check my work, that this compiler.has_header() is sufficient on your reproducer system to detect and disable the non-working feature.

it is indeed all that was needed, abd makes me wonder if a future version of dependency() shouldn't have a "has_header" parameter like the one used in find_libray() to allow for this validation to happen internally and fallback as needed.

Posted a v4 with your code and modifications to still allow a fallback to the wrap.

Carlo

#16 lore raw

Re: [PATCH v3] meson: disable PCRE2 dependency by default in macOS

Quoted 10 lines · Carlo Arenas
Quoted 4 lines · Eli Schwartz

Please double-check my work, that this compiler.has_header() is sufficient on your reproducer system to detect and disable the non-working feature.

it is indeed all that was needed, abd makes me wonder if a future version of dependency() shouldn't have a "has_header" parameter like the one used in find_libray() to allow for this validation to happen internally and fallback as needed.

It's... possible, I suppose, but usually not needed unless a distributor doesn't respond to reports that their OS is broken. Which well, fair enough, happens. :)

Another possibility is to add a quirk to meson's underlying python code. If pcre2 is searched, and the platform is darwin, also check the header. You'll need a small override in mesonbuild/dependencies/*.py, like:

class PCRE2PkgConfigDependency(PkgConfigDependency):

    def __init__(...):
        super().__init__(...)
        if is_darwin:
            self.is_found = check_that_header()
Quoted 2 lines

Posted a v4 with your code and modifications to still allow a fallback to the wrap.

Thanks. :)

Signature · 1 line
Eli Schwartz
#17 lore raw

PATCH v4 1/1 meson: woraround broken system PCRE2 dependency in macOS

In reply to Carlo Marcelo Arenas Belón

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non existent pcre2.h header in /usr/local/include.

Detect that case and allow a fallback to a wrapped submodule if the feature is enabled and that is possible, or print a warning and disable the feature if the feature was set to "auto". which is the new default.

---
 meson.build       | 20 +++++++++++++++++++-
 meson_options.txt |  2 +-
 2 files changed, 20 insertions(+), 2 deletions(-)
meson.build +19 -1
index 596f5ac711..0e480e65cf 100644
@@ -1055,7 +1055,25 @@ else
   build_options_config.set('NO_ICONV', '1')
 endif
 
-pcre2 = dependency('libpcre2-8', required: get_option('pcre2'), default_options: ['default_library=static', 'test=false'])
+pcre2_feature = get_option('pcre2')
+pcre2 = dependency('libpcre2-8', required: pcre2_feature, default_options: ['default_library=static', 'test=false'])
+if pcre2.found() and pcre2.type_name() != 'internal' and host_machine.system() == 'darwin'
+  # macOS installs a broken system package, double check
+  if not compiler.has_header('pcre2.h', dependencies: pcre2)
+    if pcre2_feature.enabled()
+      # Attempt to fallback
+      pcre2 = dependency('libpcre2-8', required: true, method: 'builtin', default_options: ['default_library=static', 'test=false'])
+      if not pcre2.found()
+        error('only a broken pcre2 install found and pcre2 is required')
+      endif
+    elif pcre2_feature.auto()
+      # Replace with not-found-dependency
+      pcre2 = dependency('', required: false)
+      warning('broken pcre2 install found, disabling pcre2 feature')
+    endif
+  endif
+endif
+
 if pcre2.found()
   libgit_dependencies += pcre2
   libgit_c_args += '-DUSE_LIBPCRE2'
meson_options.txt +1 -1
index e7f768df24..1668f260a1 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'auto',
   description: 'Support Perl-compatible regular expressions in e.g. git-grep(1).')
 option('perl', type: 'feature', value: 'auto',
   description: 'Build tools written in Perl.')
Signature · 1 line
2.39.5 (Apple Git-154)
#18 lore raw

Re: [PATCH v4] meson: woraround broken system PCRE2 dependency in macOS

Quoted 4 lines · Carlo Marcelo Arenas Belón

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non existent pcre2.h header in /usr/local/include.

Quoted 8 lines

Detect that case and allow a fallback to a wrapped submodule if the feature is enabled and that is possible, or print a warning and disable the feature if the feature was set to "auto". which is the new default.

---

Thanks. Will queue.

Quoted 48 lines
 meson.build       | 20 +++++++++++++++++++-
 meson_options.txt |  2 +-
 2 files changed, 20 insertions(+), 2 deletions(-)
meson.build +19 -1
index 596f5ac711..0e480e65cf 100644
@@ -1055,7 +1055,25 @@ else
   build_options_config.set('NO_ICONV', '1')
 endif
 
-pcre2 = dependency('libpcre2-8', required: get_option('pcre2'), default_options: ['default_library=static', 'test=false'])
+pcre2_feature = get_option('pcre2')
+pcre2 = dependency('libpcre2-8', required: pcre2_feature, default_options: ['default_library=static', 'test=false'])
+if pcre2.found() and pcre2.type_name() != 'internal' and host_machine.system() == 'darwin'
+  # macOS installs a broken system package, double check
+  if not compiler.has_header('pcre2.h', dependencies: pcre2)
+    if pcre2_feature.enabled()
+      # Attempt to fallback
+      pcre2 = dependency('libpcre2-8', required: true, method: 'builtin', default_options: ['default_library=static', 'test=false'])
+      if not pcre2.found()
+        error('only a broken pcre2 install found and pcre2 is required')
+      endif
+    elif pcre2_feature.auto()
+      # Replace with not-found-dependency
+      pcre2 = dependency('', required: false)
+      warning('broken pcre2 install found, disabling pcre2 feature')
+    endif
+  endif
+endif
+
 if pcre2.found()
   libgit_dependencies += pcre2
   libgit_c_args += '-DUSE_LIBPCRE2'
meson_options.txt +1 -1
index e7f768df24..1668f260a1 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'auto',
   description: 'Support Perl-compatible regular expressions in e.g. git-grep(1).')
 option('perl', type: 'feature', value: 'auto',
   description: 'Build tools written in Perl.')
#19 lore raw

Re: [PATCH v4] meson: woraround broken system PCRE2 dependency in macOS

In reply to Carlo Marcelo Arenas Belón
Quoted 1 line · Carlo Marcelo Arenas Belón

meson: woraround broken system PCRE2 dependency in macOS

s/woraround/work around/

Quoted 3 lines

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non existent pcre2.h header in /usr/local/include.

s/non existent/non-existent/

Quoted 7 lines

Detect that case and allow a fallback to a wrapped submodule if the feature is enabled and that is possible, or print a warning and disable the feature if the feature was set to "auto". which is the new default.

#20 lore raw

PATCH v5 1/1 meson: work around broken system PCRE2 dependency in macOS

In reply to Carlo Marcelo Arenas Belón

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non-existent pcre2.h header in /usr/local/include.

Detect that case and allow a fallback to a wrapped submodule if the feature is enabled and that is possible, or print a warning and disable the feature if the feature was set to "auto", which is the new default.

To keep consistency with the cmake build system used on Windows, add a special rule to re-enable the pcre2 feature there.

---
 meson.build       | 25 ++++++++++++++++++++++++-
 meson_options.txt |  2 +-
 2 files changed, 25 insertions(+), 2 deletions(-)
meson.build +24 -1
index 596f5ac711..c77ce82bf2 100644
@@ -1055,7 +1055,30 @@ else
   build_options_config.set('NO_ICONV', '1')
 endif
 
-pcre2 = dependency('libpcre2-8', required: get_option('pcre2'), default_options: ['default_library=static', 'test=false'])
+# can't use enable_auto_if() because it is only available in meson 1.1
+if host_machine.system() == 'windows' and get_option('pcre2').allowed()
+  pcre2_feature = true
+else
+  pcre2_feature = get_option('pcre2')
+endif
+pcre2 = dependency('libpcre2-8', required: pcre2_feature, default_options: ['default_library=static', 'test=false'])
+if pcre2.found() and pcre2.type_name() != 'internal' and host_machine.system() == 'darwin'
+  # macOS installs a broken system package, double check
+  if not compiler.has_header('pcre2.h', dependencies: pcre2)
+    if pcre2_feature.enabled()
+      # Attempt to fallback, method can't be pkg-config 
+      pcre2 = dependency('libpcre2-8', method: 'builtin', default_options: ['default_library=static', 'test=false'])
+      if not pcre2.found()
+        error('only a broken pcre2 install found and pcre2 is required')
+      endif
+    else
+      # Replace with not-found-dependency
+      pcre2 = dependency('', required: false)
+      warning('broken pcre2 install found, disabling pcre2 feature')
+    endif
+  endif
+endif
+
 if pcre2.found()
   libgit_dependencies += pcre2
   libgit_c_args += '-DUSE_LIBPCRE2'
meson_options.txt +1 -1
index e7f768df24..1668f260a1 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'auto',
   description: 'Support Perl-compatible regular expressions in e.g. git-grep(1).')
 option('perl', type: 'feature', value: 'auto',
   description: 'Build tools written in Perl.')
Signature · 1 line
2.39.5 (Apple Git-154)
#21 lore raw

Re: [PATCH v5] meson: work around broken system PCRE2 dependency in macOS

Quoted 3 lines · Carlo Marcelo Arenas Belón

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non-existent pcre2.h header in /usr/local/include.

Thanks but unfortunately this came a bit too late after the previous round was merged to 'next' already. If needed, could you make it incremental update on top?

Thanks.

#22 lore raw

Re: [PATCH v5] meson: work around broken system PCRE2 dependency in macOS

Quoted 9 lines · Junio C Hamano
Quoted 3 lines · Carlo Marcelo Arenas Belón

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non-existent pcre2.h header in /usr/local/include.

Thanks but unfortunately this came a bit too late after the previous round was merged to 'next' already. If needed, could you make it incremental update on top?

Oops, sorry, please disregard.

#23 lore raw

Re: [PATCH v5] meson: work around broken system PCRE2 dependency in macOS

In reply to Carlo Marcelo Arenas Belón

meson.build else · line 1072

Quoted 8 lines · Carlo Marcelo Arenas Belón
meson.build +8 -0
+if pcre2.found() and pcre2.type_name() != 'internal' and host_machine.system() == 'darwin'
+  # macOS installs a broken system package, double check
+  if not compiler.has_header('pcre2.h', dependencies: pcre2)
+    if pcre2_feature.enabled()
+      # Attempt to fallback, method can't be pkg-config 
+      pcre2 = dependency('libpcre2-8', method: 'builtin', default_options: ['default_library=static', 'test=false'])
+      if not pcre2.found()
+        error('only a broken pcre2 install found and pcre2 is required')

If you want to override the message from a specific dependency() call, "required" defaults to true and aborts on the line before "if not pcre2.found()"

You could do:
https://mesonbuild.com/Reference-manual_functions.html#dependency_not_found_message

not_found_message: 'only a broken pcre2 install found and pcre2 is required'

Alternatively, required: false followed by if not pcre2.found() --> error(). But you will need "allow_fallback: true" as I responded in a previous message.

Signature · 1 line
Eli Schwartz
#24 lore raw

Re: [PATCH v5] meson: work around broken system PCRE2 dependency in macOS

Quoted 12 lines · Eli Schwartz

meson.build else · line 1072

Quoted 8 lines · Carlo Marcelo Arenas Belón
meson.build +8 -0
+if pcre2.found() and pcre2.type_name() != 'internal' and host_machine.system() == 'darwin'
+  # macOS installs a broken system package, double check
+  if not compiler.has_header('pcre2.h', dependencies: pcre2)
+    if pcre2_feature.enabled()
+      # Attempt to fallback, method can't be pkg-config
+      pcre2 = dependency('libpcre2-8', method: 'builtin', default_options: ['default_library=static', 'test=false'])
+      if not pcre2.found()
+        error('only a broken pcre2 install found and pcre2 is required')
Quoted 3 lines

If you want to override the message from a specific dependency() call, "required" defaults to true and aborts on the line before "if not pcre2.found()"

It is a little hacky, but because we are not using the method: auto, then won't try pkg-config again and fallback to the wrap because as you said, required defaults to true, and allow_fallback is true if required is true.

The only way this dependency() will fail is if --wrap-mode=nofallback and that won't cause it to abort.

Carlo

#25 lore raw

PATCH v6 1/1 meson: work around broken system PCRE2 dependency in macOS

In reply to Carlo Marcelo Arenas Belón

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non-existent pcre2.h header in /usr/local/include.

Detect that case and if the feature is enabled, try to fallback to a wrapped subproject through an anonymous dependency, aborting with an error if that is not possible.

Change the feature to "auto" and print a warning and disable it if a broken dependency was detected, but to keep consistency with the cmake build system used on Windows, add a special rule to re-enable the pcre2 feature by default there.

---
 meson.build       | 28 +++++++++++++++++++++++++++-
 meson_options.txt |  2 +-
 2 files changed, 28 insertions(+), 2 deletions(-)
meson.build +27 -1
index 596f5ac711..5225efb4a6 100644
@@ -1055,7 +1055,33 @@ else
   build_options_config.set('NO_ICONV', '1')
 endif
 
-pcre2 = dependency('libpcre2-8', required: get_option('pcre2'), default_options: ['default_library=static', 'test=false'])
+# can't use enable_auto_if() because it is only available in meson 1.1
+if host_machine.system() == 'windows' and get_option('pcre2').allowed()
+  pcre2_feature = true
+else
+  pcre2_feature = get_option('pcre2')
+endif
+pcre2 = dependency('libpcre2-8', required: pcre2_feature, default_options: ['default_library=static', 'test=false'])
+if pcre2.found() and pcre2.type_name() != 'internal' and host_machine.system() == 'darwin'
+  # macOS installs a broken system package, double check
+  if not compiler.has_header('pcre2.h', dependencies: pcre2)
+    if pcre2_feature.enabled()
+      pcre2_fallback = ['pcre2', 'libpcre2_8']
+    else
+      pcre2_fallback = []
+    endif
+    # Attempt to fallback or replace with not-found-dependency
+    pcre2 = dependency('', required: false, fallback: pcre2_fallback, default_options: ['default_library=static', 'test=false'])
+    if not pcre2.found()
+      if pcre2_feature.enabled()
+        error('only a broken pcre2 install found and pcre2 is required')
+      else
+        warning('broken pcre2 install found, disabling pcre2 feature')
+      endif
+    endif
+  endif
+endif
+
 if pcre2.found()
   libgit_dependencies += pcre2
   libgit_c_args += '-DUSE_LIBPCRE2'
meson_options.txt +1 -1
index e7f768df24..1668f260a1 100644
@@ -45,7 +45,7 @@ option('gitweb', type: 'feature', value: 'auto',
   description: 'Build Git web interface. Requires Perl.')
 option('iconv', type: 'feature', value: 'auto',
   description: 'Support reencoding strings with different encodings.')
-option('pcre2', type: 'feature', value: 'enabled',
+option('pcre2', type: 'feature', value: 'auto',
   description: 'Support Perl-compatible regular expressions in e.g. git-grep(1).')
 option('perl', type: 'feature', value: 'auto',
   description: 'Build tools written in Perl.')
Signature · 1 line
2.39.5 (Apple Git-154)
#26 lore raw

Re: [PATCH v6] meson: work around broken system PCRE2 dependency in macOS

Quoted 13 lines · Carlo Marcelo Arenas Belón

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non-existent pcre2.h header in /usr/local/include.

Detect that case and if the feature is enabled, try to fallback to a wrapped subproject through an anonymous dependency, aborting with an error if that is not possible.

Change the feature to "auto" and print a warning and disable it if a broken dependency was detected, but to keep consistency with the cmake build system used on Windows, add a special rule to re-enable the pcre2 feature by default there.

Quoted 7 lines
---
 meson.build       | 28 +++++++++++++++++++++++++++-
 meson_options.txt |  2 +-
 2 files changed, 28 insertions(+), 2 deletions(-)

The thread went silent after this iteration.

I _think_ it incorporates all the good suggestions offered during the discussion on the previous iterations, but is everybody happy with this version? If so, let me mark the topic for 'next'.

Thanks, all.

#27 lore raw

Re: [PATCH v6] meson: work around broken system PCRE2 dependency in macOS

Quoted 23 lines · Junio C Hamano
Quoted 13 lines · Carlo Marcelo Arenas Belón

macOS provides a PCRE2 library in base that is not usable and not configured properly, as it installs a pkgconf module that points to a non-existent pcre2.h header in /usr/local/include.

Detect that case and if the feature is enabled, try to fallback to a wrapped subproject through an anonymous dependency, aborting with an error if that is not possible.

Change the feature to "auto" and print a warning and disable it if a broken dependency was detected, but to keep consistency with the cmake build system used on Windows, add a special rule to re-enable the pcre2 feature by default there.

Quoted 7 lines
---
 meson.build       | 28 +++++++++++++++++++++++++++-
 meson_options.txt |  2 +-
 2 files changed, 28 insertions(+), 2 deletions(-)
Quoted 7 lines

The thread went silent after this iteration.

I _think_ it incorporates all the good suggestions offered during the discussion on the previous iterations, but is everybody happy with this version? If so, let me mark the topic for 'next'.

Thanks, all.

I think this version is fine. Thanks!

Patrick