diff options
author | Chun-wei Fan <fanchunwei@src.gnome.org> | 2020-08-20 18:07:54 +0800 |
---|---|---|
committer | Chun-wei Fan <fanchunwei@src.gnome.org> | 2020-08-24 23:32:46 +0800 |
commit | b0ffd96e08e2cf6ab81d878696d07746ff2834ef (patch) | |
tree | 726374bc49a1bb72e6ff33a8add6934d3bae9299 /giscanner/msvccompiler.py | |
parent | bf349e6f79ed24bedcf64cf262bbc87ff855064b (diff) | |
download | gobject-introspection-b0ffd96e08e2cf6ab81d878696d07746ff2834ef.tar.gz |
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 [args]', 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.
Diffstat (limited to 'giscanner/msvccompiler.py')
-rw-r--r-- | giscanner/msvccompiler.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/giscanner/msvccompiler.py b/giscanner/msvccompiler.py index d13eb808..0a543982 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,16 @@ class MSVCCompiler(distutils.msvccompiler.MSVCCompiler): self.__version = distutils.msvc9compiler.VERSION self.initialized = False self.preprocess_options = None + if self.check_is_clang_cl(): + cc_cmd = os.environ.get('CC').split() + self.cc = cc_cmd[0] + self.linker = 'lld-link' + self.compile_options = [] + # Add any arguments added to clang-cl to self.compile_options + # such as cross-compilation flags + if len(cc_cmd) > 1: + self.compile_options.extend(cc_cmd[1:]) + self.initialized = True def preprocess(self, source, @@ -98,3 +109,14 @@ class MSVCCompiler(distutils.msvccompiler.MSVCCompiler): return filename[filename.rfind('\\') + 1:] else: return filename[filename.rfind('\\') + 1:filename.rfind('.')] + + def check_is_clang_cl(self): + # To run g-ir-scanner under Windows using clang-cl, set both `CC` and + # `CXX` to `clang-cl [<arch_args>]` and ensure that clang-cl.exe and + # lld-link.exe are in the PATH in a Visual Studio command prompt. Note + # that the Windows SDK is still needed in this case. This is in line + # with what is done in Meson + return (os.environ.get('CC') is not None and + os.environ.get('CXX') is not None and + os.environ.get('CC').split()[0] == 'clang-cl' and + os.environ.get('CXX').split()[0] == 'clang-cl') |