[PATCH v6 2/9] meson.build: older macOS targeting compatibility with macOS 15.4 SDK

Mohamed Mediouni posted 9 patches 1 month ago
Maintainers: Pedro Barbuda <pbarbuda@microsoft.com>, Mohamed Mediouni <mohamed@unpredictable.fr>, Paolo Bonzini <pbonzini@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Peter Maydell <peter.maydell@linaro.org>, Cameron Esfahani <dirty@apple.com>, Roman Bolshakov <rbolshakov@ddn.com>, Phil Dennis-Jordan <phil@philjordan.eu>, Wei Liu <wei.liu@kernel.org>
[PATCH v6 2/9] meson.build: older macOS targeting compatibility with macOS 15.4 SDK
Posted by Mohamed Mediouni 1 month ago
Using strchrnul eagerly results in a failure to compile when using the newest SDKs, with:

error: 'strchrnul' is only available on macOS 15.4 or newer [-Werror,-Wunguarded-availability-new]

Working around that by not using strchrnul when targeting macOS.

This didn't show up on the CI because it used the macOS 15.1 SDK instead of a macOS 15.4 SDK or later.

Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
---
 meson.build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 7b4e5bc72b..78bde0611b 100644
--- a/meson.build
+++ b/meson.build
@@ -2646,7 +2646,12 @@ config_host_data.set('HAVE_COPY_FILE_RANGE', cc.has_function('copy_file_range'))
 config_host_data.set('HAVE_GETIFADDRS', cc.has_function('getifaddrs'))
 config_host_data.set('HAVE_GLIB_WITH_SLICE_ALLOCATOR', glib_has_gslice)
 config_host_data.set('HAVE_OPENPTY', cc.has_function('openpty', dependencies: util))
