Bug 1476427 - part 1 - move bindgen configure bits to a separate file; r=chmanchester
authorNathan Froyd <froydnj@mozilla.com>
Thu, 26 Jul 2018 17:37:56 -0400
changeset 486409 ede08380391724d4c6cf2c2af2b355b712ef5b74
parent 486408 e8fd3709089bb5acd5bbef144901140c0595dc0e
child 486410 f89b91c892b931c3bf02b3ad5f6521fb06cfef34
push id1815
push userffxbld-merge
push dateMon, 15 Oct 2018 10:40:45 +0000
treeherdermozilla-release@18d4c09e9378 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1476427
milestone63.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 1476427 - part 1 - move bindgen configure bits to a separate file; r=chmanchester This change makes the config variables determined for bindgen (MOZ_CLANG_PATH et al) available to JS.
build/moz.configure/bindgen.configure
moz.configure
toolkit/moz.configure
new file mode 100644
--- /dev/null
+++ b/build/moz.configure/bindgen.configure
@@ -0,0 +1,199 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+# We support setting up the appropriate options for bindgen via setting
+# LLVM_CONFIG or by providing explicit configure options.  The Windows
+# installer of LLVM/Clang doesn't provide llvm-config, so we need both
+# methods to support all of our tier-1 platforms.
+@depends(host)
+@imports('which')
+@imports('os')
+@imports('subprocess')
+def llvm_config_paths(host):
+    llvm_supported_versions = ['6.0', '5.0', '4.0', '3.9']
+    llvm_config_progs = []
+    for version in llvm_supported_versions:
+        llvm_config_progs += [
+            'llvm-config-%s' % version,
+            'llvm-config-mp-%s' % version,    # MacPorts' chosen naming scheme.
+            'llvm-config%s' % version.replace('.', ''),
+        ]
+    llvm_config_progs.append('llvm-config')
+
+    # Homebrew on macOS doesn't make clang available on PATH, so we have to
+    # look for it in non-standard places.
+    if host.kernel == 'Darwin':
+        try:
+            brew = which.which('brew')
+            brew_config = subprocess.check_output([brew, 'config']).strip()
+
+            for line in brew_config.splitlines():
+                if line.startswith('HOMEBREW_PREFIX'):
+                    fields = line.split(None, 2)
+                    prefix = fields[1] if len(fields) == 2 else ''
+                    path = ['opt', 'llvm', 'bin', 'llvm-config']
+                    llvm_config_progs.append(os.path.join(prefix, *path))
+                    break
+        except which.WhichError:
+            # Homebrew not installed, which is fine.
+            pass
+
+    # Also add in the location to which `mach bootstrap` or
+    # `mach artifact toolchain` installs clang.
+    mozbuild_state_dir = os.environ.get('MOZBUILD_STATE_PATH',
+                                        os.path.expanduser(os.path.join('~', '.mozbuild')))
+    bootstrap_llvm_config = os.path.join(mozbuild_state_dir, 'clang', 'bin', 'llvm-config')
+
+    llvm_config_progs.append(bootstrap_llvm_config)
+
+    return llvm_config_progs
+
+llvm_config = check_prog('LLVM_CONFIG', llvm_config_paths,
+                         what='llvm-config', allow_missing=True)
+
+option('--with-libclang-path', nargs=1,
+       help='Absolute path to a directory containing Clang/LLVM libraries for bindgen (version 3.9.x or above)')
+option('--with-clang-path', nargs=1,
+       help='Absolute path to a Clang binary for bindgen (version 3.9.x or above)')
+
+def invoke_llvm_config(llvm_config, *options):
+    '''Invoke llvm_config with the given options and return the first line of
+    output.'''
+    lines = check_cmd_output(llvm_config, *options).splitlines()
+    return lines[0]
+
+@imports(_from='textwrap', _import='dedent')
+def check_minimum_llvm_config_version(llvm_config):
+    version = Version(invoke_llvm_config(llvm_config, '--version'))
+    min_version = Version('3.9.0')
+    if version < min_version:
+        die(dedent('''\
+        llvm installation {} is incompatible with bindgen.
+
+        Please install version {} or greater of Clang + LLVM
+        and ensure that the 'llvm-config' from that
+        installation is first on your path.
+
+        You can verify this by typing 'llvm-config --version'.
+        '''.format(version, min_version)))
+
+@depends(llvm_config, '--with-libclang-path', '--with-clang-path',
+         host_library_name_info, host)
+@imports('os.path')
+@imports('glob')
+@imports(_from='textwrap', _import='dedent')
+def bindgen_config_paths(llvm_config, libclang_path, clang_path,
+                         library_name_info, host):
+    def search_for_libclang(path):
+        # Try to ensure that the clang shared library that bindgen is going
+        # to look for is actually present.  The files that we search for
+        # mirror the logic in clang-sys/build.rs.
+        libclang_choices = []
+        if host.os == 'WINNT':
+            libclang_choices.append('libclang.dll')
+        libclang_choices.append('%sclang%s' % (library_name_info.dll.prefix,
+                                               library_name_info.dll.suffix))
+        if host.kernel == 'Linux':
+            libclang_choices.append('libclang.so.1')
+
+        if host.os == 'OpenBSD':
+            libclang_choices = glob.glob(path + '/libclang.so.*.*')
+
+        # At least one of the choices must be found.
+        for choice in libclang_choices:
+            libclang = os.path.join(path, choice)
+            if os.path.exists(libclang):
+                return (True, None)
+        else:
+            return (False, list(set(libclang_choices)))
+
+    if not libclang_path and not clang_path:
+        # We must have LLVM_CONFIG in this case.
+        if not llvm_config:
+            die(dedent('''\
+            Could not find LLVM/Clang installation for compiling bindgen.
+            Please specify the 'LLVM_CONFIG' environment variable
+            (recommended), pass the '--with-libclang-path' and '--with-clang-path'
+            options to configure, or put 'llvm-config' in your PATH.  Altering your
+            PATH may expose 'clang' as well, potentially altering your compiler,
+            which may not be what you intended.'''))
+
+        check_minimum_llvm_config_version(llvm_config)
+        libclang_arg = '--bindir' if host.os == 'WINNT' else '--libdir'
+        libclang_path = invoke_llvm_config(llvm_config, libclang_arg)
+        clang_path = os.path.join(invoke_llvm_config(llvm_config, '--bindir'),
+                                  'clang')
+        libclang_path = normsep(libclang_path)
+        clang_path = normsep(clang_path)
+
+        # Debian-based distros, at least, can have llvm-config installed
+        # but not have other packages installed.  Since the user is trying
+        # to use their system packages, we can't be more specific about what
+        # they need.
+        clang_resolved = find_program(clang_path)
+        if not clang_resolved:
+            die(dedent('''\
+            The file {} returned by `llvm-config {}` does not exist.
+            clang is required to build Firefox.  Please install the
+            necessary packages, or run `mach bootstrap`.
+            '''.format(clang_path, '--bindir')))
+
+        if not os.path.exists(libclang_path):
+            die(dedent('''\
+            The directory {} returned by `llvm-config {}` does not exist.
+            clang is required to build Firefox.  Please install the
+            necessary packages, or run `mach bootstrap`.
+            '''.format(libclang_path, libclang_arg)))
+
+        (found, searched) = search_for_libclang(libclang_path)
+        if not found:
+            die(dedent('''\
+            Could not find the clang shared library in the path {}
+            returned by `llvm-config {}` (searched for files {}).
+            clang is required to build Firefox.  Please install the
+            necessary packages, or run `mach bootstrap`.
+            '''.format(libclang_path, libclang_arg, searched)))
+
+        return namespace(
+            libclang_path=libclang_path,
+            clang_path=clang_resolved,
+        )
+
+    if (not libclang_path and clang_path) or \
+       (libclang_path and not clang_path):
+        die(dedent('''\
+        You must provide both of --with-libclang-path and --with-clang-path
+        or neither of them.'''))
+
+    libclang_path = libclang_path[0]
+    clang_path = clang_path[0]
+
+    if not os.path.exists(libclang_path) or \
+       not os.path.isdir(libclang_path):
+        die(dedent('''\
+        The argument to --with-libclang-path is not a directory: {}
+        '''.format(libclang_path)))
+
+    (found, searched) = search_for_libclang(libclang_path)
+    if not found:
+        die(dedent('''\
+        Could not find the clang shared library in the path {}
+        specified by --with-libclang-path (searched for files {}).
+        '''.format(libclang_path, searched)))
+
+    clang_resolved = find_program(clang_path)
+    if not clang_resolved:
+        die(dedent('''\
+        The argument to --with-clang-path is not a file: {}
+        '''.format(clang_path)))
+
+    return namespace(
+        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)
--- a/moz.configure
+++ b/moz.configure
@@ -234,16 +234,19 @@ set_config('LIB_SUFFIX', library_name_in
 set_config('RUST_LIB_PREFIX', library_name_info.rust_lib.prefix)
 set_config('RUST_LIB_SUFFIX', library_name_info.rust_lib.suffix)
 set_config('OBJ_SUFFIX', library_name_info.obj.suffix)
 # Lots of compilation tests depend on this variable being present.
 add_old_configure_assignment('OBJ_SUFFIX', library_name_info.obj.suffix)
 set_config('IMPORT_LIB_SUFFIX', library_name_info.import_lib.suffix)
 set_define('MOZ_DLL_SUFFIX', depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s))
 
+# Depends on host_library_name_info, so needs to go here.
+include('build/moz.configure/bindgen.configure',
+        when='--enable-compile-environment')
 include(include_project_configure)
 
 @depends('--help')
 @imports(_from='mozbuild.backend', _import='backends')
 def build_backends_choices(_):
     return tuple(backends)
 
 
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -609,211 +609,16 @@ simple_keyfile('Google API')
 id_and_secret_keyfile('Bing API')
 
 simple_keyfile('Adjust SDK')
 
 id_and_secret_keyfile('Leanplum SDK')
 
 simple_keyfile('Pocket API')
 
-# We support setting up the appropriate options for bindgen via setting
-# LLVM_CONFIG or by providing explicit configure options.  The Windows
-# installer of LLVM/Clang doesn't provide llvm-config, so we need both
-# methods to support all of our tier-1 platforms.
-@depends(host)
-@imports('which')
-@imports('os')
-@imports('subprocess')
-def llvm_config_paths(host):
-    llvm_supported_versions = ['6.0', '5.0', '4.0', '3.9']
-    llvm_config_progs = []
-    for version in llvm_supported_versions:
-        llvm_config_progs += [
-            'llvm-config-%s' % version,
-            'llvm-config-mp-%s' % version,    # MacPorts' chosen naming scheme.
-            'llvm-config%s' % version.replace('.', ''),
-        ]
-    llvm_config_progs.append('llvm-config')
-
-    # Homebrew on macOS doesn't make clang available on PATH, so we have to
-    # look for it in non-standard places.
-    if host.kernel == 'Darwin':
-        try:
-            brew = which.which('brew')
-            brew_config = subprocess.check_output([brew, 'config']).strip()
-
-            for line in brew_config.splitlines():
-                if line.startswith('HOMEBREW_PREFIX'):
-                    fields = line.split(None, 2)
-                    prefix = fields[1] if len(fields) == 2 else ''
-                    path = ['opt', 'llvm', 'bin', 'llvm-config']
-                    llvm_config_progs.append(os.path.join(prefix, *path))
-                    break
-        except which.WhichError:
-            # Homebrew not installed, which is fine.
-            pass
-
-    # Also add in the location to which `mach bootstrap` or
-    # `mach artifact toolchain` installs clang.
-    mozbuild_state_dir = os.environ.get('MOZBUILD_STATE_PATH',
-                                        os.path.expanduser(os.path.join('~', '.mozbuild')))
-    bootstrap_llvm_config = os.path.join(mozbuild_state_dir, 'clang', 'bin', 'llvm-config')
-
-    llvm_config_progs.append(bootstrap_llvm_config)
-
-    return llvm_config_progs
-
-llvm_config = check_prog('LLVM_CONFIG', llvm_config_paths,
-                         when='--enable-compile-environment',
-                         what='llvm-config', allow_missing=True)
-
-with only_when('--enable-compile-environment'):
-    option('--with-libclang-path', nargs=1,
-           help='Absolute path to a directory containing Clang/LLVM libraries for bindgen (version 3.9.x or above)')
-    option('--with-clang-path', nargs=1,
-           help='Absolute path to a Clang binary for bindgen (version 3.9.x or above)')
-
-    def invoke_llvm_config(llvm_config, *options):
-        '''Invoke llvm_config with the given options and return the first line of
-        output.'''
-        lines = check_cmd_output(llvm_config, *options).splitlines()
-        return lines[0]
-
-    @imports(_from='textwrap', _import='dedent')
-    def check_minimum_llvm_config_version(llvm_config):
-        version = Version(invoke_llvm_config(llvm_config, '--version'))
-        min_version = Version('3.9.0')
-        if version < min_version:
-            die(dedent('''\
-            llvm installation {} is incompatible with bindgen.
-
-            Please install version {} or greater of Clang + LLVM
-            and ensure that the 'llvm-config' from that
-            installation is first on your path.
-
-            You can verify this by typing 'llvm-config --version'.
-            '''.format(version, min_version)))
-
-    @depends(llvm_config, '--with-libclang-path', '--with-clang-path',
-             host_library_name_info, host)
-    @imports('os.path')
-    @imports('glob')
-    @imports(_from='textwrap', _import='dedent')
-    def bindgen_config_paths(llvm_config, libclang_path, clang_path,
-                             library_name_info, host):
-        def search_for_libclang(path):
-            # Try to ensure that the clang shared library that bindgen is going
-            # to look for is actually present.  The files that we search for
-            # mirror the logic in clang-sys/build.rs.
-            libclang_choices = []
-            if host.os == 'WINNT':
-                libclang_choices.append('libclang.dll')
-            libclang_choices.append('%sclang%s' % (library_name_info.dll.prefix,
-                                                   library_name_info.dll.suffix))
-            if host.kernel == 'Linux':
-                libclang_choices.append('libclang.so.1')
-
-            if host.os == 'OpenBSD':
-                libclang_choices = glob.glob(path + '/libclang.so.*.*')
-
-            # At least one of the choices must be found.
-            for choice in libclang_choices:
-                libclang = os.path.join(path, choice)
-                if os.path.exists(libclang):
-                    return (True, None)
-            else:
-                return (False, list(set(libclang_choices)))
-
-        if not libclang_path and not clang_path:
-            # We must have LLVM_CONFIG in this case.
-            if not llvm_config:
-                die(dedent('''\
-                Could not find LLVM/Clang installation for compiling bindgen.
-                Please specify the 'LLVM_CONFIG' environment variable
-                (recommended), pass the '--with-libclang-path' and '--with-clang-path'
-                options to configure, or put 'llvm-config' in your PATH.  Altering your
-                PATH may expose 'clang' as well, potentially altering your compiler,
-                which may not be what you intended.'''))
-
-            check_minimum_llvm_config_version(llvm_config)
-            libclang_arg = '--bindir' if host.os == 'WINNT' else '--libdir'
-            libclang_path = invoke_llvm_config(llvm_config, libclang_arg)
-            clang_path = os.path.join(invoke_llvm_config(llvm_config, '--bindir'),
-                                      'clang')
-            libclang_path = normsep(libclang_path)
-            clang_path = normsep(clang_path)
-
-            # Debian-based distros, at least, can have llvm-config installed
-            # but not have other packages installed.  Since the user is trying
-            # to use their system packages, we can't be more specific about what
-            # they need.
-            clang_resolved = find_program(clang_path)
-            if not clang_resolved:
-                die(dedent('''\
-                The file {} returned by `llvm-config {}` does not exist.
-                clang is required to build Firefox.  Please install the
-                necessary packages, or run `mach bootstrap`.
-                '''.format(clang_path, '--bindir')))
-
-            if not os.path.exists(libclang_path):
-                die(dedent('''\
-                The directory {} returned by `llvm-config {}` does not exist.
-                clang is required to build Firefox.  Please install the
-                necessary packages, or run `mach bootstrap`.
-                '''.format(libclang_path, libclang_arg)))
-
-            (found, searched) = search_for_libclang(libclang_path)
-            if not found:
-                die(dedent('''\
-                Could not find the clang shared library in the path {}
-                returned by `llvm-config {}` (searched for files {}).
-                clang is required to build Firefox.  Please install the
-                necessary packages, or run `mach bootstrap`.
-                '''.format(libclang_path, libclang_arg, searched)))
-
-            return namespace(
-                libclang_path=libclang_path,
-                clang_path=clang_resolved,
-            )
-
-        if (not libclang_path and clang_path) or \
-           (libclang_path and not clang_path):
-            die(dedent('''\
-            You must provide both of --with-libclang-path and --with-clang-path
-            or neither of them.'''))
-
-        libclang_path = libclang_path[0]
-        clang_path = clang_path[0]
-
-        if not os.path.exists(libclang_path) or \
-           not os.path.isdir(libclang_path):
-            die(dedent('''\
-            The argument to --with-libclang-path is not a directory: {}
-            '''.format(libclang_path)))
-
-        (found, searched) = search_for_libclang(libclang_path)
-        if not found:
-            die(dedent('''\
-            Could not find the clang shared library in the path {}
-            specified by --with-libclang-path (searched for files {}).
-            '''.format(libclang_path, searched)))
-
-        clang_resolved = find_program(clang_path)
-        if not clang_resolved:
-            die(dedent('''\
-            The argument to --with-clang-path is not a file: {}
-            '''.format(clang_path)))
-
-        return namespace(
-            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)
 
 # WebRender integration
 option('--enable-webrender', nargs='?', choices=('build',),
        help='Include WebRender in the build and/or enable it at runtime')
 
 @depends('--enable-webrender')
 def webrender(value):
     build_webrender = None