Bug 1524467 - Fix and refactor basic_bindgen_cflags. r=froydnj
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 05 Feb 2019 00:27:33 +0000
changeset 457719 ead57b4507aca2a98f58db477109c914030d458e
parent 457718 649fc91aa4d3fa1e4b598369fc87b6b83e836635
child 457720 54eafeca2123c137c52cbfe54df3dbdd85617c5b
push id77725
push usermh@glandium.org
push dateFri, 08 Feb 2019 02:58:39 +0000
treeherderautoland@ead57b4507ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1524467
milestone67.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 1524467 - Fix and refactor basic_bindgen_cflags. r=froydnj basic_bindgen_cflags's function is to set some flags for use with rust-bindgen through clang/libclang for C++ code. Part of the flags it sets are for the C++ standard, and the target. Unfortunately, some of the logic wrt target-specific flags is currently broken. It wants to apply per-compiler flags on Windows, but fails to do so. First, because the condition test is wrong, and second, because it only cares about msvc and not clang-cl. OTOH, we already have those flags when the compiler is clang or clang-cl. And we already have code to get the right flags for a given compiler. So when the compiler is not clang or clang-cl, we can use that to get the right flags for the clang we're going to use for bindgen. Depends on D18316 Differential Revision: https://phabricator.services.mozilla.com/D18317
build/moz.configure/bindgen.configure
--- a/build/moz.configure/bindgen.configure
+++ b/build/moz.configure/bindgen.configure
@@ -238,121 +238,68 @@ def bindgen_config_paths(llvm_config, li
         libclang_path=libclang_path,
         clang_path=clang_resolved,
     )
 
 set_config('MOZ_LIBCLANG_PATH', bindgen_config_paths.libclang_path)
 set_config('MOZ_CLANG_PATH', bindgen_config_paths.clang_path)
 
 
-@depends(host, target, target_is_unix, c_compiler, bindgen_cflags_android)
-def basic_bindgen_cflags(host, target, is_unix, compiler_info, android_cflags):
+@depends(target, target_is_unix, cxx_compiler, bindgen_cflags_android,
+         bindgen_config_paths.clang_path)
+def basic_bindgen_cflags(target, is_unix, compiler_info, android_cflags, clang_path):
     args = [
-        '-x', 'c++', '-std=gnu++14', '-fno-sized-deallocation',
+        '-x', 'c++', '-fno-sized-deallocation',
         '-DTRACING=1', '-DIMPL_LIBXUL', '-DMOZILLA_INTERNAL_API',
         '-DRUST_BINDGEN'
     ]
 
     if is_unix:
         args += ['-DOS_POSIX=1']
 
     if target.os == 'Android':
         args += android_cflags
 
-    def handle_cpu(obj):
-        if 'cpu' in obj and target.cpu in obj['cpu']:
-            return obj['cpu'][target.cpu]
-        return []
-
-    if target.os == 'WINNT' and host.raw_os.startswith('gnu'):
-        args += handle_cpu({
-            'cpu': {
-                'x86': ['--target=i686-pc-mingw32'],
-                'x86_64': ['--target=x86_64-w64-mingw32'],
-            },
-        })
+    args += {
+        'Android': ['-DOS_ANDROID=1'],
+        'DragonFly': ['-DOS_BSD=1', '-DOS_DRAGONFLY=1'],
+        'FreeBSD': ['-DOS_BSD=1', '-DOS_FREEBSD=1'],
+        'GNU': ['-DOS_LINUX=1'],
+        'NetBSD': ['-DOS_BSD=1', '-DOS_NETBSD=1'],
+        'OpenBSD': ['-DOS_BSD=1', '-DOS_OPENBSD=1'],
+        'OSX': ['-DOS_MACOSX=1', '-stdlib=libc++'],
+        'SunOS': ['-DOS_SOLARIS=1'],
+        'WINNT': [
+            '-DOS_WIN=1',
+            '-DWIN32=1',
+        ],
+    }.get(target.os, [])
 
