[gobject-introspection/clang-cl] giscanner: Add support for using clang-cl




commit 6aabf10ac1811689791423d8525e04f8020f9700
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Thu Aug 20 18:07:54 2020 +0800

    giscanner: Add support for using clang-cl
    
    This adds quick support for using 'clang-cl' (CLang's emulation of the Visual
    Studio compiler) to run giscanner.
    
    This will still initialize things mostly in the MSVC fashion, except that it
    will also check whether both 'CC' and 'CXX' envvars are set to 'clang-cl', as
    per the way that Meson supports using 'clang-cl'.
    
    Since we are using distutils to set up the compiler instance, when we enable
    'clang-cl' support, we trick distutils that we have already initialized the
    MSVCCompiler parameters as needed.  We just leave out the compiler flags as
    we don't really care about debug symbols nor optimization with the built
    dumper binary, as it is gone as soon as the .gir file is generated.
    
    This will build G-I successfully with all the tests passed.

 giscanner/ccompiler.py    | 17 ++++++++++++-----
 giscanner/msvccompiler.py |  6 ++++++
 2 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/giscanner/ccompiler.py b/giscanner/ccompiler.py
index a81d4b867..4d6ada324 100644
--- a/giscanner/ccompiler.py
+++ b/giscanner/ccompiler.py
@@ -163,9 +163,11 @@ class CCompiler(object):
                 elif os.environ.get('VCInstallDir'):
                     os.environ['MSSdk'] = os.environ.get('VCInstallDir')
 
-            self.compiler_cmd = 'cl.exe'
-
-            self._cflags_no_deprecation_warnings = "-wd4996"
+            if self.check_is_clang_cl():
+                self.compiler_cmd = 'clang-cl.exe'
+            else:
+                self.compiler_cmd = 'cl.exe'
+                self._cflags_no_deprecation_warnings = "-wd4996"
         else:
             if (isinstance(self.compiler, Mingw32CCompiler)):
                 self.compiler_cmd = self.compiler.compiler[0]
@@ -263,7 +265,7 @@ class CCompiler(object):
         # Define these macros when using Visual C++ to silence many warnings,
         # and prevent stepping on many Visual Studio-specific items, so that
         # we don't have to handle them specifically in scannerlexer.l
-        if self.check_is_msvc():
+        if self.check_is_msvc() and not self.check_is_clang_cl():
             macros.append(('_USE_DECLSPECS_FOR_SAL', None))
             macros.append(('_CRT_SECURE_NO_WARNINGS', None))
             macros.append(('_CRT_NONSTDC_NO_WARNINGS', None))
@@ -318,7 +320,7 @@ class CCompiler(object):
         args = []
         libsearch = []
 
-        # When we are using Visual C++...
+        # When we are using Visual C++ or clang-cl...
         if self.check_is_msvc():
             # The search path of the .lib's on Visual C++
             # is dependent on the LIB environmental variable,
@@ -425,6 +427,11 @@ class CCompiler(object):
     def check_is_msvc(self):
         return isinstance(self.compiler, MSVCCompiler)
 
+    def check_is_clang_cl(self):
+        return (isinstance(self.compiler, MSVCCompiler) and
+                os.environ.get('CC') == 'clang-cl' and
+                os.environ.get('CXX') == 'clang-cl')
+
     # Private APIs
     def _set_cpp_options(self, options):
         includes = []
diff --git a/giscanner/msvccompiler.py b/giscanner/msvccompiler.py
index d13eb8084..11202a874 100644
--- a/giscanner/msvccompiler.py
+++ b/giscanner/msvccompiler.py
@@ -36,6 +36,7 @@ def get_msvc_compiler():
 class MSVCCompiler(distutils.msvccompiler.MSVCCompiler):
 
     def __init__(self, verbose=0, dry_run=0, force=0):
+        super(distutils.msvccompiler.MSVCCompiler, self).__init__()
         CCompiler.__init__(self, verbose, dry_run, force)
         self.__paths = []
         self.__arch = None  # deprecated name
@@ -44,6 +45,11 @@ class MSVCCompiler(distutils.msvccompiler.MSVCCompiler):
                 self.__version = distutils.msvc9compiler.VERSION
         self.initialized = False
         self.preprocess_options = None
+        if os.environ.get('CC') == 'clang-cl' and os.environ.get('CXX') == 'clang-cl':
+            self.cc = 'clang-cl'
+            self.linker = 'lld-link'
+            self.compile_options = []
+            self.initialized = True
 
     def preprocess(self,
                    source,


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