meson: detect memfd_create() and getrandom() from headers, not system libraries
Some checks are pending
macOS-CI / macOS-CI (dri) (push) Waiting to run
macOS-CI / macOS-CI (xlib) (push) Waiting to run

When compiling Mesa on Android targeting Android, under some conditions `memfd_create()` and `getrandom()` are detected as available when they are not, so they should not be assumed to be available unless they are detected by Meson as available in the appropriate header passed in the `prefix` argument to Meson's `has_function()` method.

`memfd_create()` is not available unless the target Android API level is 30 (Android 11) or higher and the define `_GNU_SOURCE` (which in turn sets the define `__USE_GNU`) is set, and Mesa does set `_GNU_SOURCE`, so by setting `args: pre_args` in the appropriate call to `has_function()` (which causes `-D_GNU_SOURCE` to be added to the arguments used by Meson to check the header only if it was detected as necessary for `pre_args` in the earlier condition), `memfd_create()` will be correctly detected as available when targeting (only) Android 11 or newer (and other operating systems that support `memfd_create()`) after this PR,

and `getrandom()` is not available unless the target Android API level is 28 (Android 9) or higher, so `getrandom()` will be detected as available when targeting (only) Android 9 or newer (and other operating systems that support `getrandom()`) after this PR.

Related information:

https://android.googlesource.com/platform/bionic/+/refs/heads/android15-release/libc/include/sys/mman.h#186

https://android.googlesource.com/platform/bionic/+/refs/heads/android15-release/libc/include/sys/random.h#55

https://android.googlesource.com/platform/bionic/+/refs/heads/android15-release/libc/include/sys/cdefs.h#182

927f65caf3/meson.build (L1074)

cab3b67cfe/docs/markdown/Compiler-properties.md (does-a-function-exist)

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/13566
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37630>
This commit is contained in:
Fafa Kitten 2025-09-30 01:42:57 -05:00
parent 927f65caf3
commit 42a78a1aae

View file

@ -1400,11 +1400,11 @@ endforeach
functions_to_detect = {
'strtof': '',
'mkostemp': '',
'memfd_create': '',
'memfd_create': '#include <sys/mman.h>',
'random_r': '',
'flock': '',
'strtok_r': '',
'getrandom': '',
'getrandom': '#include <sys/random.h>',
'qsort_s': '',
'posix_fallocate': '',
'secure_getenv': '',
@ -1412,7 +1412,7 @@ functions_to_detect = {
}
foreach f, prefix: functions_to_detect
if cc.has_function(f, prefix: prefix)
if cc.has_function(f, args: pre_args, prefix: prefix)
pre_args += '-DHAVE_@0@'.format(f.to_upper())
endif
endforeach