-config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul', prefix: osdep_prefix))
+
+# strchrnul was introduced in macOS 15.4.
+# Keep this condition for compatibility of new macOS SDKs with older releases.
+if host_os != 'darwin'
+  config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul', prefix: osdep_prefix))
+endif
 config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix: '#include <stdlib.h>'))
 if rbd.found()
   config_host_data.set('HAVE_RBD_NAMESPACE_EXISTS',
-- 
2.50.1 (Apple Git-155)
Re: [PATCH v6 2/9] meson.build: older macOS targeting compatibility with macOS 15.4 SDK
Posted by Paolo Bonzini 1 month ago
On 3/7/26 19:18, Mohamed Mediouni wrote:
> Using strchrnul eagerly results in a failure to compile when using the newest SDKs, with:
>
> error: 'strchrnul' is only available on macOS 15.4 or newer [-Werror,-Wunguarded-availability-new]
>
> Working around that by not using strchrnul when targeting macOS.
>
> This didn't show up on the CI because it used the macOS 15.1 SDK instead of a macOS 15.4 SDK or later.
>
> Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
> ---
>   meson.build | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/meson.build b/meson.build
> index 7b4e5bc72b..78bde0611b 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -2646,7 +2646,12 @@ config_host_data.set('HAVE_COPY_FILE_RANGE', cc.has_function('copy_file_range'))
>   config_host_data.set('HAVE_GETIFADDRS', cc.has_function('getifaddrs'))
>   config_host_data.set('HAVE_GLIB_WITH_SLICE_ALLOCATOR', glib_has_gslice)
>   config_host_data.set('HAVE_OPENPTY', cc.has_function('openpty', dependencies: util))
> -config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul', prefix: osdep_prefix))
> +
> +# strchrnul was introduced in macOS 15.4.
> +# Keep this condition for compatibility of new macOS SDKs with older releases.
> +if host_os != 'darwin'
> +  config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul', prefix: osdep_prefix))
> +endif

Is -Wunguarded-availability-new enabled by default?  If it is enough to
shut up the compiler maybe you can add a -mmacosx-version-min= flag, but
workarounds on each function are not acceptable.

I'm applying the other patches, but for this one I don't think this is
the right fix.


Paolo
Re: [PATCH v6 2/9] meson.build: older macOS targeting compatibility with macOS 15.4 SDK
Posted by Mohamed Mediouni 1 month ago

> On 9. Mar 2026, at 09:20, Paolo Bonzini <pbonzini@redhat.com> wrote:
> 
> On 3/7/26 19:18, Mohamed Mediouni wrote:
>> Using strchrnul eagerly results in a failure to compile when using the newest SDKs, with:
>> 
>> error: 'strchrnul' is only available on macOS 15.4 or newer [-Werror,-Wunguarded-availability-new]
>> 
>> Working around that by not using strchrnul when targeting macOS.
>> 
>> This didn't show up on the CI because it used the macOS 15.1 SDK instead of a macOS 15.4 SDK or later.
>> 
>> Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
>> ---
>>  meson.build | 7 ++++++-
>>  1 file changed, 6 insertions(+), 1 deletion(-)
>> 
>> diff --git a/meson.build b/meson.build
>> index 7b4e5bc72b..78bde0611b 100644
>> --- a/meson.build
>> +++ b/meson.build
>> @@ -2646,7 +2646,12 @@ config_host_data.set('HAVE_COPY_FILE_RANGE', cc.has_function('copy_file_range'))
>>  config_host_data.set('HAVE_GETIFADDRS', cc.has_function('getifaddrs'))
>>  config_host_data.set('HAVE_GLIB_WITH_SLICE_ALLOCATOR', glib_has_gslice)
>>  config_host_data.set('HAVE_OPENPTY', cc.has_function('openpty', dependencies: util))
>> -config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul', prefix: osdep_prefix))
>> +
>> +# strchrnul was introduced in macOS 15.4.
>> +# Keep this condition for compatibility of new macOS SDKs with older releases.
>> +if host_os != 'darwin'
>> +  config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul', prefix: osdep_prefix))
>> +endif
> 
> Is -Wunguarded-availability-new enabled by default?

Hello,

Yes, it’s enabled by default at least by the CI.

> If it is enough to shut up the compiler maybe you can add a -mmacosx-version-min= flag, but
> workarounds on each function are not acceptable.
> 
-mmacosx-version-min=15.4 or later would be overriding the macOS minimum version set by the user or
corresponding to the host machine QEMU is built on.

Another way would be to have the has_function have -Werror which should be enough to deal with
this case properly. Does that sound better?

For meson not sure whether it actually picks up the definition from the header or tries to use a dummy
definition though from looking at https://github.com/mesonbuild/meson/blob/6e67be7492d6982d2baf153387f9adbdb480d099/mesonbuild/compilers/mixins/clike.py#L738

If it picks the definition from the header, having Werror there ought to be enough. Otherwise, won’t be caught...

Thank you,
-Mohamed

> I'm applying the other patches, but for this one I don't think this is
> the right fix.
> 
> 
> Paolo
> 
Re: [PATCH v6 2/9] meson.build: older macOS targeting compatibility with macOS 15.4 SDK
Posted by Paolo Bonzini 1 month ago
On Mon, Mar 9, 2026 at 9:38 AM Mohamed Mediouni
<mohamed@unpredictable.fr> wrote:
> Another way would be to have the has_function have -Werror which should be enough to deal with
> this case properly. Does that sound better?

Yes, if that works it's better. For 11.1 we can look into adding
-Werror to all cc.has_function() calls.

> For meson not sure whether it actually picks up the definition from the header or tries to use a dummy
> definition though from looking at https://github.com/mesonbuild/meson/blob/6e67be7492d6982d2baf153387f9adbdb480d099/mesonbuild/compilers/mixins/clike.py#L738
> If it picks the definition from the header, having Werror there ought to be enough. Otherwise, won’t be caught...

If you have a "#include <>" in the prefix it will pick the declaration:

        if '#include' in prefix:
            head, main = self._have_prototype_templ()
        else:
            head, main = self._no_prototype_templ()

which is also something that we can add to 11.1.

Paolo