Bug 1747145 - Add more configure checks for the wasm toolchain setup. r?build
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 17 Jan 2023 01:41:35 +0000 (10:41 +0900)
committerMike Hommey <glandium@debian.org>
Tue, 17 Jan 2023 20:33:36 +0000 (20:33 +0000)
Differential Revision: https://phabricator.services.mozilla.com/D166977

Gbp-Pq: Topic fixes
Gbp-Pq: Name Bug-1747145-Add-more-configure-checks-for-the-wasm-t.patch

build/moz.configure/compilers-util.configure
toolkit/moz.configure

index 1d8930347f58ef365c031d1be925ac10388ac724..2c9fe0217e2560e3b0dca5f643d824b0c765d00c 100644 (file)
@@ -96,16 +96,22 @@ def compiler_class(compiler, host_or_target):
                 def checking_fn(fn):
                     return fn
 
+            # We accept onerror being a @depends function that returns a callable.
+            # So, create a similar @depends function when it's not already one.
+            if not isinstance(onerror, SandboxDependsFunction):
+                onerror = dependable(lambda: onerror)
+
             @depends(
                 self,
                 dependable(flags),
                 extra_toolchain_flags,
                 stlport_cppflags,
                 dependable(header),
+                onerror,
                 when=when,
             )
             @checking_fn
-            def func(compiler, flags, extra_flags, stlport_flags, header):
+            def func(compiler, flags, extra_flags, stlport_flags, header, onerror):
                 flags = list(flags or [])
                 if is_target:
                     flags += extra_flags or []
index 0dd52bd5203b71c1e2fcac5fa2e1b791c770e043..4c356e61b2f9341897ac71dd6694d2363e22d604 100644 (file)
@@ -2437,24 +2437,57 @@ with only_when(requires_wasm_sandboxing & compile_environment):
 
         return wasi_sysroot
 
+    @depends(wasi_sysroot)
+    def wasi_sysroot_flags(wasi_sysroot):
+        log.info("Using wasi sysroot in %s", wasi_sysroot)
+        return ["--sysroot=%s" % wasi_sysroot]
+
     set_config("WASI_SYSROOT", wasi_sysroot)
 
-    def wasm_compiler_with_flags(compiler, sysroot):
-        if not sysroot:
-            return
-        elif compiler:
+    def wasm_compiler_with_flags(compiler, sysroot_flags):
+        if compiler:
             return (
-                compiler.wrapper
-                + [compiler.compiler]
-                + compiler.flags
-                + ["--sysroot=%s" % sysroot]
+                compiler.wrapper + [compiler.compiler] + compiler.flags + sysroot_flags
             )
 
+    @template
+    def wasm_compiler_error(msg):
+        @depends("--with-wasm-sandboxed-libraries")
+        def wasm_compiler_error(sandboxed_libs):
+            suggest_disable = ""
+            if sandboxed_libs.origin == "default":
+                suggest_disable = " Or build with --without-wasm-sandboxed-libraries."
+            return lambda: die(msg + suggest_disable)
+
+        return wasm_compiler_error
+
+    @template
+    def check_wasm_compiler(compiler, language):
+        compiler.try_compile(
+            includes=["cstring" if language == "C++" else "string.h"],
+            flags=wasi_sysroot_flags,
+            check_msg="the wasm %s compiler can find wasi headers" % language,
+            onerror=wasm_compiler_error(
+                "Cannot find wasi headers or problem with the wasm compiler. "
+                "Please fix the problem."
+            ),
+        )
+
+        compiler.try_run(
+            flags=wasi_sysroot_flags,
+            check_msg="the wasm %s linker can find wasi libraries" % language,
+            onerror=wasm_compiler_error(
+                "Cannot find wasi libraries or problem with the wasm linker. "
+                "Please fix the problem."
+            ),
+        )
+
     wasm_cc = compiler("C", wasm, other_compiler=c_compiler)
+    check_wasm_compiler(wasm_cc, "C")
 
-    @depends(wasm_cc, wasi_sysroot)
-    def wasm_cc_with_flags(wasm_cc, wasi_sysroot):
-        return wasm_compiler_with_flags(wasm_cc, wasi_sysroot)
+    @depends(wasm_cc, wasi_sysroot_flags)
+    def wasm_cc_with_flags(wasm_cc, wasi_sysroot_flags):
+        return wasm_compiler_with_flags(wasm_cc, wasi_sysroot_flags)
 
     set_config("WASM_CC", wasm_cc_with_flags)
 
@@ -2465,10 +2498,11 @@ with only_when(requires_wasm_sandboxing & compile_environment):
         other_compiler=cxx_compiler,
         other_c_compiler=c_compiler,
     )
+    check_wasm_compiler(wasm_cxx, "C++")
 
-    @depends(wasm_cxx, wasi_sysroot)
-    def wasm_cxx_with_flags(wasm_cxx, wasi_sysroot):
-        return wasm_compiler_with_flags(wasm_cxx, wasi_sysroot)
+    @depends(wasm_cxx, wasi_sysroot_flags)
+    def wasm_cxx_with_flags(wasm_cxx, wasi_sysroot_flags):
+        return wasm_compiler_with_flags(wasm_cxx, wasi_sysroot_flags)
 
     set_config("WASM_CXX", wasm_cxx_with_flags)