diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn
index cc7e92ddb67cd..f9212d2e81c63 100644
--- a/build/config/BUILDCONFIG.gn
+++ b/build/config/BUILDCONFIG.gn
@@ -305,10 +305,11 @@ is_ios = current_os == "ios"
is_linux = current_os == "linux"
is_mac = current_os == "mac"
is_nacl = current_os == "nacl"
+is_wasm = current_os == "wasm"
is_win = current_os == "win" || current_os == "winuwp"
is_apple = is_ios || is_mac
-is_posix = !is_win && !is_fuchsia
+is_posix = !is_win && !is_fuchsia && !is_wasm
# =============================================================================
# TARGET DEFAULTS
diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn
index 6119aa066a982..a77ca7e4a2ab8 100644
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -647,6 +647,20 @@ config("compiler") {
ldflags += [ "-fexperimental-relative-c++-abi-vtables" ]
}
+ if (is_wasm) {
+ ldflags += [
+ "-s",
+ "ALLOW_MEMORY_GROWTH=1",
+ "-s",
+ "LLD_REPORT_UNDEFINED=1",
+ ]
+
+ if (is_official_build) {
+ cflags += ["-flto=full"]
+ ldflags += ["-flto=full"]
+ }
+ }
+
# Add flags for link-time optimization. These flags enable
# optimizations/transformations that require whole-program visibility at link
# time, so they need to be applied to all translation units, and we may end up
@@ -766,7 +780,7 @@ config("compiler") {
# TODO(crbug.com/40242425): Cleanup undefined symbol errors caught by
# --no-undefined-version.
- if (use_lld && !is_win && !is_mac && !is_ios) {
+ if (use_lld && !is_win && !is_mac && !is_ios && !is_wasm) {
ldflags += [ "-Wl,--undefined-version" ]
}
@@ -777,7 +791,7 @@ config("compiler") {
if (use_lld && !enable_call_graph_profile_sort) {
if (is_win) {
ldflags += [ "/call-graph-profile-sort:no" ]
- } else {
+ } else if (!is_wasm) {
ldflags += [ "-Wl,--no-call-graph-profile-sort" ]
}
}
@@ -1615,7 +1629,7 @@ config("default_warnings") {
"-Wno-ignored-pragma-optimize",
]
- if (!is_nacl) {
+ if (!is_nacl && !is_wasm) {
cflags += [
# TODO(crbug.com/40231599) Evaluate and possibly enable.
"-Wno-deprecated-builtins",
@@ -2380,6 +2394,9 @@ config("symbols") {
# All configs using /DEBUG should include this:
configs = [ ":win_pdbaltpath" ]
+ } else if (is_wasm) {
+ cflags = [ "-gseparate-dwarf" ]
+ ldflags = [ "-gseparate-dwarf" ]
} else {
cflags = []
if (is_mac && enable_dsyms) {
diff --git a/build/toolchain/toolchain.gni b/build/toolchain/toolchain.gni
index 844bc8e540bcc..93e6e0c437fab 100644
--- a/build/toolchain/toolchain.gni
+++ b/build/toolchain/toolchain.gni
@@ -47,6 +47,9 @@ if (is_apple) {
shlib_extension = ".so"
} else if (is_win) {
shlib_extension = ".dll"
+} else if (is_wasm) {
+ # WebAssembly does not stably support shared libraries. (as of Oct 2019)
+ shlib_extension = ".wasm"
} else {
assert(false, "Platform not supported")
}
diff --git a/build/toolchain/wasm/BUILD.gn b/build/toolchain/wasm/BUILD.gn
new file mode 100644
index 0000000000000..4aed5264eae15
--- /dev/null
+++ b/build/toolchain/wasm/BUILD.gn
@@ -0,0 +1,30 @@
+# Copyright 2019 The Chromium Authors
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import("//build/toolchain/gcc_toolchain.gni")
+
+gcc_toolchain("wasm") {
+ cc = "emcc"
+ cxx = "em++"
+ nm = "emcc"
+ ar = "emar"
+ ld = cxx
+
+ toolchain_args = {
+ current_cpu = "wasm"
+ current_os = "wasm"
+
+ is_clang = true
+ use_remoteexec = false
+ use_debug_fission = false
+ clang_use_chrome_plugins = false
+ use_allocator_shim = false
+ is_component_build = false
+ }
+ executable_extension = ".js"
+ link_outputs = [
+ "{{output_dir}}/{{target_output_name}}.wasm",
+ "{{output_dir}}/{{target_output_name}}.wasm.debug.wasm",
+ ]
+}