Repository: mesonbuild/meson

Issue:
sizeof compiler check should #include after {prefix}
Else, things like `#define _GNU_SOURCE` do not get applied to it.

https://github.com/systemd/casync/pull/160#issuecomment-406201718


Discussion:

Resolving patch:
diff --git a/mesonbuild/compilers/mixins/clike.py b/mesonbuild/compilers/mixins/clike.py
--- a/mesonbuild/compilers/mixins/clike.py
+++ b/mesonbuild/compilers/mixins/clike.py
@@ -498,8 +498,8 @@ def run(self, code: 'mesonlib.FileOrString', env: 'Environment', *,
     def _compile_int(self, expression: str, prefix: str, env: 'Environment',
                      extra_args: T.Union[None, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]],
                      dependencies: T.Optional[T.List['Dependency']]) -> bool:
-        t = f'''#include <stdio.h>
-        {prefix}
+        t = f'''{prefix}
+        #include <stdio.h>
         int main(void) {{ static int a[1-2*!({expression})]; a[0]=0; return 0; }}'''
         return self.compiles(t, env, extra_args=extra_args,
                              dependencies=dependencies)[0]
@@ -559,8 +559,8 @@ def compute_int(self, expression: str, low: T.Optional[int], high: T.Optional[in
             extra_args = []
         if self.is_cross:
             return self.cross_compute_int(expression, low, high, guess, prefix, env, extra_args, dependencies)
-        t = f'''#include<stdio.h>
-        {prefix}
+        t = f'''{prefix}
+        #include<stdio.h>
         int main(void) {{
             printf("%ld\\n", (long)({expression}));
             return 0;
@@ -578,8 +578,8 @@ def cross_sizeof(self, typename: str, prefix: str, env: 'Environment', *,
                      dependencies: T.Optional[T.List['Dependency']] = None) -> int:
         if extra_args is None:
             extra_args = []
-        t = f'''#include <stdio.h>
-        {prefix}
+        t = f'''{prefix}
+        #include <stdio.h>
         int main(void) {{
             {typename} something;
             return 0;
@@ -598,8 +598,8 @@ def sizeof(self, typename: str, prefix: str, env: 'Environment', *,
             r = self.cross_sizeof(typename, prefix, env, extra_args=extra_args,
                                   dependencies=dependencies)
             return r, False
-        t = f'''#include<stdio.h>
-        {prefix}
+        t = f'''{prefix}
+        #include<stdio.h>
         int main(void) {{
             printf("%ld\\n", (long)(sizeof({typename})));
             return 0;
@@ -617,8 +617,8 @@ def cross_alignment(self, typename: str, prefix: str, env: 'Environment', *,
                         dependencies: T.Optional[T.List['Dependency']] = None) -> int:
         if extra_args is None:
             extra_args = []
-        t = f'''#include <stdio.h>
-        {prefix}
+        t = f'''{prefix}
+        #include <stdio.h>
         int main(void) {{
             {typename} something;
             return 0;
@@ -626,8 +626,8 @@ def cross_alignment(self, typename: str, prefix: str, env: 'Environment', *,
         if not self.compiles(t, env, extra_args=extra_args,
                              dependencies=dependencies)[0]:
             return -1
-        t = f'''#include <stddef.h>
-        {prefix}
+        t = f'''{prefix}
+        #include <stddef.h>
         struct tmp {{
             char c;
             {typename} target;
@@ -643,9 +643,9 @@ def alignment(self, typename: str, prefix: str, env: 'Environment', *,
             r = self.cross_alignment(typename, prefix, env, extra_args=extra_args,
                                      dependencies=dependencies)
             return r, False
-        t = f'''#include <stdio.h>
+        t = f'''{prefix}
+        #include <stdio.h>
         #include <stddef.h>
-        {prefix}
         struct tmp {{
             char c;
             {typename} target;


Test patch: