build emscripten on Linux, incl. bots

using emsdk

Change-Id: Id5f347e6303d277d64e4282068703c2c425de15d
Reviewed-on: https://skia-review.googlesource.com/c/skcms/+/199815
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
Auto-Submit: Mike Klein <mtklein@google.com>
diff --git a/build.ninja b/build.ninja
index b1558fa..0310e1f 100644
--- a/build.ninja
+++ b/build.ninja
@@ -39,3 +39,5 @@
 subninja build/ios.portable
 subninja build/ios.tiny
 subninja build/ios.xsan
+
+subninja build/emscripten
diff --git a/build/emscripten b/build/emscripten
index be013a8..05c6bba 100644
--- a/build/emscripten
+++ b/build/emscripten
@@ -5,7 +5,14 @@
 exe     = .html
 out     = out/emscripten$mode
 
+# Run only when emrun is on your PATH, i.e. not on the bots.
 rule run
-    command = emrun $in > $out
+    command = if which emrun >/dev/null; $
+              then $
+                  emrun $in > $out; $
+              else touch $out; fi
+    description = run $in
 
 include build/common
+
+disabled = (uname | grep -qv Linux)
diff --git a/infra/bots/bot.py b/infra/bots/bot.py
index 02e0a2e..c034f55 100644
--- a/infra/bots/bot.py
+++ b/infra/bots/bot.py
@@ -44,6 +44,35 @@
   append('skcms/build/clang', 'cc  = {}/bin/clang  '.format(clang_linux))
   append('skcms/build/clang', 'cxx = {}/bin/clang++'.format(clang_linux))
 
+  # Get an Emscripten environment all set up.
+  call('git clone https://github.com/emscripten-core/emsdk.git')
+  os.chdir('emsdk')
+  call('./emsdk install sdk-1.38.28-64bit')
+  os.chdir('..')
+
+  emscripten_sdk = os.path.realpath('emsdk')
+
+  em_config = os.path.realpath(os.path.join('.', 'em_config'))
+  with open(em_config, 'w') as f:
+    print >>f, '''
+BINARYEN_ROOT = '{}'
+LLVM_ROOT = '{}'
+NODE_JS = '{}'
+COMPILER_ENGINE = NODE_JS
+JS_ENGINES = [NODE_JS]
+  '''.format(
+    emscripten_sdk + '/clang/e1.38.28_64bit/binaryen',
+    emscripten_sdk + '/clang/e1.38.28_64bit',
+    emscripten_sdk + '/node/8.9.1_64bit/bin/node',
+  )
+
+  append('skcms/build/emscripten',
+         'cc  = env EM_CONFIG={} {}/emscripten/1.38.28/emcc'.format(
+           em_config, emscripten_sdk))
+  append('skcms/build/emscripten',
+         'cxx = env EM_CONFIG={} {}/emscripten/1.38.28/em++'.format(
+           em_config, emscripten_sdk))
+
   call('{ninja}/ninja -C skcms -k 0'.format(ninja=ninja))
 
 else:  # Windows