diff mbox series

[8/9] meson: fix compilation with Visual Studio

Message ID 20250113-b4-pks-meson-additions-v1-8-97f6a93f691d@pks.im (mailing list archive)
State Superseded
Headers show
Series meson: a couple of additions | expand

Commit Message

Patrick Steinhardt Jan. 13, 2025, 8:33 a.m. UTC
The Visual Studio compiler defaults to C89 unless explicitly asked to
use a different version of the C standard. We don't specify any C
standard at all though in our Meson build, and consequently compiling
Git fails:

    ...\git\git-compat-util.h(14): fatal error C1189: #error:  "Required C99 support is in a test phase.  Please see git-compat-util.h for more details."

Fix the issue by specifying the project's C standard. Funny enough,
specifying C99 does not work because apparently, `__STDC_VERSION__` is
not getting defined in that version at all. Instead, we have to specify
C11 as the project's C standard, which is also done in our CMake build
instructions.

We don't want to generally enforce C11 though, as our requiremets only
state that a C99 compiler is required. In fact, we don't even require
plain C99, but rather the GNU variant thereof.

Meson allows us to handle this case rather easily by specifying
"gnu99,c11", which will cause it to fall back to C11 in case GNU C99 is
unsupported. This feature has only been introduced with Meson 1.3.0
though, and we support 0.61.0 and newer. In case we use such an oldish
version though we fall back to requiring GNU99 unconditionally. This
means that Windows essentially requires Meson 1.3.0 and newer when using
Visual Studio, but I doubt that this is ever going to be a real problem.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 meson.build | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

M Hickford Jan. 13, 2025, 9:12 p.m. UTC | #1
On 2025-01-13 08:33, Patrick Steinhardt wrote:
> The Visual Studio compiler defaults to C89 unless explicitly asked to
> use a different version of the C standard. We don't specify any C
> standard at all though in our Meson build, and consequently compiling
> Git fails:
> 
>      ...\git\git-compat-util.h(14): fatal error C1189: #error:  "Required C99 support is in a test phase.  Please see git-compat-util.h for more details."
> 
> Fix the issue by specifying the project's C standard. Funny enough,
> specifying C99 does not work because apparently, `__STDC_VERSION__` is
> not getting defined in that version at all. Instead, we have to specify
> C11 as the project's C standard, which is also done in our CMake build
> instructions.
> 
> We don't want to generally enforce C11 though, as our requiremets only
> state that a C99 compiler is required. In fact, we don't even require
> plain C99, but rather the GNU variant thereof.
> 
> Meson allows us to handle this case rather easily by specifying
> "gnu99,c11", which will cause it to fall back to C11 in case GNU C99 is
> unsupported. This feature has only been introduced with Meson 1.3.0
> though, and we support 0.61.0 and newer. In case we use such an oldish
> version though we fall back to requiring GNU99 unconditionally. This
> means that Windows essentially requires Meson 1.3.0 and newer when using
> Visual Studio, but I doubt that this is ever going to be a real problem.
> 
> Signed-off-by: Patrick Steinhardt <ps@pks.im>

Thanks. This fixes the problem for me.

Tested-by: M Hickford <mirth.hickford@gmail.com>

> ---
>   meson.build | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/meson.build b/meson.build
> index cb352ce6fd50616e3281a776104692c5b2bfa5b2..831da1d43cafe85a8c9ac872e141476adbc08188 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -171,6 +171,14 @@
>   project('git', 'c',
>     meson_version: '>=0.61.0',
>     version: files('GIT-VERSION'),
> +  default_options: [
> +    # Git requires C99 with GNU extensions, which of course isn't supported by
> +    # MSVC. Funny enough, C99 doesn't work with MSVC either, as it has only
> +    # learned to define __STDC_VERSION__ with C11 and later. We thus require
> +    # GNU C99 and fall back to C11. Meson only learned to handle the fallback
> +    # with version 1.3.0, so on older versions we use GNU C99 unconditionally.
> +    'c_std=' + (meson.version().version_compare('>=1.3.0') ? 'gnu99,c11' : 'gnu99'),
> +  ]
>   )
>   
>   fs = import('fs')
>
diff mbox series

Patch

diff --git a/meson.build b/meson.build
index cb352ce6fd50616e3281a776104692c5b2bfa5b2..831da1d43cafe85a8c9ac872e141476adbc08188 100644
--- a/meson.build
+++ b/meson.build
@@ -171,6 +171,14 @@ 
 project('git', 'c',
   meson_version: '>=0.61.0',
   version: files('GIT-VERSION'),
+  default_options: [
+    # Git requires C99 with GNU extensions, which of course isn't supported by
+    # MSVC. Funny enough, C99 doesn't work with MSVC either, as it has only
+    # learned to define __STDC_VERSION__ with C11 and later. We thus require
+    # GNU C99 and fall back to C11. Meson only learned to handle the fallback
+    # with version 1.3.0, so on older versions we use GNU C99 unconditionally.
+    'c_std=' + (meson.version().version_compare('>=1.3.0') ? 'gnu99,c11' : 'gnu99'),
+  ]
 )
 
 fs = import('fs')