systemd / casync

Content-Addressable Data Synchronization Tool
1.5k stars 117 forks source link

build: check for renameat2()/copy_file_range() with _GNU_SOURCE #160

Closed ignatenkobrain closed 5 years ago

ignatenkobrain commented 6 years ago

The config.h which we generate doesn't apply for checks and those functions are available only when _GNU_SOURCE is defined.

Signed-off-by: Igor Gnatenko i.gnatenko.brain@gmail.com

keszybz commented 6 years ago

There's a gotcha. If you look at the log file, meson sometimes includes its own header before the text specified through prefix. It doesn't do that with .has_function, but it does e.g. with .sizeof. If I have

conf.set('SIZEOF_PID_T', cc.sizeof('pid_t', prefix : '''#define _GNU_SOURCE
#include <sys/types.h>'''))

this is turned into

 #include<stdio.h>
        #define _GNU_SOURCE
#include <sys/types.h>
        int main(int argc, char **argv) {
            printf("%ld\n", (long)(sizeof(pid_t)));
            return 0;
        };

Including stdio.h first defeats the define.

In systemd we used args instead: https://github.com/systemd/systemd/blob/master/meson.build#L435 args is undocumented, but seems to work with sizeof and has_function. Your version would work for has_function, but it depends on meson not adding any pre-prefix, and the same form cannot be used with sizeof. So I think it'd be better to use args everywhere.

Long term, hopefully meson will allow simply setting arguments for the compiler used for checks.

ignatenkobrain commented 6 years ago

@keszybz then we need to fix compiler.sizeof() function. This is clearly a bug there. Using args is not really nice because it is not documented

nirbheek commented 6 years ago

then we need to fix compiler.sizeof() function. This is clearly a bug there.

Yes. The fix is a two-liner. I filed https://github.com/mesonbuild/meson/issues/3912

Using args is not really nice because it is not documented

It's documented: https://mesonbuild.com/Reference-manual.html#compiler-object

keszybz commented 6 years ago

https://mesonbuild.com/Compiler-properties.html#does-a-function-exist doesn't mention it ;( I expect that's where most people will look, because it's easier to find and longer.

keszybz commented 5 years ago

OK, let's merge.