-    os_dict = {
-        'Android': {
-            'default': ['-DOS_ANDROID=1'],
-            'cpu': {
-                'aarch64': ['--target=aarch64-linux-android'],
-                'arm': ['--target=armv7-linux-androideabi'],
-                'x86': ['--target=i686-linux-android'],
-                'x86_64': ['--target=x86_64-linux-android'],
-            },
-        },
-        'DragonFly': {
-            'default': ['-DOS_BSD=1', '-DOS_DRAGONFLY=1'],
-        },
-        'FreeBSD': {
-            'default': ['-DOS_BSD=1', '-DOS_FREEBSD=1'],
-        },
-        'GNU': {
-            'default': ['-DOS_LINUX=1'],
-            'cpu': {
-                'x86': ['-m32'],
-                'x86_64': ['-m64'],
-            },
-        },
-        'NetBSD': {
-            'default': ['-DOS_BSD=1', '-DOS_NETBSD=1'],
-        },
-        'OpenBSD': {
-            'default': ['-DOS_BSD=1', '-DOS_OPENBSD=1'],
-        },
-        'OSX': {
-            'default': [
-                '-DOS_MACOSX=1',
-                '-stdlib=libc++',
-                # To disable the fixup bindgen applies which adds search
-                # paths from clang command line in order to avoid potential
-                # conflict with -stdlib=libc++.
-                '--target=x86_64-apple-darwin',
-            ],
-        },
-        'SunOS': {
-            'default': ['-DOS_SOLARIS=1'],
-        },
-        'WINNT': {
-            'default': [
-                '-DOS_WIN=1',
-                '-DWIN32=1',
-            ],
-            'compiler': {
-                'msvc': {
-                    'default': [
-                        # To enable the builtin __builtin_offsetof so that CRT wouldn't
-                        # use reinterpret_cast in offsetof() which is not allowed inside
-                        # static_assert().
-                        '-D_CRT_USE_BUILTIN_OFFSETOF',
-                        # Enable hidden attribute (which is not supported by MSVC and
-                        # thus not enabled by default with a MSVC-compatibile build)
-                        # to exclude hidden symbols from the generated file.
-                        '-DHAVE_VISIBILITY_HIDDEN_ATTRIBUTE=1',
-                    ],
-                    'cpu': {
-                        'x86': ['--target=i686-pc-win32'],
-                        'x86_64': ['--target=x86_64-pc-win32'],
-                        'aarch64': ['--target=aarch64-pc-windows-msvc'],
-                    },
-                },
-            },
-        },
-    }.get(target.os, {})
+    if compiler_info.type in ('msvc', 'clang-cl'):
+        args += [
+            # To enable the builtin __builtin_offsetof so that CRT wouldn't
+            # use reinterpret_cast in offsetof() which is not allowed inside
+            # static_assert().
+            '-D_CRT_USE_BUILTIN_OFFSETOF',
+            # Enable hidden attribute (which is not supported by MSVC and
+            # thus not enabled by default with a MSVC-compatibile build)
+            # to exclude hidden symbols from the generated file.
+            '-DHAVE_VISIBILITY_HIDDEN_ATTRIBUTE=1',
+        ]
 
-    if 'default' in os_dict:
-        args += os_dict['default']
+    # We want to pass the same base flags as we'd pass clang.
+    # check_compiler from toolchain.configure gives us that, but we don't need
+    # to use that when the compiler used for the build is already clang-based,
+    # in which case we can use the same flags.
+    if compiler_info.type in ('clang-cl', 'clang'):
+        info = compiler_info
+    else:
+        info = check_compiler([clang_path], 'C++', target)
 
-    args += handle_cpu(os_dict)
-    if 'compiler' in os_dict and compiler_info and compiler_info in os_dict['compiler']:
-        compiler_dict = os_dict['compiler'].get(compiler_info)
-        if 'default' in compiler_dict:
-            args += compiler_dict['default']
-        args += handle_cpu(compiler_dict)
+    args += info.flags
 
     return args
 
 
 js_option(env='BINDGEN_CFLAGS',
           nargs=1,
           help='Options bindgen should pass to the C/C++ parser')