Bug 1246334 - Add support for building the clang plugin using clang-cl; r=glandium
authorEhsan Akhgari <ehsan@mozilla.com>
Fri, 05 Feb 2016 15:23:18 -0500
changeset 285798 cb43c67f89030fb0ee8e702e48bc78bcbc4c8d51
parent 285797 94593f55cd01bd9d2f227f211eec535a61bc7670
child 285799 b73632b2d7243de58d081c6cdc94dd2aa43e6162
push id30036
push usercbook@mozilla.com
push dateMon, 29 Feb 2016 10:35:59 +0000
treeherdermozilla-central@9da51cb4974e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglandium
bugs1246334
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1246334 - Add support for building the clang plugin using clang-cl; r=glandium
build/autoconf/clang-plugin.m4
build/clang-plugin/Makefile.in
config/static-checking-config.mk
--- a/build/autoconf/clang-plugin.m4
+++ b/build/autoconf/clang-plugin.m4
@@ -4,23 +4,28 @@ dnl file, You can obtain one at http://m
 
 AC_DEFUN([MOZ_CONFIG_CLANG_PLUGIN], [
 
 MOZ_ARG_ENABLE_BOOL(clang-plugin,
 [  --enable-clang-plugin   Enable building with the mozilla clang plugin ],
    ENABLE_CLANG_PLUGIN=1,
    ENABLE_CLANG_PLUGIN= )
 if test -n "$ENABLE_CLANG_PLUGIN"; then
-    if test -z "$CLANG_CC"; then
+    if test -z "${CLANG_CC}${CLANG_CL}"; then
         AC_MSG_ERROR([Can't use clang plugin without clang.])
     fi
 
     AC_MSG_CHECKING([for llvm-config])
     if test -z "$LLVMCONFIG"; then
-      LLVMCONFIG=`$CXX -print-prog-name=llvm-config`
+      if test -n "$CLANG_CL"; then
+          CXX_COMPILER="$(dirname "$CXX")/clang"
+      else
+          CXX_COMPILER="${CXX}"
+      fi
+      LLVMCONFIG=`$CXX_COMPILER -print-prog-name=llvm-config`
     fi
 
     if test -z "$LLVMCONFIG"; then
       LLVMCONFIG=`which llvm-config`
     fi
 
     if test ! -x "$LLVMCONFIG"; then
       AC_MSG_RESULT([not found])
@@ -31,28 +36,67 @@ if test -n "$ENABLE_CLANG_PLUGIN"; then
 
     if test -z "$LLVMCONFIG"; then
         AC_MSG_ERROR([Cannot find an llvm-config binary for building a clang plugin])
     fi
     LLVM_CXXFLAGS=`$LLVMCONFIG --cxxflags`
     dnl The clang package we use on OSX is old, and its llvm-config doesn't
     dnl recognize --system-libs, so ask for that separately.  llvm-config's
     dnl failure here is benign, so we can ignore it if it happens.
-    LLVM_LDFLAGS=`$LLVMCONFIG --system-libs | xargs`
-    LLVM_LDFLAGS="$LLVM_LDFLAGS `$LLVMCONFIG --ldflags --libs core mc analysis asmparser mcparser bitreader option | xargs`"
+    dnl Use tr instead of xargs in order to avoid problems with path separators on Windows.
+    LLVM_LDFLAGS=`$LLVMCONFIG --system-libs | tr '\n' ' '`
+    LLVM_LDFLAGS="$LLVM_LDFLAGS `$LLVMCONFIG --ldflags --libs core mc analysis asmparser mcparser bitreader option | tr '\n' ' '`"
 
     if test "${HOST_OS_ARCH}" = "Darwin"; then
         CLANG_LDFLAGS="-lclangFrontend -lclangDriver -lclangSerialization"
         CLANG_LDFLAGS="$CLANG_LDFLAGS -lclangParse -lclangSema -lclangAnalysis"
         CLANG_LDFLAGS="$CLANG_LDFLAGS -lclangEdit -lclangAST -lclangLex"
         CLANG_LDFLAGS="$CLANG_LDFLAGS -lclangBasic -lclangASTMatchers"
+    elif test "${HOST_OS_ARCH}" = "WINNT"; then
+        CLANG_LDFLAGS="clangFrontend.lib clangDriver.lib clangSerialization.lib"
+        CLANG_LDFLAGS="$CLANG_LDFLAGS clangParse.lib clangSema.lib clangAnalysis.lib"
+        CLANG_LDFLAGS="$CLANG_LDFLAGS clangEdit.lib clangAST.lib clangLex.lib"
+        CLANG_LDFLAGS="$CLANG_LDFLAGS clangBasic.lib clangASTMatchers.lib"
     else
         CLANG_LDFLAGS="-lclangASTMatchers"
     fi
 
+    if test -n "$CLANG_CL"; then
+        dnl The llvm-config coming with clang-cl may give us arguments in the
+        dnl /ARG form, which in msys will be interpreted as a path name.  So we
+        dnl need to split the args and convert the leading slashes that we find
+        dnl into a dash.
+        LLVM_REPLACE_CXXFLAGS=''
+        for arg in $LLVM_CXXFLAGS; do
+            dnl The following expression replaces a leading slash with a dash.
+            dnl Also replace any backslashes with forward slash.
+            arg=`echo "$arg"|sed -e 's/^\//-/' -e 's/\\\\/\//g'`
+            LLVM_REPLACE_CXXFLAGS="$LLVM_REPLACE_CXXFLAGS $arg"
+        done
+        LLVM_CXXFLAGS="$LLVM_REPLACE_CXXFLAGS"
+
+        LLVM_REPLACE_LDFLAGS=''
+        for arg in $LLVM_LDFLAGS; do
+            dnl The following expression replaces a leading slash with a dash.
+            dnl Also replace any backslashes with forward slash.
+            arg=`echo "$arg"|sed -e 's/^\//-/' -e 's/\\\\/\//g'`
+            LLVM_REPLACE_LDFLAGS="$LLVM_REPLACE_LDFLAGS $arg"
+        done
+        LLVM_LDFLAGS="$LLVM_REPLACE_LDFLAGS"
+
+        CLANG_REPLACE_LDFLAGS=''
+        for arg in $CLANG_LDFLAGS; do
+            dnl The following expression replaces a leading slash with a dash.
+            dnl Also replace any backslashes with forward slash.
+            arg=`echo "$arg"|sed -e 's/^\//-/' -e 's/\\\\/\//g'`
+            CLANG_REPLACE_LDFLAGS="$CLANG_REPLACE_LDFLAGS $arg"
+        done
+        CLANG_LDFLAGS="$CLANG_REPLACE_LDFLAGS"
+    fi
+
     dnl Check for the new ASTMatcher API names.  Since this happened in the
     dnl middle of the 3.8 cycle, our CLANG_VERSION_FULL is impossible to use
     dnl correctly, so we have to detect this at configure time.
     AC_CACHE_CHECK(for new ASTMatcher names,
                    ac_cv_have_new_ASTMatcher_names,
         [
             AC_LANG_SAVE
             AC_LANG_CPLUSPLUS
--- a/build/clang-plugin/Makefile.in
+++ b/build/clang-plugin/Makefile.in
@@ -4,20 +4,24 @@
 
 # LLVM_CXXFLAGS comes with its own optimization flags.
 MOZ_OPTIMIZE =
 
 include $(topsrcdir)/config/config.mk
 
 # In the current moz.build world, we need to override essentially every
 # variable to limit ourselves to what we need to build the clang plugin.
+ifeq ($(HOST_OS_ARCH),WINNT)
+OS_CXXFLAGS := $(LLVM_CXXFLAGS) -GR- -EHsc
+else
 OS_CXXFLAGS := $(LLVM_CXXFLAGS) -fno-rtti -fno-exceptions
+DSO_LDOPTS := -shared
+endif
 OS_COMPILE_CXXFLAGS :=
 OS_LDFLAGS := $(LLVM_LDFLAGS) $(CLANG_LDFLAGS)
-DSO_LDOPTS := -shared
 
 ifeq ($(HOST_OS_ARCH)_$(OS_ARCH),Linux_Darwin)
 # Use the host compiler instead of the target compiler.
 CXX := $(HOST_CXX)
 # expandlibs doesn't know the distinction between host and target toolchains,
 # and on cross linux/darwin builds, the options to give to the linker for file
 # lists differ between both, so don't use file lists.
 EXPAND_MKSHLIB_ARGS :=
--- a/config/static-checking-config.mk
+++ b/config/static-checking-config.mk
@@ -1,12 +1,12 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 # The entire tree should be subject to static analysis using the XPCOM
 # script. Additional scripts may be added by specific subdirectories.
 
 ifdef ENABLE_CLANG_PLUGIN
-CLANG_PLUGIN := $(DEPTH)/build/clang-plugin/$(DLL_PREFIX)clang-plugin$(DLL_SUFFIX)
+CLANG_PLUGIN := $(topobjdir)/build/clang-plugin/$(DLL_PREFIX)clang-plugin$(DLL_SUFFIX)
 OS_CXXFLAGS += -Xclang -load -Xclang $(CLANG_PLUGIN) -Xclang -add-plugin -Xclang moz-check
 OS_CFLAGS += -Xclang -load -Xclang $(CLANG_PLUGIN) -Xclang -add-plugin -Xclang moz-check
 endif