[gjs/master.windows: 1/3] meson: Fix Windows builds against mozjs-78 and later




commit a3349b316c53bfc40de568f567d371f8ac660f2b
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Fri Aug 21 11:47:11 2020 +0800

    meson: Fix Windows builds against mozjs-78 and later
    
    Since Spidermonkey 78, the headers shipped with it do not work on Visual Studio
    builds without major and intrusive changes, so make the Meson build files work
    for using CLang's `clang-cl` compiler, which is CLang that tries hard to
    emulate the MSVC compiler and is the compiler that is being used to build
    SpiderMonkey on Windows nowadays.  As a result, we use Meson's
    `cxx.get_argument_syntax() == 'msvc'` rather than `cxx.get_id() === 'msvc'`
    (and so for the c compiler), so that we cover the case where we are using
    `clang-cl`.
    
    This also means that an error message will be displayed when one tries to use
    the Visual Studio compiler when building GJS, and that we can start sharing
    some of the compiler flags that is also being used for GCC (and other CLang)
    builds.  This also means that we can clean up the build files a little bit.
    
    However, this will still require and use Microsoft's Windows SDK's headers and
    libraries, so there are some Visual Studio-specific compiler flags that needs
    to be kept, and the Cairo dependencies continue to be searched manually in
    cases where the pkg-config files for them cannot be found.
    
    Note that if the other dependencies of GJS were built with Visual Studio, they
    do not need to be recompiled with `clang-cl` as long as they link to the same
    C Runtime library DLL.

 installed-tests/js/meson.build |  6 ++---
 installed-tests/meson.build    |  4 +--
 meson.build                    | 57 ++++++++++++++++++------------------------
 meson_options.txt              |  2 +-
 4 files changed, 31 insertions(+), 38 deletions(-)
---
diff --git a/installed-tests/js/meson.build b/installed-tests/js/meson.build
index 9c424418..a9c030b9 100644
--- a/installed-tests/js/meson.build
+++ b/installed-tests/js/meson.build
@@ -17,8 +17,8 @@ gi_tests = gidatadir / 'tests'
 test_gir_extra_c_args = []
 test_gir_warning_c_args = []
 
-if cc.get_id() == 'msvc'
-  # We need to ensure the symbols in the test DLLs export in MSVC builds
+if cc.get_argument_syntax() == 'msvc'
+  # We need to ensure the symbols in the test DLLs export in clang-cl builds
   test_gir_extra_c_args += ['-D_GI_EXTERN=__declspec(dllexport)extern']
 else
   # These consist of external code (from gobject-introspection) so they should not
@@ -33,7 +33,7 @@ if build_cairo
     regress_gir_includes += 'cairo-1.0'
     regress_dependencies += [cairo, cairo_gobject]
 else
-    regress_gir_c_args = ['-D_GI_DISABLE_CAIRO']
+    regress_gir_c_args += ['-D_GI_DISABLE_CAIRO']
 endif
 
 regress_sources = [
diff --git a/installed-tests/meson.build b/installed-tests/meson.build
index 9210957f..04c7910f 100644
--- a/installed-tests/meson.build
+++ b/installed-tests/meson.build
@@ -8,8 +8,8 @@ installed_tests_metadir = abs_datadir / 'installed-tests' / meson.project_name()
 simple_tests = []
 
 # The test scripts need to be ported from shell scripts
-# for MSVC builds, which do not use BASH-style shells
-if cxx.get_id() != 'msvc'
+# for clang-cl builds, which do not use BASH-style shells
+if cxx.get_argument_syntax() != 'msvc'
     simple_tests += [
         'CommandLine',
         'Warnings',
diff --git a/meson.build b/meson.build
index dcc12ddf..0ccbac7c 100644
--- a/meson.build
+++ b/meson.build
@@ -25,35 +25,28 @@ endif
 cxx = meson.get_compiler('cpp')
 cc = meson.get_compiler('c')
 
-if cxx.get_id() == 'msvc'
+add_project_arguments(cxx.get_supported_arguments([
+    '-fno-strict-aliasing',
+
+    # Ignore spurious compiler warnings for things that GLib and SpiderMonkey
+    # header files commonly do
+    '-Wno-variadic-macros',  # GLib uses these in header files
+    '-Wno-missing-field-initializers',  # SpiderMonkey JSClass, among others
+]), language: 'cpp')
+
+add_project_arguments(cc.get_supported_arguments([
+    '-Wno-typedef-redefinition',  # GLib does this in header files
+]), language: 'c')
+
+if cc.get_argument_syntax() == 'msvc'
+    if cc.get_id() == 'msvc'
+        error('Buliding GJS with Visual Studio compilers is no longer supported.  Please use `clang-cl`.')
+    endif
     add_project_arguments(cxx.get_supported_arguments([
-        '-utf-8',  # Use UTF-8 mode
-        '-Dssize_t=gssize',  # Visual Studio do not come with ssize_t
-        '-Zc:externConstexpr',  # Required for 'extern constexpr' on MSVC
+        '-Dssize_t=gssize',  # Windows SDK/MSVC headers do not come with ssize_t
         '-DNOMINMAX',  # We don't want 'min' or 'max' to interfere
-
-        # Ignore spurious compiler warnings for things that
-        # GLib and SpiderMonkey header files commonly do
-        '-FImsvc_recommended_pragmas.h',
-        '-EHsc',
-        '-wd4099',
-        '-wd4251',
-        '-wd4291',
-        '-wd4800',
-    ]), language: ['cpp', 'c'])
+        ]), language: ['cpp', 'c'])
 else
-    add_project_arguments(cxx.get_supported_arguments([
-        '-fno-strict-aliasing',
-
-        # Ignore spurious compiler warnings for things that GLib and SpiderMonkey
-        # header files commonly do
-        '-Wno-variadic-macros',  # GLib uses these in header files
-        '-Wno-missing-field-initializers',  # SpiderMonkey JSClass, among others
-    ]), language: 'cpp')
-    add_project_arguments(cc.get_supported_arguments([
-        '-Wno-typedef-redefinition',  # GLib does this in header files
-    ]), language: 'c')
-
     if get_option('bsymbolic_functions')
         if not cxx.has_link_argument('-Bsymbolic-functions')
             error('''-Bsymbolic-functions not supported, configure with
@@ -73,7 +66,7 @@ endif
 # match that option because we need to derive from SpiderMonkey classes
 if get_option('spidermonkey_rtti')
     if cxx.has_argument('-GR-')
-        add_project_arguments('-GR-', language: 'cpp')  # MSVC option
+        add_project_arguments('-GR-', language: 'cpp')  # MSVC/clang-cl option
     endif
 else
     if cxx.has_argument('-fno-rtti')
@@ -118,12 +111,12 @@ gi = dependency('gobject-introspection-1.0', version: '>= 1.61.2',
 spidermonkey = dependency('mozjs-78')
 
 # We might need to look for the headers and lib's for Cairo
-# manually on MSVC builds...
-cairo = dependency('cairo', required: get_option('cairo').enabled() and cxx.get_id() != 'msvc')
-cairo_gobject = dependency('cairo-gobject', required: cairo.found() and cxx.get_id() != 'msvc')
+# manually on MSVC/clang-cl builds...
+cairo = dependency('cairo', required: get_option('cairo').enabled() and cxx.get_argument_syntax() != 'msvc')
+cairo_gobject = dependency('cairo-gobject', required: cairo.found() and cxx.get_argument_syntax() != 'msvc')
 cairo_xlib = dependency('cairo-xlib', required: false)
 
-if cxx.get_id() == 'msvc'
+if cxx.get_argument_syntax() == 'msvc'
     if not cairo.found()
         cairo = cc.find_library('cairo', has_headers: ['cairo.h'], required: get_option('cairo').enabled())
     endif
@@ -592,7 +585,7 @@ tests_environment.set('GSETTINGS_BACKEND', 'memory')
 tests_environment.set('G_DEBUG', 'fatal-warnings,fatal-criticals')
 
 tests_locale = 'N/A'
-if cxx.get_id() != 'msvc'
+if cxx.get_argument_syntax() != 'msvc'
     result = run_command('build/choose-tests-locale.sh')
     if result.returncode() == 0
         tests_locale = result.stdout().strip()
diff --git a/meson_options.txt b/meson_options.txt
index 66f66024..edf61ca3 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -16,7 +16,7 @@ option('dtrace', type: 'boolean', value: false,
 option('systemtap', type: 'boolean', value: false,
     description: 'Include systemtap trace support (requires -Ddtrace=true)')
 option('bsymbolic_functions', type: 'boolean', value: true,
-    description: 'Link with -Bsymbolic-functions linker flag used to avoid intra-library PLT jumps, if 
supported; not used for MSVC builds')
+    description: 'Link with -Bsymbolic-functions linker flag used to avoid intra-library PLT jumps, if 
supported; not used for clang-cl builds')
 option('spidermonkey_rtti', type: 'boolean', value: false,
     description: 'Needs to match SpiderMonkey\'s config option')
 option('skip_dbus_tests', type: 'boolean', value: false,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]