0001-Fix-meson-function-tests.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. From 4840ffe9e8610934d91b27061ff149cc74b41c28 Mon Sep 17 00:00:00 2001
  2. From: Bernd Schubert <bschubert@ddn.com>
  3. Date: Thu, 24 Apr 2025 16:49:08 +0200
  4. Subject: [PATCH] Fix meson function tests
  5. Several meson tests were incorrectly failing
  6. Checking for function "static_assert" : NO (cached)
  7. Checking for function "pthread_setname_np" : NO (cached)
  8. Check usable header "#include <linux/close_range.h>" : NO (cached)
  9. These functions get now tested with compilation tests
  10. and get found on my system.
  11. Checking if "static_assert check" compiles: YES
  12. Checking if "pthread_setname_np check" compiles: YES
  13. Checking if "close_range check" compiles: YES
  14. Upstream: https://github.com/libfuse/libfuse/commit/82bcd818fb3e7d5ced9b0c04b7b7a98a892e807e
  15. Signed-off-by: Bernd Schubert <bschubert@ddn.com>
  16. Signed-off-by: Giulio Benetti <giulio.benetti@benettiengineering.com>
  17. ---
  18. meson.build | 67 +++++++++++++++++++++++++++++++++++++++--------------
  19. 1 file changed, 49 insertions(+), 18 deletions(-)
  20. diff --git a/meson.build b/meson.build
  21. index ba551ed..d1346d0 100644
  22. --- a/meson.build
  23. +++ b/meson.build
  24. @@ -59,6 +59,8 @@ include_default = '''
  25. #include <sys/types.h>
  26. #include <sys/stat.h>
  27. #include <fcntl.h>
  28. +#include <assert.h> /* For static_assert */
  29. +#include <pthread.h> /* For pthread_setname_np */
  30. '''
  31. args_default = [ '-D_GNU_SOURCE' ]
  32. @@ -72,32 +74,61 @@ private_cfg.set_quoted('PACKAGE_VERSION', meson.project_version())
  33. # Test for presence of some functions
  34. test_funcs = [ 'fork', 'fstatat', 'openat', 'readlinkat', 'pipe2',
  35. 'splice', 'vmsplice', 'posix_fallocate', 'fdatasync',
  36. - 'utimensat', 'copy_file_range', 'fallocate', 'static_assert',
  37. - 'pthread_setname_np' ]
  38. + 'utimensat', 'copy_file_range', 'fallocate' ]
  39. foreach func : test_funcs
  40. private_cfg.set('HAVE_' + func.to_upper(),
  41. cc.has_function(func, prefix: include_default, args: args_default))
  42. endforeach
  43. -private_cfg.set('HAVE_SETXATTR',
  44. - cc.has_function('setxattr', prefix: '#include <sys/xattr.h>'))
  45. -private_cfg.set('HAVE_ICONV',
  46. - cc.has_function('iconv', prefix: '#include <iconv.h>'))
  47. -private_cfg.set('HAVE_BACKTRACE',
  48. - cc.has_function('backtrace', prefix: '#include <execinfo.h>'))
  49. -# Test if headers exist
  50. -private_cfg.set('HAVE_LINUX_CLOSE_RANGE_H',
  51. - cc.check_header('#include <linux/close_range.h>'))
  52. +# Special case checks that need custom code
  53. +special_funcs = {
  54. + 'static_assert': '''
  55. + #include <assert.h>
  56. + static_assert(1, "test");
  57. + int main(void) { return 0; }
  58. + ''',
  59. + 'pthread_setname_np': '''
  60. + #include <pthread.h>
  61. + int main(void) {
  62. + pthread_t thread = pthread_self();
  63. + pthread_setname_np(thread, "test");
  64. + return 0;
  65. + }
  66. + ''',
  67. + 'close_range': '''
  68. + #include <unistd.h>
  69. + #include <fcntl.h>
  70. + #include <linux/close_range.h>
  71. + int main(void) {
  72. + unsigned int flags = CLOSE_RANGE_UNSHARE;
  73. + return close_range(3, ~0U, flags);
  74. + }
  75. + '''
  76. +}
  77. +
  78. +foreach name, code : special_funcs
  79. + private_cfg.set('HAVE_' + name.to_upper(),
  80. + cc.compiles(code, args: ['-Werror'] + args_default,
  81. + name: name + ' check'))
  82. +endforeach
  83. +
  84. +# Regular function checks
  85. +private_cfg.set('HAVE_SETXATTR',
  86. + cc.has_function('setxattr', prefix: '#include <sys/xattr.h>'))
  87. +private_cfg.set('HAVE_ICONV',
  88. + cc.has_function('iconv', prefix: '#include <iconv.h>'))
  89. +private_cfg.set('HAVE_BACKTRACE',
  90. + cc.has_function('backtrace', prefix: '#include <execinfo.h>'))
  91. -# Test if structs have specific member
  92. +# Struct member checks
  93. private_cfg.set('HAVE_STRUCT_STAT_ST_ATIM',
  94. - cc.has_member('struct stat', 'st_atim',
  95. - prefix: include_default,
  96. - args: args_default))
  97. + cc.has_member('struct stat', 'st_atim',
  98. + prefix: include_default + '#include <sys/stat.h>',
  99. + args: args_default))
  100. private_cfg.set('HAVE_STRUCT_STAT_ST_ATIMESPEC',
  101. - cc.has_member('struct stat', 'st_atimespec',
  102. - prefix: include_default,
  103. - args: args_default))
  104. + cc.has_member('struct stat', 'st_atimespec',
  105. + prefix: include_default + '#include <sys/stat.h>',
  106. + args: args_default))
  107. #
  108. # Compiler configuration
  109. --
  110. 2.39.5