Bug 1375798 - Figure out host library/object prefix/suffixes and use them for libclang. r?mshal draft
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 23 Jun 2017 15:12:04 +0900
changeset 601160 9c161609d08fa1f0c40a1fd48ace8335d4c2ed2e
parent 601159 77c5c855f66753f258345c9a0909b8b1ac9e2197
child 635180 69ef3033c8ec22f884b6a871af2b23bcbbaa91e2
push id65973
push userbmo:mh+mozilla@glandium.org
push dateWed, 28 Jun 2017 05:39:17 +0000
reviewersmshal
bugs1375798
milestone56.0a1
Bug 1375798 - Figure out host library/object prefix/suffixes and use them for libclang. r?mshal The libclang test wants to find a libclang library for use for rust bindgen. But that's a host process, that needs a host libclang. However, we currently only have the target library/object prefix/suffixes. This works fine... except when cross-compiling. So we need to figure out the proper ones for the host, and use those instead. For that, we templatize library_name_info in order to get a separate set of library/object prefix/suffixes for the host and the target. And we use the host set for the libclang check. Ideally, the build system would also use the host set for host tools builds, but we'll leave that to a followup.
moz.configure
toolkit/moz.configure
--- a/moz.configure
+++ b/moz.configure
@@ -138,69 +138,83 @@ include('build/moz.configure/toolchain.c
         when='--enable-compile-environment')
 include('build/moz.configure/memory.configure',
         when='--enable-compile-environment')
 include('build/moz.configure/headers.configure',
         when='--enable-compile-environment')
 include('build/moz.configure/warnings.configure',
         when='--enable-compile-environment')
 
-@depends(target)
-def is_openbsd(target):
-    return target.kernel == 'OpenBSD'
+
+@depends(target, host)
+def is_openbsd(target, host):
+    return target.kernel == 'OpenBSD' or host.kernel == 'OpenBSD'
 
 option(env='SO_VERSION', nargs=1, default='1.0', when=is_openbsd,
        help='Shared library version for OpenBSD systems')
 
 @depends('SO_VERSION', when=is_openbsd)
 def so_version(value):
     return value
 
-@depends(target, c_compiler, so_version)
-def library_name_info(target, c_compiler, so_version):
-    if target.kernel == 'WINNT':
-        # There aren't artifacts for mingw builds, so it's OK that the results
-        # are inaccurate in that case.
-        if c_compiler and c_compiler.type not in ('msvc', 'clang-cl'):
+@template
+def library_name_info_template(host_or_target):
+    assert host_or_target in (host, target)
+    compiler = {
+        host: host_c_compiler,
+        target: c_compiler,
+    }[host_or_target]
+
+    @depends(host_or_target, compiler, so_version)
+    def library_name_info_impl(host_or_target, compiler, so_version):
+        if host_or_target.kernel == 'WINNT':
+            # There aren't artifacts for mingw builds, so it's OK that the
+            # results are inaccurate in that case.
+            if compiler and compiler.type not in ('msvc', 'clang-cl'):
+                return namespace(
+                    dll=namespace(prefix='', suffix='.dll'),
+                    lib=namespace(prefix='lib', suffix='a'),
+                    import_lib=namespace(prefix='lib', suffix='a'),
+                    rust_lib=namespace(prefix='', suffix='lib'),
+                    obj=namespace(prefix='', suffix='o'),
+                )
+
             return namespace(
                 dll=namespace(prefix='', suffix='.dll'),
+                lib=namespace(prefix='', suffix='lib'),
+                import_lib=namespace(prefix='', suffix='lib'),
+                rust_lib=namespace(prefix='', suffix='lib'),
+                obj=namespace(prefix='', suffix='obj'),
+            )
+
+        elif host_or_target.kernel == 'Darwin':
+            return namespace(
+                dll=namespace(prefix='lib', suffix='.dylib'),
                 lib=namespace(prefix='lib', suffix='a'),
-                import_lib=namespace(prefix='lib', suffix='a'),
-                rust_lib=namespace(prefix='', suffix='lib'),
+                import_lib=namespace(prefix=None, suffix=''),
+                rust_lib=namespace(prefix='lib', suffix='a'),
                 obj=namespace(prefix='', suffix='o'),
             )
+        elif so_version:
+            so = '.so.%s' % so_version
+        else:
+            so = '.so'
 
         return namespace(
-            dll=namespace(prefix='', suffix='.dll'),
-            lib=namespace(prefix='', suffix='lib'),
-            import_lib=namespace(prefix='', suffix='lib'),
-            rust_lib=namespace(prefix='', suffix='lib'),
-            obj=namespace(prefix='', suffix='obj'),
-        )
-
-    elif target.kernel == 'Darwin':
-        return namespace(
-            dll=namespace(prefix='lib', suffix='.dylib'),
+            dll=namespace(prefix='lib', suffix=so),
             lib=namespace(prefix='lib', suffix='a'),
             import_lib=namespace(prefix=None, suffix=''),
             rust_lib=namespace(prefix='lib', suffix='a'),
             obj=namespace(prefix='', suffix='o'),
         )
-    elif so_version:
-        so = '.so.%s' % so_version
-    else:
-        so = '.so'
+
+    return library_name_info_impl
 
-    return namespace(
-        dll=namespace(prefix='lib', suffix=so),
-        lib=namespace(prefix='lib', suffix='a'),
-        import_lib=namespace(prefix=None, suffix=''),
-        rust_lib=namespace(prefix='lib', suffix='a'),
-        obj=namespace(prefix='', suffix='o'),
-    )
+host_library_name_info = library_name_info_template(host)
+library_name_info = library_name_info_template(target)
 
 set_config('DLL_PREFIX', library_name_info.dll.prefix)
 set_config('DLL_SUFFIX', library_name_info.dll.suffix)
 set_config('LIB_PREFIX', library_name_info.lib.prefix)
 set_config('LIB_SUFFIX', library_name_info.lib.suffix)
 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)
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -691,17 +691,17 @@ with only_when(building_stylo_bindgen):
             To compile Stylo, 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',
-             library_name_info, host)
+             host_library_name_info, host)
     @imports('os.path')
     @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.