[WASM] Add POC compile bot for WebAssembly

Fix core.gni to use not use Assembler for none cpu.

Right now, there are no outputs because we aren't compiling
dm or nanobench.  However, this still compiles the skia
library and creates two executables, so it's a good canary
for a real WASM build.

Additional note: the two executables in question don't draw
anything to the screen via GL, which is still not possible with
Skia+WASM.

Bug: skia:
Change-Id: I0d767467e94e40d01070e34223dd90e96f1c96f2
Reviewed-on: https://skia-review.googlesource.com/49540
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Reviewed-by: Mike Klein <mtklein@chromium.org>
Reviewed-by: Eric Boren <borenet@google.com>
diff --git a/BUILD.gn b/BUILD.gn
index bf57a64..ece39b0 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1190,51 +1190,53 @@
     ]
   }
 
-  test_lib("views") {
-    public_include_dirs = [ "include/views" ]
-    sources = [
-      "src/views/SkEvent.cpp",
-      "src/views/SkEventSink.cpp",
-      "src/views/SkOSMenu.cpp",
-      "src/views/SkTagList.cpp",
-      "src/views/SkTouchGesture.cpp",
-      "src/views/SkView.cpp",
-      "src/views/SkViewPriv.cpp",
-    ]
-    libs = []
-    deps = []
-    if (!is_android) {
-      sources += [ "src/views/SkWindow.cpp" ]
-    }
-    if (is_linux) {
-      public_include_dirs += [ "src/views/unix" ]
-      sources += [
-        "src/views/unix/SkOSWindow_Unix.cpp",
-        "src/views/unix/keysym2ucs.c",
+  if (target_cpu != "wasm") {
+    test_lib("views") {
+      public_include_dirs = [ "include/views" ]
+      sources = [
+        "src/views/SkEvent.cpp",
+        "src/views/SkEventSink.cpp",
+        "src/views/SkOSMenu.cpp",
+        "src/views/SkTagList.cpp",
+        "src/views/SkTouchGesture.cpp",
+        "src/views/SkView.cpp",
+        "src/views/SkViewPriv.cpp",
       ]
-      libs += [
-        "GL",
-        "X11",
-      ]
-    } else if (is_mac) {
-      sources += [
-        "src/views/mac/SkEventNotifier.mm",
-        "src/views/mac/SkNSView.mm",
-        "src/views/mac/SkOSWindow_Mac.mm",
-        "src/views/mac/SkTextFieldCell.m",
-      ]
-      libs += [
-        "QuartzCore.framework",
-        "Cocoa.framework",
-        "Foundation.framework",
-      ]
-    } else if (is_win) {
-      sources += [ "src/views/win/SkOSWindow_win.cpp" ]
-    } else if (is_ios) {
-      sources += [ "src/views/mac/SkEventNotifier.mm" ]
-    }
-    if (skia_use_angle) {
-      deps += [ "//third_party/angle2" ]
+      libs = []
+      deps = []
+      if (!is_android) {
+        sources += [ "src/views/SkWindow.cpp" ]
+      }
+      if (is_linux) {
+        public_include_dirs += [ "src/views/unix" ]
+        sources += [
+          "src/views/unix/SkOSWindow_Unix.cpp",
+          "src/views/unix/keysym2ucs.c",
+        ]
+        libs += [
+          "GL",
+          "X11",
+        ]
+      } else if (is_mac) {
+        sources += [
+          "src/views/mac/SkEventNotifier.mm",
+          "src/views/mac/SkNSView.mm",
+          "src/views/mac/SkOSWindow_Mac.mm",
+          "src/views/mac/SkTextFieldCell.m",
+        ]
+        libs += [
+          "QuartzCore.framework",
+          "Cocoa.framework",
+          "Foundation.framework",
+        ]
+      } else if (is_win) {
+        sources += [ "src/views/win/SkOSWindow_win.cpp" ]
+      } else if (is_ios) {
+        sources += [ "src/views/mac/SkEventNotifier.mm" ]
+      }
+      if (skia_use_angle) {
+        deps += [ "//third_party/angle2" ]
+      }
     }
   }
 
@@ -1292,60 +1294,61 @@
     ]
   }
 
-  import("gn/samples.gni")
-  test_lib("samples") {
-    public_include_dirs = [ "samplecode" ]
-    include_dirs = [ "experimental" ]
-    sources = samples_sources + [
-                "experimental/SkSetPoly3To3.cpp",
-                "experimental/SkSetPoly3To3_A.cpp",
-                "experimental/SkSetPoly3To3_D.cpp",
+  if (target_cpu != "wasm") {
+    import("gn/samples.gni")
+    test_lib("samples") {
+      public_include_dirs = [ "samplecode" ]
+      include_dirs = [ "experimental" ]
+      sources = samples_sources + [
+                  "experimental/SkSetPoly3To3.cpp",
+                  "experimental/SkSetPoly3To3_A.cpp",
+                  "experimental/SkSetPoly3To3_D.cpp",
 
-                # Relocating these files here, so that clients don't try to build them while they're
-                # still in active development. Clang's thread safety analysis gets tripped up by
-                # conditional locks.
-                "src/core/SkThreadedBMPDevice.cpp",
-                "src/core/SkThreadedBMPDevice.h",
-              ]
-    deps = [
-      ":experimental_svg_model",
-      ":flags",
-      ":gm",
-      ":tool_utils",
-      ":views",
-      ":xml",
-    ]
+                  # Relocating these files here, so that clients don't try to build them while they're
+                  # still in active development. Clang's thread safety analysis gets tripped up by
+                  # conditional locks.
+                  "src/core/SkThreadedBMPDevice.cpp",
+                  "src/core/SkThreadedBMPDevice.h",
+                ]
+      deps = [
+        ":experimental_svg_model",
+        ":flags",
+        ":gm",
+        ":tool_utils",
+        ":views",
+        ":xml",
+      ]
 
-    if (skia_use_lua) {
-      sources += [ "samplecode/SampleLua.cpp" ]
-      deps += [
-        ":lua",
-        "//third_party/lua",
+      if (skia_use_lua) {
+        sources += [ "samplecode/SampleLua.cpp" ]
+        deps += [
+          ":lua",
+          "//third_party/lua",
+        ]
+      }
+    }
+    test_app("dm") {
+      sources = [
+        "dm/DM.cpp",
+        "dm/DMJsonWriter.cpp",
+        "dm/DMSrcSink.cpp",
+      ]
+      include_dirs = [ "tests" ]
+      deps = [
+        ":common_flags",
+        ":experimental_svg_model",
+        ":flags",
+        ":gm",
+        ":gpu_tool_utils",
+        ":skia",
+        ":tests",
+        ":tool_utils",
+        "//third_party/jsoncpp",
+        "//third_party/libpng",
       ]
     }
   }
 
-  test_app("dm") {
-    sources = [
-      "dm/DM.cpp",
-      "dm/DMJsonWriter.cpp",
-      "dm/DMSrcSink.cpp",
-    ]
-    include_dirs = [ "tests" ]
-    deps = [
-      ":common_flags",
-      ":experimental_svg_model",
-      ":flags",
-      ":gm",
-      ":gpu_tool_utils",
-      ":skia",
-      ":tests",
-      ":tool_utils",
-      "//third_party/jsoncpp",
-      "//third_party/libpng",
-    ]
-  }
-
   test_app("ok") {
     sources = [
       "tools/ok.cpp",
@@ -1363,7 +1366,6 @@
       ":tool_utils",
     ]
   }
-
   test_app("nanobench") {
     sources = [
       "bench/nanobench.cpp",
@@ -1434,7 +1436,7 @@
   }
 
   # We can't yet build ICU on iOS or Windows.
-  if (!is_ios && !is_win) {
+  if (!is_ios && !is_win && target_cpu != "wasm") {
     test_app("sktexttopdf-hb") {
       sources = [
         "tools/shape/SkShaper_harfbuzz.cpp",
@@ -1502,7 +1504,7 @@
     ]
   }
 
-  if (!is_ios) {
+  if (!is_ios && target_cpu != "wasm") {
     test_app("skiaserve") {
       sources = [
         "tools/skiaserve/Request.cpp",
diff --git a/gn/BUILD.gn b/gn/BUILD.gn
index b91c877..5d17cad 100644
--- a/gn/BUILD.gn
+++ b/gn/BUILD.gn
@@ -438,6 +438,13 @@
     } else {
       ldflags = [ "-Wl,--gc-sections" ]
     }
+    if (target_cpu == "wasm") {
+      # The compiler asks us to add an optimization flag to both cflags
+      # and ldflags to cut down on the local variables,
+      # for performance reasons.
+      # The "linking" step is the conversion to javascript.
+      ldflags += [ "-O3" ]
+    }
   }
   defines = [ "NDEBUG" ]
 }
diff --git a/gn/BUILDCONFIG.gn b/gn/BUILDCONFIG.gn
index ca91c1b..057bea1 100644
--- a/gn/BUILDCONFIG.gn
+++ b/gn/BUILDCONFIG.gn
@@ -37,6 +37,10 @@
 
 assert(!(is_debug && is_official_build))
 
+if (target_cpu == "wasm") {
+  target_os = "wasm"
+}
+
 # Platform detection
 if (target_os == "") {
   target_os = host_os
@@ -69,7 +73,8 @@
   current_cpu = target_cpu
 }
 
-is_clang = is_android || is_ios || is_mac || (cc == "clang" && cxx == "clang++") || clang_win != ""
+is_clang = is_android || is_ios || is_mac ||
+           (cc == "clang" && cxx == "clang++") || clang_win != ""
 if (!is_clang && !is_win) {
   is_clang = exec_script("gn/is_clang.py",
                          [
diff --git a/gn/core.gni b/gn/core.gni
index eb0d0d2..79498b4 100644
--- a/gn/core.gni
+++ b/gn/core.gni
@@ -530,6 +530,7 @@
     # assembler situation is figured out, https://crbug.com/762167
     skia_core_defines += [ "SK_JUMPER_USE_ASSEMBLY=0" ]
   }
-} else {
+} else if (target_cpu == "arm" || target_cpu == "arm64" ||
+           target_cpu == "x86" || target_cpu == "x64") {
   skia_core_sources += [ "$_src/jumper/SkJumper_generated.S" ]
 }
diff --git a/infra/bots/assets/asset_utils.py b/infra/bots/assets/asset_utils.py
index df29aec..10dc547 100644
--- a/infra/bots/assets/asset_utils.py
+++ b/infra/bots/assets/asset_utils.py
@@ -123,6 +123,7 @@
         '--tag', TAG_PROJECT_SKIA,
         '--tag', TAG_VERSION_TMPL % version,
         '--compression-level', '1',
+        '-verification-timeout', '30m0s',
     ])
 
   def download(self, name, version, target_dir):
diff --git a/infra/bots/assets/emscripten_sdk/README.md b/infra/bots/assets/emscripten_sdk/README.md
new file mode 100644
index 0000000..7ec14d9
--- /dev/null
+++ b/infra/bots/assets/emscripten_sdk/README.md
@@ -0,0 +1,7 @@
+Checkout and build the emscripten_sdk following the instructions here:
+http://webassembly.org/getting-started/developers-guide/
+
+Then, run
+infra/bots/assets/emscripten_sdk/create_and_upload.py -s /path/to/dir/emsdk
+
+It will take a while because the emsdk dir is > 26GB.
\ No newline at end of file
diff --git a/infra/bots/assets/emscripten_sdk/VERSION b/infra/bots/assets/emscripten_sdk/VERSION
new file mode 100644
index 0000000..56a6051
--- /dev/null
+++ b/infra/bots/assets/emscripten_sdk/VERSION
@@ -0,0 +1 @@
+1
\ No newline at end of file
diff --git a/infra/bots/assets/emscripten_sdk/common.py b/infra/bots/assets/emscripten_sdk/common.py
new file mode 100755
index 0000000..caa0ad8
--- /dev/null
+++ b/infra/bots/assets/emscripten_sdk/common.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Common vars used by scripts in this directory."""
+
+
+import os
+import sys
+
+FILE_DIR = os.path.dirname(os.path.abspath(__file__))
+INFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir, os.pardir))
+
+sys.path.insert(0, INFRA_BOTS_DIR)
+from assets import assets
+
+ASSET_NAME = os.path.basename(FILE_DIR)
+
+
+def run(cmd):
+  """Run a command, eg. "upload" or "download". """
+  assets.main([cmd, ASSET_NAME] + sys.argv[1:])
diff --git a/infra/bots/assets/emscripten_sdk/create_and_upload.py b/infra/bots/assets/emscripten_sdk/create_and_upload.py
new file mode 100755
index 0000000..56e41a2
--- /dev/null
+++ b/infra/bots/assets/emscripten_sdk/create_and_upload.py
@@ -0,0 +1,43 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Create the asset and upload it."""
+
+
+import argparse
+import common
+import os
+import subprocess
+import sys
+import utils
+
+
+def main():
+  if 'linux' not in sys.platform:
+    print >> sys.stderr, 'This script only runs on Linux.'
+    sys.exit(1)
+  parser = argparse.ArgumentParser()
+  parser.add_argument('--gsutil')
+  parser.add_argument('--sdk_path', '-s', required=True)
+  args = parser.parse_args()
+
+  with utils.tmp_dir():
+    upload_script = os.path.join(common.FILE_DIR, 'upload.py')
+
+    try:
+      cmd = ['python', upload_script, '-t', args.sdk_path]
+      if args.gsutil:
+        cmd.extend(['--gsutil', args.gsutil])
+      subprocess.check_call(cmd)
+    except subprocess.CalledProcessError:
+      # Trap exceptions to avoid printing two stacktraces.
+      sys.exit(1)
+
+
+if __name__ == '__main__':
+  main()
diff --git a/infra/bots/assets/emscripten_sdk/download.py b/infra/bots/assets/emscripten_sdk/download.py
new file mode 100755
index 0000000..ca999e0
--- /dev/null
+++ b/infra/bots/assets/emscripten_sdk/download.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Download the current version of the asset."""
+
+
+import common
+
+
+if __name__ == '__main__':
+  common.run('download')
diff --git a/infra/bots/assets/emscripten_sdk/upload.py b/infra/bots/assets/emscripten_sdk/upload.py
new file mode 100755
index 0000000..bdfbda7
--- /dev/null
+++ b/infra/bots/assets/emscripten_sdk/upload.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+#
+# Copyright 2017 Google Inc.
+#
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+
+"""Upload a new version of the asset."""
+
+
+import common
+
+
+if __name__ == '__main__':
+  common.run('upload')
diff --git a/infra/bots/gen_tasks.go b/infra/bots/gen_tasks.go
index 077c709..8fc69e5 100644
--- a/infra/bots/gen_tasks.go
+++ b/infra/bots/gen_tasks.go
@@ -479,6 +479,9 @@
 		if strings.Contains(name, "Vulkan") {
 			pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("linux_vulkan_sdk"))
 		}
+		if strings.Contains(name, "EMCC") {
+			pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("emscripten_sdk"))
+		}
 	} else if strings.Contains(name, "Win") {
 		pkgs = append(pkgs, b.MustGetCipdPackageFromAsset("win_toolchain"))
 		if strings.Contains(name, "Clang") {
diff --git a/infra/bots/jobs.json b/infra/bots/jobs.json
index def410c..d31cfbd 100644
--- a/infra/bots/jobs.json
+++ b/infra/bots/jobs.json
@@ -33,6 +33,7 @@
   "Build-Debian9-Clang-x86_64-Release-TSAN",
   "Build-Debian9-Clang-x86_64-Release-UBSAN_float_cast_overflow",
   "Build-Debian9-Clang-x86_64-Release-Vulkan",
+  "Build-Debian9-EMCC-wasm-Release",
   "Build-Debian9-GCC-arm-Debug-Chromecast",
   "Build-Debian9-GCC-arm-Release-Chromecast",
   "Build-Debian9-GCC-x86-Debug",
diff --git a/infra/bots/recipe_modules/flavor/examples/full.expected/Build-Ubuntu-EMCC-wasm-Release.json b/infra/bots/recipe_modules/flavor/examples/full.expected/Build-Ubuntu-EMCC-wasm-Release.json
new file mode 100644
index 0000000..0d98a76
--- /dev/null
+++ b/infra/bots/recipe_modules/flavor/examples/full.expected/Build-Ubuntu-EMCC-wasm-Release.json
@@ -0,0 +1,54 @@
+[
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[CUSTOM_/_B_WORK]/skia/bin/fetch-gn"
+    ],
+    "cwd": "[CUSTOM_/_B_WORK]/skia",
+    "env": {
+      "BUILDTYPE": "Release",
+      "CHROME_HEADLESS": "1",
+      "PATH": "<PATH>:RECIPE_PACKAGE_REPO[depot_tools]",
+      "SKIA_OUT": "[CUSTOM_/_B_WORK]/skia/out/Build-Ubuntu-EMCC-wasm-Release"
+    },
+    "infra_step": true,
+    "name": "fetch-gn"
+  },
+  {
+    "cmd": [
+      "[CUSTOM_/_B_WORK]/skia/bin/gn",
+      "gen",
+      "[CUSTOM_/_B_WORK]/skia/out/Build-Ubuntu-EMCC-wasm-Release/Release",
+      "--args=cc=\"[START_DIR]/emscripten_sdk/emscripten/incoming/emcc\" cxx=\"[START_DIR]/emscripten_sdk/emscripten/incoming/em++\" extra_cflags=[\"-Wno-unknown-warning-option\"] is_debug=false skia_enable_gpu=false skia_use_dng_sdk=false skia_use_fontconfig=false skia_use_freetype=false skia_use_icu=false target_cpu=\"wasm\""
+    ],
+    "cwd": "[CUSTOM_/_B_WORK]/skia",
+    "env": {
+      "BUILDTYPE": "Release",
+      "CHROME_HEADLESS": "1",
+      "PATH": "[START_DIR]/emscripten_sdk/clang/fastcomp/build_incoming_64/bin:<PATH>:RECIPE_PACKAGE_REPO[depot_tools]",
+      "SKIA_OUT": "[CUSTOM_/_B_WORK]/skia/out/Build-Ubuntu-EMCC-wasm-Release"
+    },
+    "name": "gn gen"
+  },
+  {
+    "cmd": [
+      "ninja",
+      "-C",
+      "[CUSTOM_/_B_WORK]/skia/out/Build-Ubuntu-EMCC-wasm-Release/Release"
+    ],
+    "cwd": "[CUSTOM_/_B_WORK]/skia",
+    "env": {
+      "BUILDTYPE": "Release",
+      "CHROME_HEADLESS": "1",
+      "PATH": "[START_DIR]/emscripten_sdk/clang/fastcomp/build_incoming_64/bin:<PATH>:RECIPE_PACKAGE_REPO[depot_tools]",
+      "SKIA_OUT": "[CUSTOM_/_B_WORK]/skia/out/Build-Ubuntu-EMCC-wasm-Release"
+    },
+    "name": "ninja"
+  },
+  {
+    "name": "$result",
+    "recipe_result": null,
+    "status_code": 0
+  }
+]
\ No newline at end of file
diff --git a/infra/bots/recipe_modules/flavor/examples/full.py b/infra/bots/recipe_modules/flavor/examples/full.py
index abe7478..71b0aff 100644
--- a/infra/bots/recipe_modules/flavor/examples/full.py
+++ b/infra/bots/recipe_modules/flavor/examples/full.py
@@ -61,6 +61,7 @@
   'Build-Ubuntu-Clang-x86_64-Release-Mini',
   'Build-Ubuntu-Clang-x86_64-Release-Shared',
   'Build-Ubuntu-Clang-x86_64-Release-Vulkan',
+  'Build-Ubuntu-EMCC-wasm-Release',
   'Build-Ubuntu-GCC-x86_64-Debug-SK_USE_DISCARDABLE_SCALEDIMAGECACHE',
   'Build-Ubuntu-GCC-x86_64-Release-ANGLE',
   'Build-Ubuntu-GCC-x86_64-Release-Fast',
diff --git a/infra/bots/recipe_modules/flavor/gn_flavor.py b/infra/bots/recipe_modules/flavor/gn_flavor.py
index a6591b9..88a164a 100644
--- a/infra/bots/recipe_modules/flavor/gn_flavor.py
+++ b/infra/bots/recipe_modules/flavor/gn_flavor.py
@@ -30,7 +30,8 @@
     os            = self.m.vars.builder_cfg.get('os',            '')
     target_arch   = self.m.vars.builder_cfg.get('target_arch',   '')
 
-    clang_linux   = str(self.m.vars.slave_dir.join('clang_linux'))
+    clang_linux        = str(self.m.vars.slave_dir.join('clang_linux'))
+    emscripten_sdk     = str(self.m.vars.slave_dir.join('emscripten_sdk'))
     linux_vulkan_sdk   = str(self.m.vars.slave_dir.join('linux_vulkan_sdk'))
     win_toolchain = str(self.m.vars.slave_dir.join(
       't', 'depot_tools', 'win_toolchain', 'vs_files',
@@ -53,6 +54,10 @@
       cc, cxx = 'gcc-4.8', 'g++-4.8'
     elif compiler == 'GCC':
       cc, cxx = 'gcc', 'g++'
+    elif compiler == 'EMCC':
+      cc   = emscripten_sdk + '/emscripten/incoming/emcc'
+      cxx  = emscripten_sdk + '/emscripten/incoming/em++'
+      extra_cflags.append('-Wno-unknown-warning-option')
 
     if compiler != 'MSVC' and configuration == 'Debug':
       extra_cflags.append('-O1')
@@ -113,6 +118,14 @@
       args['skia_compile_processors'] = 'true'
     if compiler == 'Clang' and 'Win' in os:
       args['clang_win'] = '"%s"' % self.m.vars.slave_dir.join('clang_win')
+    if target_arch == 'wasm':
+      args.update({
+        'skia_use_freetype':   'false',
+        'skia_use_fontconfig': 'false',
+        'skia_use_dng_sdk':    'false',
+        'skia_use_icu':        'false',
+        'skia_enable_gpu':     'false',
+      })
 
     sanitize = ''
     if extra_config == 'UBSAN_float_cast_overflow':
@@ -149,6 +162,9 @@
         self._py(
             'fetch-clang-format',
             self.m.vars.skia_dir.join('bin', 'fetch-clang-format'))
+      if target_arch == 'wasm':
+        fastcomp = emscripten_sdk + '/clang/fastcomp/build_incoming_64/bin'
+        env['PATH'] = '%s:%%(PATH)s' % fastcomp
 
       with self.m.env(env):
         self._run('gn gen', [gn, 'gen', self.out_dir, '--args=' + gn_args])
diff --git a/infra/bots/recipes/compile.expected/Build-Ubuntu-EMCC-wasm-Release.json b/infra/bots/recipes/compile.expected/Build-Ubuntu-EMCC-wasm-Release.json
new file mode 100644
index 0000000..116a436
--- /dev/null
+++ b/infra/bots/recipes/compile.expected/Build-Ubuntu-EMCC-wasm-Release.json
@@ -0,0 +1,175 @@
+[
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "ensure-directory",
+      "--mode",
+      "0777",
+      "[CUSTOM_/_B_WORK]"
+    ],
+    "infra_step": true,
+    "name": "makedirs checkout_path"
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "RECIPE_MODULE[recipe_engine::file]/resources/fileutil.py",
+      "--json-output",
+      "/path/to/tmp/json",
+      "remove",
+      "[CUSTOM_/_B_WORK]/.gclient_entries"
+    ],
+    "infra_step": true,
+    "name": "remove [CUSTOM_/_B_WORK]/.gclient_entries"
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "RECIPE_MODULE[depot_tools::bot_update]/resources/bot_update.py",
+      "--spec",
+      "cache_dir = '[CUSTOM_/_B_CACHE]'\nsolutions = [{'deps_file': '.DEPS.git', 'managed': False, 'name': 'skia', 'url': 'https://skia.googlesource.com/skia.git'}]",
+      "--patch_root",
+      "skia",
+      "--revision_mapping_file",
+      "{\"got_revision\": \"skia\"}",
+      "--git-cache-dir",
+      "[CUSTOM_/_B_CACHE]",
+      "--cleanup-dir",
+      "[CLEANUP]/bot_update",
+      "--output_json",
+      "/path/to/tmp/json",
+      "--revision",
+      "skia@abc123"
+    ],
+    "cwd": "[CUSTOM_/_B_WORK]",
+    "env": {
+      "GIT_HTTP_LOW_SPEED_LIMIT": "1000",
+      "GIT_HTTP_LOW_SPEED_TIME": "300",
+      "PATH": "<PATH>:RECIPE_PACKAGE_REPO[depot_tools]"
+    },
+    "infra_step": true,
+    "name": "bot_update",
+    "~followup_annotations": [
+      "@@@STEP_TEXT@Some step text@@@",
+      "@@@STEP_LOG_LINE@json.output@{@@@",
+      "@@@STEP_LOG_LINE@json.output@  \"did_run\": true, @@@",
+      "@@@STEP_LOG_LINE@json.output@  \"fixed_revisions\": {@@@",
+      "@@@STEP_LOG_LINE@json.output@    \"skia\": \"abc123\"@@@",
+      "@@@STEP_LOG_LINE@json.output@  }, @@@",
+      "@@@STEP_LOG_LINE@json.output@  \"manifest\": {@@@",
+      "@@@STEP_LOG_LINE@json.output@    \"skia\": {@@@",
+      "@@@STEP_LOG_LINE@json.output@      \"repository\": \"https://fake.org/skia.git\", @@@",
+      "@@@STEP_LOG_LINE@json.output@      \"revision\": \"9046e2e693bb92a76e972b694580e5d17ad10748\"@@@",
+      "@@@STEP_LOG_LINE@json.output@    }@@@",
+      "@@@STEP_LOG_LINE@json.output@  }, @@@",
+      "@@@STEP_LOG_LINE@json.output@  \"patch_failure\": false, @@@",
+      "@@@STEP_LOG_LINE@json.output@  \"patch_root\": \"skia\", @@@",
+      "@@@STEP_LOG_LINE@json.output@  \"properties\": {@@@",
+      "@@@STEP_LOG_LINE@json.output@    \"got_revision\": \"9046e2e693bb92a76e972b694580e5d17ad10748\", @@@",
+      "@@@STEP_LOG_LINE@json.output@    \"got_revision_cp\": \"refs/heads/master@{#164710}\"@@@",
+      "@@@STEP_LOG_LINE@json.output@  }, @@@",
+      "@@@STEP_LOG_LINE@json.output@  \"root\": \"skia\", @@@",
+      "@@@STEP_LOG_LINE@json.output@  \"step_text\": \"Some step text\"@@@",
+      "@@@STEP_LOG_LINE@json.output@}@@@",
+      "@@@STEP_LOG_END@json.output@@@",
+      "@@@SET_BUILD_PROPERTY@got_revision@\"9046e2e693bb92a76e972b694580e5d17ad10748\"@@@",
+      "@@@SET_BUILD_PROPERTY@got_revision_cp@\"refs/heads/master@{#164710}\"@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "[CUSTOM_/_B_WORK]/skia/bin/fetch-gn"
+    ],
+    "cwd": "[CUSTOM_/_B_WORK]/skia",
+    "env": {
+      "BUILDTYPE": "Release",
+      "CHROME_HEADLESS": "1",
+      "PATH": "<PATH>:RECIPE_PACKAGE_REPO[depot_tools]",
+      "SKIA_OUT": "[CUSTOM_/_B_WORK]/skia/out/Build-Ubuntu-EMCC-wasm-Release"
+    },
+    "infra_step": true,
+    "name": "fetch-gn"
+  },
+  {
+    "cmd": [
+      "[CUSTOM_/_B_WORK]/skia/bin/gn",
+      "gen",
+      "[CUSTOM_/_B_WORK]/skia/out/Build-Ubuntu-EMCC-wasm-Release/Release",
+      "--args=cc=\"[START_DIR]/emscripten_sdk/emscripten/incoming/emcc\" cxx=\"[START_DIR]/emscripten_sdk/emscripten/incoming/em++\" extra_cflags=[\"-Wno-unknown-warning-option\"] is_debug=false skia_enable_gpu=false skia_use_dng_sdk=false skia_use_fontconfig=false skia_use_freetype=false skia_use_icu=false target_cpu=\"wasm\""
+    ],
+    "cwd": "[CUSTOM_/_B_WORK]/skia",
+    "env": {
+      "BUILDTYPE": "Release",
+      "CHROME_HEADLESS": "1",
+      "PATH": "[START_DIR]/emscripten_sdk/clang/fastcomp/build_incoming_64/bin:<PATH>:RECIPE_PACKAGE_REPO[depot_tools]",
+      "SKIA_OUT": "[CUSTOM_/_B_WORK]/skia/out/Build-Ubuntu-EMCC-wasm-Release"
+    },
+    "name": "gn gen"
+  },
+  {
+    "cmd": [
+      "ninja",
+      "-C",
+      "[CUSTOM_/_B_WORK]/skia/out/Build-Ubuntu-EMCC-wasm-Release/Release"
+    ],
+    "cwd": "[CUSTOM_/_B_WORK]/skia",
+    "env": {
+      "BUILDTYPE": "Release",
+      "CHROME_HEADLESS": "1",
+      "PATH": "[START_DIR]/emscripten_sdk/clang/fastcomp/build_incoming_64/bin:<PATH>:RECIPE_PACKAGE_REPO[depot_tools]",
+      "SKIA_OUT": "[CUSTOM_/_B_WORK]/skia/out/Build-Ubuntu-EMCC-wasm-Release"
+    },
+    "name": "ninja"
+  },
+  {
+    "cmd": [
+      "python",
+      "-u",
+      "import errno\nimport glob\nimport os\nimport shutil\nimport sys\n\nsrc = sys.argv[1]\ndst = sys.argv[2]\nbuild_products_whitelist = ['dm', 'dm.exe', 'dm.app', 'nanobench.app', 'get_images_from_skps', 'get_images_from_skps.exe', 'nanobench', 'nanobench.exe', 'skpbench', '*.so', '*.dll', '*.dylib', 'skia_launcher', 'lib/*.so', 'iOSShell.app', 'iOSShell.ipa', 'visualbench', 'visualbench.exe', 'vulkan-1.dll']\n\ntry:\n  os.makedirs(dst)\nexcept OSError as e:\n  if e.errno != errno.EEXIST:\n    raise\n\nfor pattern in build_products_whitelist:\n  path = os.path.join(src, pattern)\n  for f in glob.glob(path):\n    dst_path = os.path.join(dst, os.path.relpath(f, src))\n    if not os.path.isdir(os.path.dirname(dst_path)):\n      os.makedirs(os.path.dirname(dst_path))\n    print 'Copying build product %s to %s' % (f, dst_path)\n    shutil.move(f, dst_path)\n",
+      "[CUSTOM_/_B_WORK]/skia/out/Build-Ubuntu-EMCC-wasm-Release/Release",
+      "[CUSTOM_[SWARM_OUT_DIR]]/out/Release"
+    ],
+    "infra_step": true,
+    "name": "copy build products",
+    "~followup_annotations": [
+      "@@@STEP_LOG_LINE@python.inline@import errno@@@",
+      "@@@STEP_LOG_LINE@python.inline@import glob@@@",
+      "@@@STEP_LOG_LINE@python.inline@import os@@@",
+      "@@@STEP_LOG_LINE@python.inline@import shutil@@@",
+      "@@@STEP_LOG_LINE@python.inline@import sys@@@",
+      "@@@STEP_LOG_LINE@python.inline@@@@",
+      "@@@STEP_LOG_LINE@python.inline@src = sys.argv[1]@@@",
+      "@@@STEP_LOG_LINE@python.inline@dst = sys.argv[2]@@@",
+      "@@@STEP_LOG_LINE@python.inline@build_products_whitelist = ['dm', 'dm.exe', 'dm.app', 'nanobench.app', 'get_images_from_skps', 'get_images_from_skps.exe', 'nanobench', 'nanobench.exe', 'skpbench', '*.so', '*.dll', '*.dylib', 'skia_launcher', 'lib/*.so', 'iOSShell.app', 'iOSShell.ipa', 'visualbench', 'visualbench.exe', 'vulkan-1.dll']@@@",
+      "@@@STEP_LOG_LINE@python.inline@@@@",
+      "@@@STEP_LOG_LINE@python.inline@try:@@@",
+      "@@@STEP_LOG_LINE@python.inline@  os.makedirs(dst)@@@",
+      "@@@STEP_LOG_LINE@python.inline@except OSError as e:@@@",
+      "@@@STEP_LOG_LINE@python.inline@  if e.errno != errno.EEXIST:@@@",
+      "@@@STEP_LOG_LINE@python.inline@    raise@@@",
+      "@@@STEP_LOG_LINE@python.inline@@@@",
+      "@@@STEP_LOG_LINE@python.inline@for pattern in build_products_whitelist:@@@",
+      "@@@STEP_LOG_LINE@python.inline@  path = os.path.join(src, pattern)@@@",
+      "@@@STEP_LOG_LINE@python.inline@  for f in glob.glob(path):@@@",
+      "@@@STEP_LOG_LINE@python.inline@    dst_path = os.path.join(dst, os.path.relpath(f, src))@@@",
+      "@@@STEP_LOG_LINE@python.inline@    if not os.path.isdir(os.path.dirname(dst_path)):@@@",
+      "@@@STEP_LOG_LINE@python.inline@      os.makedirs(os.path.dirname(dst_path))@@@",
+      "@@@STEP_LOG_LINE@python.inline@    print 'Copying build product %s to %s' % (f, dst_path)@@@",
+      "@@@STEP_LOG_LINE@python.inline@    shutil.move(f, dst_path)@@@",
+      "@@@STEP_LOG_END@python.inline@@@"
+    ]
+  },
+  {
+    "name": "$result",
+    "recipe_result": null,
+    "status_code": 0
+  }
+]
\ No newline at end of file
diff --git a/infra/bots/recipes/compile.py b/infra/bots/recipes/compile.py
index 622c6c3..41569c8 100644
--- a/infra/bots/recipes/compile.py
+++ b/infra/bots/recipes/compile.py
@@ -90,6 +90,7 @@
   'Build-Ubuntu-Clang-x86_64-Debug-MSAN',
   'Build-Ubuntu-Clang-x86_64-Release-Mini',
   'Build-Ubuntu-Clang-x86_64-Release-Vulkan',
+  'Build-Ubuntu-EMCC-wasm-Release',
   'Build-Ubuntu-GCC-arm-Release-Chromecast',
   'Build-Ubuntu-GCC-x86-Debug',
   'Build-Ubuntu-GCC-x86_64-Debug-GN',
diff --git a/infra/bots/tasks.json b/infra/bots/tasks.json
index d92a5d6..4c40891 100644
--- a/infra/bots/tasks.json
+++ b/infra/bots/tasks.json
@@ -204,6 +204,12 @@
         "Build-Debian9-Clang-x86_64-Release-Vulkan"
       ]
     },
+    "Build-Debian9-EMCC-wasm-Release": {
+      "priority": 0.8,
+      "tasks": [
+        "Build-Debian9-EMCC-wasm-Release"
+      ]
+    },
     "Build-Debian9-GCC-arm-Debug-Chromecast": {
       "priority": 0.8,
       "tasks": [
@@ -3727,6 +3733,36 @@
       "isolate": "compile_skia.isolate",
       "priority": 0.8
     },
+    "Build-Debian9-EMCC-wasm-Release": {
+      "cipd_packages": [
+        {
+          "name": "skia/bots/emscripten_sdk",
+          "path": "emscripten_sdk",
+          "version": "version:1"
+        }
+      ],
+      "dimensions": [
+        "cpu:x86-64-avx2",
+        "gpu:none",
+        "os:Debian-9.1",
+        "pool:Skia"
+      ],
+      "extra_args": [
+        "--workdir",
+        "../../..",
+        "compile",
+        "repository=<(REPO)",
+        "buildername=Build-Debian9-EMCC-wasm-Release",
+        "swarm_out_dir=${ISOLATED_OUTDIR}",
+        "revision=<(REVISION)",
+        "patch_repo=<(PATCH_REPO)",
+        "patch_storage=<(PATCH_STORAGE)",
+        "patch_issue=<(ISSUE)",
+        "patch_set=<(PATCHSET)"
+      ],
+      "isolate": "compile_skia.isolate",
+      "priority": 0.8
+    },
     "Build-Debian9-GCC-arm-Debug-Chromecast": {
       "cipd_packages": [
         {