Bug 1594552 - Add moz.configure bits to specify a compiler for converting C/C++ to wasm r=firefox-build-system-reviewers,chmanchester
authorRicky Stewart <rstewart@mozilla.com>
Thu, 14 Nov 2019 16:26:24 +0000
changeset 501983 6c7a26bb6f04fe1677fd8ceb0ca914d042beea41
parent 501982 29ad799700cde08c67fae646439e1bbdb6a1ede2
child 501984 8cc93a06da6629d94e26e573e56508e1143fa7ac
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfirefox-build-system-reviewers, chmanchester
bugs1594552
milestone72.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 1594552 - Add moz.configure bits to specify a compiler for converting C/C++ to wasm r=firefox-build-system-reviewers,chmanchester Differential Revision: https://phabricator.services.mozilla.com/D52111
build/moz.configure/toolchain.configure
toolkit/moz.configure
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -857,22 +857,22 @@ def default_cxx_compilers(c_compiler, ot
             return (os.path.join(dir, file.replace('clang', 'clang++')),)
 
         return (c_compiler.compiler,)
 
     return default_cxx_compilers
 
 
 @template
-def provided_program(env_var):
+def provided_program(env_var, when=None):
     '''Template handling cases where a program can be specified either as a
     path or as a path with applicable arguments.
     '''
 
-    @depends_if(env_var)
+    @depends_if(env_var, when=when)
     @imports(_from='itertools', _import='takewhile')
     @imports(_from='mozbuild.shellutil', _import='split', _as='shell_split')
     def provided(cmd):
         # Assume the first dash-prefixed item (and any subsequent items) are
         # command-line options, the item before the dash-prefixed item is
         # the program we're looking for, and anything before that is a wrapper
         # of some kind (e.g. sccache).
         cmd = shell_split(cmd[0])
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -1774,16 +1774,73 @@ def requires_wasm_sandboxing(libraries):
     if libraries:
         return True
 
 set_config('MOZ_USING_WASM_SANDBOXING', requires_wasm_sandboxing)
 
 lucetc = check_prog('LUCETC', ['lucetc'],
                     paths=toolchain_search_path, when=requires_wasm_sandboxing)
 
+option('--with-wasi-sysroot',
+       nargs=1,
+       help='Path to wasi sysroot for wasm sandboxing',
+       when=requires_wasm_sandboxing)
+
+@depends('--with-wasi-sysroot', when=requires_wasm_sandboxing)
+@imports('os')
+def wasi_sysroot(wasi_sysroot):
+    if not wasi_sysroot:
+        return
+
+    wasi_sysroot = wasi_sysroot[0]
+    if not os.path.isdir(wasi_sysroot):
+        die('Argument to --with-wasi-sysroot must be a directory')
+    if not os.path.isabs(wasi_sysroot):
+        die('Argument to --with-wasi-sysroot must be an absolute path')
+
+    return wasi_sysroot
+
+set_config('WASI_SYSROOT', wasi_sysroot)
+
+
+def wasm_compiler_with_flags(wasm_compiler, provided_wasm_compiler, sysroot):
+    if not sysroot:
+        return
+    if provided_wasm_compiler:
+        return ' '.join(
+            provided_wasm_compiler.wrapper + [provided_wasm_compiler.program]
+            + provided_wasm_compiler.flags + ['--sysroot=%s' % sysroot])
+    elif wasm_compiler:
+        return '%s --target=wasm32-wasi --sysroot=%s' % (wasm_compiler, sysroot)
+
+option(env='WASM_CC', nargs=1, help='Path to the C->WASM compiler',
+       when=requires_wasm_sandboxing)
+provided_wasm_cc = provided_program('WASM_CC', when=requires_wasm_sandboxing)
+wasm_cc = check_prog('_WASM_CC', ['clang'], input=provided_wasm_cc.program,
+                     paths=toolchain_search_path, allow_missing=True,
+                     what='the C->WASM compiler', when=requires_wasm_sandboxing)
+@depends(wasm_cc, provided_wasm_cc, wasi_sysroot, when=requires_wasm_sandboxing)
+def wasm_cc_with_flags(wasm_cc, provided_wasm_cc, wasi_sysroot):
+    return wasm_compiler_with_flags(wasm_cc, provided_wasm_cc, wasi_sysroot)
+set_config('WASM_CC', wasm_cc_with_flags, when=requires_wasm_sandboxing)
+
+option(env='WASM_CXX', nargs=1, help='Path to the C++->WASM compiler',
+       when=requires_wasm_sandboxing)
+provided_wasm_cxx = provided_program('WASM_CXX', when=requires_wasm_sandboxing)
+wasm_cxx = check_prog(
+    '_WASM_CXX', ['clang++'], input=provided_wasm_cxx.program,
+    paths=toolchain_search_path, allow_missing=True,
+    what='the C++->WASM compiler', when=requires_wasm_sandboxing)
+@depends(wasm_cxx, provided_wasm_cxx, wasi_sysroot,
+         when=requires_wasm_sandboxing)
+def wasm_cxx_with_flags(wasm_cxx, provided_wasm_cxx, wasi_sysroot):
+    return wasm_compiler_with_flags(wasm_cxx, provided_wasm_cxx, wasi_sysroot)
+set_config('WASM_CXX', wasm_cxx_with_flags, when=requires_wasm_sandboxing)
+
+
 @depends('--with-wasm-sandboxed-libraries', target)
 def wasm_sandboxing(libraries, target):
     if not libraries:
         return
 
     # Wasm sandboxing is only enabled on specific targets.
     if not (target.cpu in ('x86_64',) and \
             target.kernel == 'Linux' and \
@@ -1795,37 +1852,16 @@ def wasm_sandboxing(libraries, target):
 @template
 def wasm_sandboxing_config_defines():
     for lib in wasm_sandboxing_libraries():
         set_config('MOZ_WASM_SANDBOXING_%s' % lib.upper(), getattr(wasm_sandboxing, lib))
         set_define('MOZ_WASM_SANDBOXING_%s' % lib.upper(), getattr(wasm_sandboxing, lib))
 
 wasm_sandboxing_config_defines()
 
-option('--with-wasi-sysroot',
-       nargs=1,
-       help='Path to wasi sysroot for wasm sandboxing',
-       when=requires_wasm_sandboxing)
-
-@depends('--with-wasi-sysroot', when=requires_wasm_sandboxing)
-@imports('os')
-def wasi_sysroot(wasi_sysroot):
-    if not wasi_sysroot:
-        die('--with-wasi-sysroot must be specified when using wasm sandboxing')
-
-    wasi_sysroot = wasi_sysroot[0]
-    if not os.path.isdir(wasi_sysroot):
-        die('Argument to --with-wasi-sysroot must be a directory')
-    if not os.path.isabs(wasi_sysroot):
-        die('Argument to --with-wasi-sysroot must be an absolute path')
-
-    return wasi_sysroot
-
-set_config('WASI_SYSROOT', wasi_sysroot)
-
 
 # new XULStore implementation
 # ==============================================================
 
 @depends(milestone)
 def new_xulstore(milestone):
     if milestone.is_nightly:
         return True