Skip to contentSkip to conversation

meson: don't use compiler.has_header

PATCH In review Dylan Baker 2 participants 5 messages Mar 12, 2018 – Mar 13, 2018 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 meson: don't use compiler.has_header

Meson's compiler.has_header is completely useless, it only checks that a header exists, not whether it's usable. This creates problems if a header contains a conditional #error declaration, like so:

Quoted 3 lines

#if __x86_64__

# error "Doesn't work with x86_64!"
#endif

Compiler.has_header will return true in this case, even when compiling for x86_64. This is useless.

Instead, we'll do a compile check so that any #error declarations will be treated as errors, and compilation will work.

Fixes compilation on x32 architecture.

Gentoo Bugzilla: https://bugs.gentoo.org/show_bug.cgi?id=649746
meson bug: https://github.com/mesonbuild/meson/issues/2246

---
 meson.build | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meson.build +2 -2
index df6f2bd2..a0c79e30 100644
@@ -186,10 +186,10 @@ else
   dep_rt = []
 endif
 dep_m = cc.find_library('m', required : false)
-if cc.has_header('sys/sysctl.h')
+if cc.compiles('#include <sys/sysctl.h>', name : 'sys/sysctl.h works')
   config.set10('HAVE_SYS_SYSCTL_H', true)
 endif
-if cc.has_header('sys/select.h')
+if cc.compiles('#include <sys/select.h>', name : 'sys/select.h works')
   config.set10('HAVE_SYS_SELECT_H', true)
 endif
 if cc.has_header_symbol('sys/sysmacros.h', 'major')
Signature · 6 lines
2.16.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Dylan Baker

Meson's compiler.has_header is completely useless, it only checks that a header exists, not whether it's usable. This creates problems if a header contains a conditional #error declaration, like so:

Quoted 3 lines

#if __x86_64__

# error "Doesn't work with x86_64!"
#endif

Compiler.has_header will return true in this case, even when compiling for x86_64. This is useless.

Instead, we'll do a compile check so that any #error declarations will be treated as errors, and compilation will work.

Quoted 6 lines

Fixes compilation on x32 architecture.

Gentoo Bugzilla: https://bugs.gentoo.org/show_bug.cgi?id=649746
meson bug: https://github.com/mesonbuild/meson/issues/2246

Nvm my comment on your mesa patch, you've done this already :)

Sending a couple patches on this bit of the code, they'll be based on top of this patch.

Quoted 28 lines
---
 meson.build | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
meson.build +2 -2
index df6f2bd2..a0c79e30 100644
@@ -186,10 +186,10 @@ else
   dep_rt = []
 endif
 dep_m = cc.find_library('m', required : false)
-if cc.has_header('sys/sysctl.h')
+if cc.compiles('#include <sys/sysctl.h>', name : 'sys/sysctl.h works')
   config.set10('HAVE_SYS_SYSCTL_H', true)
 endif
-if cc.has_header('sys/select.h')
+if cc.compiles('#include <sys/select.h>', name : 'sys/select.h works')
   config.set10('HAVE_SYS_SELECT_H', true)
 endif
 if cc.has_header_symbol('sys/sysmacros.h', 'major')
Signature · 6 lines
2.16.2

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw

PATCH 1/2 meson: make it easy to add headers to check

---
 meson.build | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
meson.build +5 -6
index f4c95394c52e65672f24..3a33928d02a6dce5f075 100644
@@ -186,12 +186,11 @@ else
   dep_rt = []
 endif
 dep_m = cc.find_library('m', required : false)
-if cc.compiles('#include <sys/sysctl.h>', name : 'sys/sysctl.h works')
-  config.set10('HAVE_SYS_SYSCTL_H', true)
-endif
-if cc.compiles('#include <sys/select.h>', name : 'sys/select.h works')
-  config.set10('HAVE_SYS_SELECT_H', true)
-endif
+foreach header : ['sys/sysctl.h', 'sys/select.h']
+  if cc.compiles('#include <@0@>'.format(header), name : '@0@ works'.format(header))
+    config.set10('HAVE_' + header.underscorify().to_upper(), true)
+  endif
+endforeach
 if cc.has_header_symbol('sys/sysmacros.h', 'major')
   config.set10('MAJOR_IN_SYSMACROS', true)
 elif cc.has_header_symbol('sys/mkdev.h', 'major')
Signature · 7 lines
Cheers,
  Eric

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

PATCH 2/2 meson: detect alloca.h

amdgpu makes use of it

---
 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meson.build +1 -1
index 3a33928d02a6dce5f075..f7986af9bb5259be5da5 100644
@@ -186,7 +186,7 @@ else
   dep_rt = []
 endif
 dep_m = cc.find_library('m', required : false)
-foreach header : ['sys/sysctl.h', 'sys/select.h']
+foreach header : ['sys/sysctl.h', 'sys/select.h', 'alloca.h']
   if cc.compiles('#include <@0@>'.format(header), name : '@0@ works'.format(header))
     config.set10('HAVE_' + header.underscorify().to_upper(), true)
   endif
Signature · 7 lines
Cheers,
  Eric

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author Reviewed-by on v1 2/2
#4 lore raw

Re: [PATCH libdrm 2/2] meson: detect alloca.h

Quoting Eric Engestrom (2018-03-13 07:54:12)

Quoted 24 lines

amdgpu makes use of it

---
 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meson.build +1 -1
index 3a33928d02a6dce5f075..f7986af9bb5259be5da5 100644
@@ -186,7 +186,7 @@ else
   dep_rt = []
 endif
 dep_m = cc.find_library('m', required : false)
-foreach header : ['sys/sysctl.h', 'sys/select.h']
+foreach header : ['sys/sysctl.h', 'sys/select.h', 'alloca.h']
   if cc.compiles('#include <@0@>'.format(header), name : '@0@ works'.format(header))
     config.set10('HAVE_' + header.underscorify().to_upper(), true)
   endif
Signature · 2 lines
Cheers,
  Eric

for the series:

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel