Bug 1302028 - part 2 - add configury for stylo build-time bindgen needs; r=gps,chmanchester
authornfroyd@mozilla.com <nfroyd@mozilla.com>
Fri, 20 Jan 2017 16:33:04 +0000
changeset 377652 210b8d21be0634b4f5b01b9413b2207311e763bb
parent 377651 eee5f618279a9af4e188dfb228b309f119ae5dcb
child 377653 84cf4267a0069682cd70df5091221f820617bcda
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps, chmanchester
bugs1302028
milestone53.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 1302028 - part 2 - add configury for stylo build-time bindgen needs; r=gps,chmanchester
toolkit/moz.configure
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -564,23 +564,108 @@ simple_keyfile('Adjust SDK')
 
 # Servo integration
 # ==============================================================
 option('--enable-stylo', env='STYLO_ENABLED', nargs=0,
        help='Enables experimental integration with the servo style system. '
             'This requires either building servo within Gecko\'s cargo phase '
             'or passing --with-servo')
 
-@depends('--enable-stylo')
-def stylo(value):
-    if value:
-        return True
+# We support setting up the appropriate options for Stylo's build-time
+# bindings generation 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.
+llvm_config = check_prog('LLVM_CONFIG', ('llvm-config',),
+                         what='llvm-config', allow_missing=True)
+
+option('--disable-stylo-build-bindgen',
+       help='Enable build-time bindgen for Stylo')
+
+option('--with-libclang-path', nargs=1,
+       help='Absolute path to Clang/LLVM libraries for Stylo (at least version 3.9.0')
+option('--with-clang-path', nargs=1,
+       help='Absolute path to a Clang binary for Stylo bindgen (at least version 3.9.0)')
+
+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 too old.
+
+        To compile Stylo, please install at least version {} 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')
+@imports(_from='textwrap', _import='dedent')
+def bindgen_config_paths(llvm_config, libclang_path, clang_path):
+    if not libclang_path and not clang_path:
+        # We must have LLVM_CONFIG in this case.
+        if not llvm_config:
+            return None
 
-set_config('MOZ_STYLO', stylo)
-set_define('MOZ_STYLO', stylo)
+        check_minimum_llvm_config_version(llvm_config)
+        return namespace(
+            libclang_path=invoke_llvm_config(llvm_config, '--libdir'),
+            clang_path=os.path.join(invoke_llvm_config(llvm_config, '--bindir'),
+                                    'clang'),
+        )
+
+    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.'''))
+
+    return namespace(
+        libclang_path=libclang_path[0],
+        clang_path=clang_path[0],
+    )
+
+@depends('--enable-stylo', bindgen_config_paths, '--enable-stylo-build-bindgen')
+@imports(_from='textwrap', _import='dedent')
+def stylo(stylo_enabled, bindgen_config_paths, bindgen_enabled):
+    if not stylo_enabled:
+        return None
+    elif not bindgen_enabled:
+        return namespace(
+            enabled=bool(stylo_enabled)
+        )
+    elif not bindgen_config_paths:
+        die(dedent('''\
+        Could not find LLVM/Clang installation for compiling stylo build-time
+        bindgen.  Please put 'llvm-config' in your PATH, specify the
+        'LLVM_CONFIG' environment variable, or pass the '--with-libclang-path'
+        and '--with-clang-path' options to configure.'''))
+
+    return namespace(
+        enabled=bool(stylo_enabled),
+        libclang_path=bindgen_config_paths.libclang_path,
+        clang_path=bindgen_config_paths.clang_path,
+        bindgen_enabled=bool(bindgen_enabled),
+    )
+
+set_config('MOZ_STYLO', delayed_getattr(stylo, 'enabled'))
+set_define('MOZ_STYLO', delayed_getattr(stylo, 'enabled'))
+
+set_config('MOZ_LIBCLANG_PATH', delayed_getattr(stylo, 'libclang_path'))
+set_config('MOZ_CLANG_PATH', delayed_getattr(stylo, 'clang_path'))
+set_config('MOZ_STYLO_BINDGEN', delayed_getattr(stylo, 'bindgen_enabled'))
 
 @depends(stylo, dmd)
 def jemalloc(stylo, dmd):
     if stylo:
         return 'moz'
     elif dmd:
         return True