Commit 08c0c800 authored by Ricky Stewart's avatar Ricky Stewart
Browse files

Bug 1594552 - Add moz.configure bits to specify a compiler for converting...

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

--HG--
extra : moz-landing-system : lando
parent 698c7f92
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -862,12 +862,12 @@ def default_cxx_compilers(c_compiler, other_c_compiler=None, other_cxx_compiler=


@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):
+57 −21
Original line number Diff line number Diff line
@@ -1779,6 +1779,63 @@ 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:
@@ -1800,27 +1857,6 @@ def wasm_sandboxing_config_defines():

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
# ==============================================================