Bug 1701603 part 1 - Support WASI as a new target for compilation. r=glandium

Add new OS - WASI and new processor - wasm32 to the SM's build system.

Differential Revision: https://phabricator.services.mozilla.com/D110067
This commit is contained in:
Chris Fallin 2021-04-08 08:02:15 +00:00
Родитель 38a85cb95b
Коммит e888f83b57
6 изменённых файлов: 47 добавлений и 19 удалений

Просмотреть файл

@ -672,7 +672,7 @@ option(
@imports(_from="mozbuild.configure.constants", _import="Kernel")
@imports(_from="mozbuild.configure.constants", _import="OS")
@imports(_from="__builtin__", _import="ValueError")
def split_triplet(triplet, allow_msvc=False):
def split_triplet(triplet, allow_msvc=False, allow_wasi=False):
# The standard triplet is defined as
# CPU_TYPE-VENDOR-OPERATING_SYSTEM
# There is also a quartet form:
@ -728,6 +728,8 @@ def split_triplet(triplet, allow_msvc=False):
canonical_os = canonical_kernel = "OpenBSD"
elif os.startswith("solaris"):
canonical_os = canonical_kernel = "SunOS"
elif os.startswith("wasi") and allow_wasi:
canonical_os = canonical_kernel = "WASI"
else:
raise ValueError("Unknown OS: %s" % os)
@ -781,6 +783,9 @@ def split_triplet(triplet, allow_msvc=False):
elif cpu == "sh4":
canonical_cpu = "sh4"
endianness = "little"
elif cpu == "wasm32" and allow_wasi:
canonical_cpu = "wasm32"
endianness = "little"
else:
raise ValueError("Unknown CPU type: %s" % cpu)
@ -921,7 +926,7 @@ def real_target(value, host, shell, project, application):
pass
try:
return split_triplet(config_sub(shell, target))
return split_triplet(config_sub(shell, target), allow_wasi=(project == "js"))
except ValueError as e:
die(e)
@ -1070,6 +1075,12 @@ def target_is_linux(target):
set_define("XP_LINUX", target_is_linux)
@depends(target)
def target_is_linux_or_wasi(target):
if target.kernel in ("Linux", "WASI"):
return True
@depends(target)
def target_is_android(target):
if target.os == "Android":

Просмотреть файл

@ -239,7 +239,7 @@ def rust_supported_targets(rustc):
data = {}
for t in out:
try:
info = split_triplet(t)
info = split_triplet(t, allow_wasi=True)
except ValueError:
if t.startswith("thumb"):
cpu, rest = t.split("-", 1)
@ -251,7 +251,7 @@ def rust_supported_targets(rustc):
else:
continue
try:
info = split_triplet(retry)
info = split_triplet(retry, allow_wasi=True)
except ValueError:
continue
key = (info.cpu, info.endianness, info.os)

Просмотреть файл

@ -928,11 +928,11 @@ option(
"--with-sysroot",
env="SYSROOT",
nargs=1,
when=target_is_linux,
when=target_is_linux_or_wasi,
help="Build using the given sysroot directory",
)
sysroot_input = depends("--with-sysroot", when=target_is_linux)(lambda x: x)
sysroot_input = depends("--with-sysroot", when=target_is_linux_or_wasi)(lambda x: x)
bootstrap_sysroot = depends(target_is_linux, sysroot_input)(
lambda linux, input: linux and not input and input.origin == "default"
)
@ -1795,6 +1795,10 @@ def security_hardening_cflags(
js_flags = []
js_ldflags = []
# WASI compiler doesn't support security hardening cflags
if target.os == "WASI":
return
# ----------------------------------------------------------
# If hardening is explicitly enabled, or not explicitly disabled
if hardening_flag.origin == "default" or hardening_flag:
@ -2345,26 +2349,23 @@ def select_linker(
set_config("LINKER_KIND", select_linker.KIND)
@depends_if(select_linker, macos_sdk, sysroot_path, multiarch_dir)
def linker_ldflags(linker, macos_sdk, sysroot_path, multiarch_dir):
@depends_if(select_linker, target, macos_sdk, sysroot_path, multiarch_dir)
@imports("os")
def linker_ldflags(linker, target, macos_sdk, sysroot_path, multiarch_dir):
flags = list((linker and linker.LINKER_FLAG) or [])
if macos_sdk:
if target.kernel == "Darwin":
if linker and linker.KIND == "ld64":
flags.append("-Wl,-syslibroot,%s" % macos_sdk)
else:
flags.append("-Wl,--sysroot=%s" % macos_sdk)
if sysroot_path and multiarch_dir:
# Non-Debian-patched binutils linkers (both BFD and gold) don't lookup
# in multi-arch directories.
flags.append(
"-Wl,-rpath-link,%s" % os.path.join(sysroot_path, "lib", multiarch_dir)
)
flags.append(
"-Wl,-rpath-link,%s"
% os.path.join(sysroot_path, "usr", "lib", multiarch_dir)
)
for d in ("lib", "usr/lib"):
multiarch_lib_dir = os.path.join(sysroot_path, d, multiarch_dir)
if os.path.exists(multiarch_lib_dir):
# Non-Debian-patched binutils linkers (both BFD and gold) don't lookup
# in multi-arch directories.
flags.append("-Wl,-rpath-link,%s" % multiarch_lib_dir)
return flags

Просмотреть файл

@ -708,6 +708,10 @@ case "$target" in
MOZ_FIX_LINK_PATHS="-L${DIST}/bin"
;;
*-wasi*)
MOZ_FIX_LINK_PATHS=
;;
esac
CFLAGS="$CFLAGS $DSO_PIC_CFLAGS"

Просмотреть файл

@ -49,3 +49,10 @@ OBJDIR_FILES.js.src.shell += ["!/dist/bin/js-gdb.py"]
# People expect the js shell to wind up in the top-level JS dir.
OBJDIR_FILES.js.src += ["!/dist/bin/js%s" % CONFIG["BIN_SUFFIX"]]
# Stack size on Wasm/WASI
# ==================================
# Increase the default stack size (64KB) to 1MB.
# Also make the stack grow towards 0 so that if SpiderMonkey's stack limiter is buggy, overflow will likely trap.
if CONFIG["OS_ARCH"] == "WASI":
LDFLAGS += ["-Wl,-z,stack-size=1048576", "-Wl,--stack-first"]

Просмотреть файл

@ -25,6 +25,7 @@ OS = EnumString.subclass(
"OSX",
"SunOS",
"WINNT",
"WASI",
)
Kernel = EnumString.subclass(
@ -37,6 +38,7 @@ Kernel = EnumString.subclass(
"OpenBSD",
"SunOS",
"WINNT",
"WASI",
)
CPU_bitness = {
@ -58,6 +60,7 @@ CPU_bitness = {
"sparc64": 64,
"x86": 32,
"x86_64": 64,
"wasm32": 32,
}
CPU = EnumString.subclass(*CPU_bitness.keys())
@ -93,6 +96,7 @@ CPU_preprocessor_checks = OrderedDict(
("mips32", "__mips__"),
("riscv64", "__riscv && __riscv_xlen == 64"),
("sh4", "__sh__"),
("wasm32", "__wasm32__"),
)
)
@ -108,6 +112,7 @@ kernel_preprocessor_checks = {
"OpenBSD": "__OpenBSD__",
"SunOS": "__sun__",
"WINNT": "_WIN32 || __CYGWIN__",
"WASI": "__wasi__",
}
assert sorted(kernel_preprocessor_checks.keys()) == sorted(Kernel.POSSIBLE_VALUES)