Commit 2f5f381c authored by Jasper Chapman-Black's avatar Jasper Chapman-Black Committed by Commit Bot

SuperSize: Add WebAssembly toolchain patch file

Usage:
1. Install emscripten locally (so that em++ works)
2. Apply the patch file
3. run build_html_viewer.py

Bug: 1011921
Change-Id: I7216f57bdf76da163bff358f6c52953cd36d76da
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1873284
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709484}
parent 4318397d
...@@ -2,7 +2,12 @@ ...@@ -2,7 +2,12 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
assert(is_linux) # Enable wasm target that depends on foo.patch being applied.
if (!defined(is_wasm)) {
is_wasm = current_os == "wasm"
}
assert(is_linux || is_wasm)
source_set("caspian-lib") { source_set("caspian-lib") {
sources = [ sources = [
...@@ -28,3 +33,32 @@ executable("cli") { ...@@ -28,3 +33,32 @@ executable("cli") {
":caspian-lib", ":caspian-lib",
] ]
} }
if (is_wasm) {
executable("caspian_web") {
sources = [
"caspian_web.cc",
]
deps = [
":caspian-lib",
]
if (!is_debug) {
# Use optimize_speed (-O3) to output the _smallest_ code.
configs -= [ "//build/config/compiler:default_optimization" ]
configs += [ "//build/config/compiler:optimize_speed" ]
}
ldflags = [
"-s",
"TOTAL_MEMORY=536870912",
"-s",
"ALLOW_MEMORY_GROWTH=1",
"-s",
"EXPORTED_FUNCTIONS=['_LoadSizeFile','_Open','_malloc','_free']",
"-s",
"EXTRA_EXPORTED_RUNTIME_METHODS=['ccall','cwrap','UTF8ToString']",
]
if (!is_debug) {
ldflags += [ "-O3" ]
}
}
}
# Caspian
## What is it?
Caspian is the name for the WebAssembly portion of the SuperSize Tiger Viewer.
## How do I build it?
1. Apply the patch file at `tools/binary_size/libsupersize/caspian/wasmbuild.patch`
2. From `src/`, run
`gn gen out/caspian &&
third_party/depot_tools/autoninja -C out/caspian tools/binary_size:caspian_web -v &&
cp out/caspian/wasm/caspian_web.* tools/binary_size/libsupersize/static/`
* If doing a release build, you should change your gn args: set is\_debug=false
3. You can then launch a local instance using `tools/binary_size/supersize start_server out.size`
diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn
index f89e7e831b79..ebfb4ba88b35 100644
--- a/build/config/BUILDCONFIG.gn
+++ b/build/config/BUILDCONFIG.gn
@@ -291,9 +291,10 @@ is_ios = current_os == "ios"
is_linux = current_os == "chromeos" || 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_posix = !is_win && !is_fuchsia
+is_posix = !is_win && !is_fuchsia && !is_wasm
# =============================================================================
# SOURCES FILTERS
diff --git a/build/config/compiler/BUILD.gn b/build/config/compiler/BUILD.gn
index 1822d8350117..dca8c088b3b6 100644
--- a/build/config/compiler/BUILD.gn
+++ b/build/config/compiler/BUILD.gn
@@ -2290,6 +2290,9 @@ config("symbols") {
cflags += [ "-fno-standalone-debug" ]
}
}
+ } else if (is_wasm) {
+ cflags = [ "-g4" ]
+ ldflags = [ "-g4" ]
} else {
cflags = []
if (is_mac && enable_dsyms) {
diff --git a/build/toolchain/toolchain.gni b/build/toolchain/toolchain.gni
index 3edc9762907d..ab483e44a11c 100644
--- a/build/toolchain/toolchain.gni
+++ b/build/toolchain/toolchain.gni
@@ -58,6 +58,9 @@ if (is_mac || is_ios) {
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 000000000000..15bc7a4ea258
--- /dev/null
+++ b/build/toolchain/wasm/BUILD.gn
@@ -0,0 +1,31 @@
+# Copyright 2019 The Chromium Authors. All rights reserved.
+# 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_goma = false
+ use_debug_fission = false
+ clang_use_chrome_plugins = false
+ use_allocator_shim = false
+ is_component_build = false
+ }
+ extra_ldflags = "-s BINARYEN_METHOD='native-wasm'"
+ executable_extension = ".js"
+ link_outputs = [
+ "{{output_dir}}/{{target_output_name}}.wasm",
+ "{{output_dir}}/{{target_output_name}}.wasm.map",
+ ]
+}
diff --git a/tools/binary_size/BUILD.gn b/tools/binary_size/BUILD.gn
index a9629c27bc42..aa07d6376ac7 100644
--- a/tools/binary_size/BUILD.gn
+++ b/tools/binary_size/BUILD.gn
@@ -30,3 +30,9 @@ if (is_linux) {
]
}
}
+
+group("caspian_web") {
+ deps = [
+ "//tools/binary_size/libsupersize/caspian:caspian_web(//build/toolchain/wasm:wasm)",
+ ]
+}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment