On 4/27/23 11:41, Andrea Bolognani wrote: > This fixes cross-building in some scenarios. > > Specifically, when building for armv7l on x86_64, has_header() > will see the x86_64 version of the header and consider it usable. > Later, when an attempt is made to actually use it, the compiler > will quickly realize that things can't quite work. > > The reason why we haven't hit this in our CI is that we only ever > install the foreign version of header files. When building the > Debian package, however, some of the Debian-specific tooling will > bring in the native version of the Linux headers in addition to > the foreign one, causing Meson to misreport the header's > availability status. > > Checking for its actual usability, as opposed to mere presence, > is enough to make things work correctly in all cases. > > https://bugs.debian.org/1024504 > > Suggested-by: Helmut Grohne <helmut@xxxxxxxxxx> > Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx> > --- > meson.build | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/meson.build b/meson.build > index d35d5e076b..21a4bd5b37 100644 > --- a/meson.build > +++ b/meson.build > @@ -614,7 +614,6 @@ headers = [ > 'asm/hwcap.h', > 'ifaddrs.h', > 'libtasn1.h', > - 'linux/kvm.h', > 'mntent.h', > 'net/ethernet.h', > 'net/if.h', > @@ -635,12 +634,24 @@ if host_machine.system() == 'freebsd' > headers += 'libutil.h' > endif > > +# headers for which we need to check actual usability. in most > +# cases, checking for presence is enough (and it's way faster) > +check_headers = [ > + 'linux/kvm.h', > +] > + > foreach name : headers > if cc.has_header(name) > conf.set('WITH_@0@'.format(name.underscorify().to_upper()), 1) > endif > endforeach > > +foreach name : check_headers > + if cc.check_header(name) > + conf.set('WITH_@0@'.format(name.underscorify().to_upper()), 1) > + endif > +endforeach > + > # check for kernel header required by src/util/virnetdevbridge.c > if host_machine.system() == 'linux' > if not cc.has_header('linux/sockios.h') One could argue, that the semantics of has_header() is broken then. What good is there to check if the host has a header file when compiler rejects it subsequently? But leaving meson aside, shouldn't we just use check_header() for every header file then? I mean, this fixes this particular instance of the problem, but can't we hit it again with say ifaddrs.h or any other header file on the list? Michal