Bug 1537641 - Make MIDL use clang-cl as a preprocessor. r=dmajor
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 26 Mar 2019 16:29:17 +0000
changeset 466239 12b301ea0f924424f0a5057f1ebccc7cd8098e8e
parent 466238 912818869defa9374097c1d6aaa077a83d60df1d
child 466240 a84b8318c39b3224e5a9066cd9a674c1d2ab3b5e
push id1
push userpvanderbeken@mozilla.com
push dateThu, 28 Mar 2019 13:34:35 +0000
Bug 1537641 - Make MIDL use clang-cl as a preprocessor. r=dmajor Using clang-cl as a preprocessor fails with: ``` In file included from z:\build\build\src\accessible\ipc\win\handler\HandlerData.idl:8: z:\build\build\src\accessible\ipc\win\handler/AccessibleHandler.h(27,8): error: pasting formed 'Accessible2_3.', an invalid preprocessing token [-Winvalid-token-paste] import NEWEST_IA2_IDL; ^ z:\build\build\src\accessible\ipc\win\handler/AccessibleHandler.h(15,24): note: expanded from macro 'NEWEST_IA2_IDL' ^ z:\build\build\src\accessible\ipc\win\handler/AccessibleHandler.h(14,22): note: expanded from macro 'IDLFOR' ^ z:\build\build\src\accessible\ipc\win\handler/AccessibleHandler.h(13,36): note: expanded from macro '__GENIDL' ^ 1 error generated. midl : command line error MIDL1003 : error returned by the C preprocessor (1) ``` There's only one place using the NEWEST_IA2_IDL and accompanying macros, we can just avoid the issue altogether by expanding it manually (and it's not like the macro buys much, the other arm of the __midl ifdef has a #include "Accessible2_3.h" that doesn't use the macro either, presumably for the same reason). Differential Revision: https://phabricator.services.mozilla.com/D24868
--- a/accessible/ipc/win/handler/AccessibleHandler.h
+++ b/accessible/ipc/win/handler/AccessibleHandler.h
@@ -4,32 +4,27 @@
  * 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/. */
 #ifndef mozilla_a11y_AccessibleHandler_h
 #define mozilla_a11y_AccessibleHandler_h
 #define NEWEST_IA2_BASENAME Accessible2_3
-#define __QUOTE(idl) #idl
-#define __GENIDL(base) __QUOTE(base##.idl)
-#define IDLFOR(base) __GENIDL(base)
 #define __GENIFACE(base) I##base
 #define INTERFACEFOR(base) __GENIFACE(base)
 #define __GENIID(iface) IID_##iface
 #define IIDFOR(iface) __GENIID(iface)
 #if defined(__midl) || defined(__WIDL__)
-import NEWEST_IA2_IDL;
+import "Accessible2_3.idl";
 #  include "HandlerData.h"
 #  include <windows.h>
 #  if !defined(MOZILLA_INTERNAL_API)
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -1158,18 +1158,22 @@ midl = check_prog('MIDL', midl_names, wh
 def midl_flags(c_compiler, target, toolchain_search_path):
     if c_compiler and c_compiler.type == 'clang-cl':
         env = {
             'x86': 'win32',
             'x86_64': 'x64',
             'aarch64': 'arm64',
         flags = ['-env', env]
-        # Ideally, we'd use ['-cpp_cmd', c_compiler.compiler], but clang-cl
-        # currently doesn't work as a preprocessor for midl, so we need to
+        if c_compiler.version >= '8':
+            return flags + ['-cpp_cmd', c_compiler.compiler]
+        # clang-cl didn't work as a preprocessor for midl before version 8
+        # so we need to find cl if we use an older version.
         # find cl. https://bugs.llvm.org/show_bug.cgi?id=40140
         cl = find_program('cl', paths=toolchain_search_path)
         if not cl:
             die('Could not find Microsoft Visual C/C++ compiler for MIDL')
         flags += ['-cpp_cmd', cl]
         return flags
     # mingw