summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathieu Duponchelle <mduponchelle1@gmail.com>2020-09-05 23:01:34 +0000
committerMathieu Duponchelle <mduponchelle1@gmail.com>2020-09-05 23:01:34 +0000
commit25dcd89afabd57f199e33cb253aa7fd7fb91ec01 (patch)
tree706b67598366d110639ff3d4796aad8fb7ee7e36
parentbc53f2d0d33846ae3108486cfbc40d6e5ff43e22 (diff)
parentef428e88dc04bfedb40f0ccd61b01da7ca139aa2 (diff)
downloadgobject-introspection-25dcd89afabd57f199e33cb253aa7fd7fb91ec01.tar.gz
Merge branch 'clang-cl' into 'master'
giscanner: Add support for using clang-cl See merge request GNOME/gobject-introspection!234
-rw-r--r--MSVC.README.rst9
-rw-r--r--giscanner/ccompiler.py14
-rw-r--r--giscanner/msvccompiler.py22
3 files changed, 39 insertions, 6 deletions
diff --git a/MSVC.README.rst b/MSVC.README.rst
index d8941de4..ec5ddb56 100644
--- a/MSVC.README.rst
+++ b/MSVC.README.rst
@@ -109,3 +109,12 @@ the following so that we ensure the manifests are embedded to the built DLLs and
for /r %f in (*.dll.manifest) do if exist $(PREFIX)\bin\%~nf mt /manifest %f /outputresource:$(PREFIX)\bin\%~nf;2
for /r %f in (*.exe.manifest) do if exist $(PREFIX)\bin\%~nf mt /manifest %f /outputresource:$(PREFIX)\bin\%~nf;1
+
+Additional notes on using clang-cl (LLVM/CLang's Visual Studio compiler emulation)
+----------------------------------------------------------------------------------
+Support has been added to build GObject-Introspection with clang-cl, specifically for
+running g-ir-scanner with clang-cl and lld-link as the compiler and linker. To enable
+such support, you need to set *both* the environment variables CC and CXX to clang-cl
+prior to building GObject-Introspection or running g-ir-scanner. This is in line with
+building with clang-cl in place of using the stock Visual Studio compiler to perform
+builds with the Meson build system.
diff --git a/giscanner/ccompiler.py b/giscanner/ccompiler.py
index a81d4b86..bd1aa78e 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.compiler.check_is_clang_cl():
+ self.compiler_cmd = os.environ.get('CC').split()[0]
+ 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.compiler.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,
@@ -336,7 +338,7 @@ class CCompiler(object):
args.append('dumpbin.exe')
args.append('-symbols')
- # When we are not using Visual C++ (i.e. we are using GCC)...
+ # When we are not using Visual C++ nor clang-cl (i.e. we are using GCC)...
else:
libtool = utils.get_libtool_command(options)
if libtool:
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')