Bug 1302028 - part 2 - add configury for stylo build-time bindgen needs; r?gps,chmanchester draft
authorNathan Froyd <froydnj@mozilla.com>
Fri, 23 Dec 2016 08:33:20 -0500
changeset 453505 1dcdadfc10f3c840f3ca746d69b6ee2cf65db5a9
parent 453504 4d0e01f1cd2d3d6bdf79d668dde3feb579831605
child 453506 75c645a2f080d084686fd0e291a323da3726cdc1
push id39696
push userbmo:nfroyd@mozilla.com
push dateFri, 23 Dec 2016 18:35:18 +0000
reviewersgps, chmanchester
bugs1302028
milestone53.0a1
Bug 1302028 - part 2 - add configury for stylo build-time bindgen needs; r?gps,chmanchester We assume that the llvm-config in the user's PATH is recent enough; it can be overridden with the environment variable LLVM_CONFIG. We also add rudimentary checking for versions, though we don't go so far as checking whether all the necessary libraries are there or whether the clang llvm-config points us to is runnable. We provide --with-libclang-path and --with-clang-path in the event that llvm-config is not available. Discussions indicated that a --disable-bindgen option might be useful, so that tags along in this commit as well. Build-time bindgen is the default, however. MozReview-Commit-ID: Ce9VoiakE4F
toolkit/moz.configure
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -559,23 +559,110 @@ 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', default=False,
+       help='Disable 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, '--disable-stylo-build-bindgen')
+@imports(_from='textwrap', _import='dedent')
+def stylo(stylo_enabled, bindgen_config_paths, disable_bindgen):
+    bindgen_enabled = not disable_bindgen
+
+    if not stylo_enabled:
+        return None
+    elif disable_bindgen:
+        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(
+        stylo_enabled=bool(stylo_enabled),
+        libclang_path=bindgen_config_paths.libclang_path,
+        clang_path=bindgen_config_paths.clang_path,
+        bindgen_enabled=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