Load emscripten_toolchain in WORKSPACE file

Change-Id: I559a8299af2e66c3387186ee91b11ec195a7a904
diff --git a/.gitignore b/.gitignore
index 5322944..b61d9cf 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
+bazel-*
 .distdir
 *.zip
 site/interpreter.*
 site/*.tflite
 dfu-util
+
diff --git a/WORKSPACE b/WORKSPACE
index 53c4695..99d1a0e 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -25,7 +25,6 @@
 
 load("@libedgetpu//:workspace.bzl", "libedgetpu_dependencies")
 libedgetpu_dependencies(TENSORFLOW_COMMIT, TENSORFLOW_SHA256)
-#libedgetpu_dependencies()
 
 load("@org_tensorflow//tensorflow:workspace3.bzl", "tf_workspace3")
 tf_workspace3()
@@ -39,39 +38,19 @@
 load("@org_tensorflow//tensorflow:workspace0.bzl", "tf_workspace0")
 tf_workspace0()
 
-#
+# Emscripten
 load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
 
+load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
 http_archive(
-    name = "build_bazel_rules_nodejs",
-    sha256 = "0f2de53628e848c1691e5729b515022f5a77369c76a09fbe55611e12731c90e3",
-    urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/2.0.1/rules_nodejs-2.0.1.tar.gz"],
+    name = "emsdk",
+    strip_prefix = "emsdk-c1589b55641787d55d53e883852035beea9aec3f/bazel",
+    url = "https://github.com/emscripten-core/emsdk/archive/c1589b55641787d55d53e883852035beea9aec3f.tar.gz",
+    sha256 = "7a58a9996b113d3e0675df30b5f17e28aa47de2e684a844f05394fe2f6f12e8e",
 )
 
-load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")
+load("@emsdk//:deps.bzl", emsdk_deps = "deps")
+emsdk_deps()
 
-# emscripten 2.0.15
-# http_archive(
-#     name = "emscripten",
-#     sha256 = "e35cced1514ad0da40584f8dd6f76aabf847ce0fa82c6dc8dd9442fb74ed6d0d",
-#     strip_prefix = "install",
-#     url = "https://storage.googleapis.com/webassembly/emscripten-releases-builds/mac/89202930a98fe7f9ed59b574469a9471b0bda7dd/wasm-binaries.tbz2",
-#     build_file = "//emscripten_toolchain:emscripten.BUILD",
-#     type = "tar.bz2",
-# )
-
-# emscripten 2.0.15
-http_archive(
-    name = "emscripten",
-    sha256 = "7ff49fc63adf29970f6e7af1df445d7f554bdbbb2606db1cb5d3567ce69df1db",
-    strip_prefix = "install",
-    url = "https://storage.googleapis.com/webassembly/emscripten-releases-builds/linux/89202930a98fe7f9ed59b574469a9471b0bda7dd/wasm-binaries.tbz2",
-    build_file = "//emscripten_toolchain:emscripten.BUILD",
-    type = "tar.bz2",
-)
-
-npm_install(
-    name = "npm",
-    package_json = "@emscripten//:emscripten/package.json",
-    package_lock_json = "@emscripten//:emscripten/package-lock.json",
-)
+load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps")
+emsdk_emscripten_deps()
diff --git a/emscripten_toolchain/BUILD.bazel b/emscripten_toolchain/BUILD.bazel
deleted file mode 100644
index 89fc320..0000000
--- a/emscripten_toolchain/BUILD.bazel
+++ /dev/null
@@ -1,80 +0,0 @@
-load(":crosstool.bzl", "emscripten_cc_toolchain_config_rule")
-
-package(default_visibility = ["//visibility:public"])
-
-filegroup(
-    name = "common-script-includes",
-    srcs = [
-        "emar.sh",
-        "emcc.sh",
-        "emscripten_config",
-        "env.sh",
-        "@emscripten//:all",
-        "@nodejs//:node_files",
-        "@npm//:node_modules",
-    ],
-)
-
-filegroup(
-    name = "compile-emscripten",
-    srcs = [":common-script-includes"],
-)
-
-filegroup(
-    name = "link-emscripten",
-    srcs = [
-        "emcc_link.sh",
-        "link_wrapper.py",
-        ":common-script-includes",
-        "@emscripten//:all",
-        "@nodejs//:node_files",
-    ],
-)
-
-filegroup(
-    name = "every-file",
-    srcs = [
-        ":compile-emscripten",
-        ":link-emscripten",
-        "@emscripten//:all",
-        "@nodejs//:node_files",
-    ],
-)
-
-filegroup(name = "empty")
-
-# dlmalloc.bc is implictly added by the emscripten toolchain
-cc_library(name = "malloc")
-
-emscripten_cc_toolchain_config_rule(
-    name = "wasm",
-    cpu = "wasm",
-    emscripten_version = "emscripten",
-)
-
-cc_toolchain(
-    name = "cc-compiler-wasm",
-    all_files = ":every-file",
-    ar_files = ":common-script-includes",
-    as_files = ":empty",
-    compiler_files = ":compile-emscripten",
-    dwp_files = ":empty",
-    linker_files = ":link-emscripten",
-    objcopy_files = ":empty",
-    strip_files = ":empty",
-    toolchain_config = "wasm",
-    toolchain_identifier = "emscripten-wasm",
-)
-
-cc_toolchain_suite(
-    name = "everything",
-    toolchains = {
-        "wasm": ":cc-compiler-wasm",
-        "wasm|emscripten": ":cc-compiler-wasm",
-    },
-)
-
-py_binary(
-    name = "wasm_binary",
-    srcs = ["wasm_binary.py"],
-)
diff --git a/emscripten_toolchain/crosstool.bzl b/emscripten_toolchain/crosstool.bzl
deleted file mode 100644
index 10c15cb..0000000
--- a/emscripten_toolchain/crosstool.bzl
+++ /dev/null
@@ -1,1100 +0,0 @@
-"""This module encapsulates logic to create emscripten_cc_toolchain_config rule."""
-
-load(
-    "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl",
-    "action_config",
-    "env_entry",
-    "env_set",
-    "feature",
-    "feature_set",
-    "flag_group",
-    "tool",
-    "tool_path",
-    "variable_with_value",
-    "with_feature_set",
-    _flag_set = "flag_set",
-)
-load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES")
-
-def flag_set(flags = None, features = None, not_features = None, **kwargs):
-    """Extension to flag_set which allows for a "simple" form.
-
-    The simple form allows specifying flags as a simple list instead of a flag_group
-    if enable_if or expand_if semantics are not required.
-
-    Similarly, the simple form allows passing features/not_features if they are a simple
-    list of semantically "and" features.
-    (i.e. "asan" and "dbg", rather than "asan" or "dbg")
-
-    Args:
-      flags: list, set of flags
-      features: list, set of features required to be enabled.
-      not_features: list, set of features required to not be enabled.
-      **kwargs: The rest of the args for flag_set.
-
-    Returns:
-      flag_set
-    """
-    if flags:
-        if kwargs.get("flag_groups"):
-            fail("Cannot set flags and flag_groups")
-        else:
-            kwargs["flag_groups"] = [flag_group(flags = flags)]
-
-    if features or not_features:
-        if kwargs.get("with_features"):
-            fail("Cannot set features/not_feature and with_features")
-        kwargs["with_features"] = [with_feature_set(
-            features = features or [],
-            not_features = not_features or [],
-        )]
-    return _flag_set(**kwargs)
-
-CROSSTOOL_DEFAULT_WARNINGS = [
-    "-Wall",
-]
-
-def _impl(ctx):
-    target_cpu = ctx.attr.cpu
-    toolchain_identifier = "emscripten-" + target_cpu
-    target_system_name = target_cpu + "-unknown-emscripten"
-
-    host_system_name = "i686-unknown-linux-gnu"
-
-    target_libc = "musl/js"
-
-    abi_version = "emscripten_syscalls"
-
-    compiler = "emscripten"
-    abi_libc_version = "default"
-
-    cc_target_os = "emscripten"
-    emscripten_version = ctx.attr.emscripten_version
-
-    builtin_sysroot = "external/emscripten/emscripten/cache/sysroot"
-
-    ################################################################
-    # Tools
-    ################################################################
-    clang_tool = tool(path = "emcc.sh")
-    clif_match_tool = tool(path = "dummy_clif_matcher")
-    link_tool = tool(path = "emcc_link.sh")
-    archive_tool = tool(path = "emar.sh")
-    strip_tool = tool(path = "NOT_USED_STRIP_TOOL")
-
-    #### Legacy tool paths (much of this is redundant with action_configs, but
-    #### these are still used for some things)
-    tool_paths = [
-        tool_path(name = "ar", path = "emar.sh"),
-        tool_path(name = "cpp", path = "/bin/false"),
-        tool_path(name = "gcc", path = "emcc.sh"),
-        tool_path(name = "gcov", path = "/bin/false"),
-        tool_path(name = "ld", path = "emcc_link.sh"),
-        tool_path(name = "nm", path = "NOT_USED"),
-        tool_path(name = "objdump", path = "/bin/false"),
-        tool_path(name = "strip", path = "NOT_USED"),
-    ]
-
-    ################################################################
-    # Action Configs
-    ################################################################
-
-    cpp_compile_action = action_config(
-        action_name = ACTION_NAMES.cpp_compile,
-        tools = [clang_tool],
-    )
-
-    cpp_module_compile_action = action_config(
-        action_name = ACTION_NAMES.cpp_module_compile,
-        tools = [clang_tool],
-    )
-
-    cpp_module_codegen_action = action_config(
-        action_name = ACTION_NAMES.cpp_module_codegen,
-        tools = [clang_tool],
-    )
-
-    clif_match_action = action_config(
-        action_name = ACTION_NAMES.clif_match,
-        tools = [clif_match_tool],
-    )
-
-    cpp_link_dynamic_library_action = action_config(
-        action_name = ACTION_NAMES.cpp_link_dynamic_library,
-        tools = [link_tool],
-    )
-
-    strip_action = action_config(
-        action_name = ACTION_NAMES.strip,
-        tools = [strip_tool],
-    )
-
-    preprocess_assemble_action = action_config(
-        action_name = ACTION_NAMES.preprocess_assemble,
-        tools = [clang_tool],
-    )
-
-    cpp_header_parsing_action = action_config(
-        action_name = ACTION_NAMES.cpp_header_parsing,
-        tools = [clang_tool],
-    )
-
-    cpp_link_static_library_action = action_config(
-        action_name = ACTION_NAMES.cpp_link_static_library,
-        enabled = True,
-        flag_sets = [
-            flag_set(
-                flag_groups = [
-                    flag_group(
-                        flags = ["rcsD", "%{output_execpath}"],
-                        expand_if_available = "output_execpath",
-                    ),
-                ],
-            ),
-            flag_set(
-                flag_groups = [
-                    flag_group(
-                        iterate_over = "libraries_to_link",
-                        flag_groups = [
-                            flag_group(
-                                flags = ["%{libraries_to_link.name}"],
-                                expand_if_equal = variable_with_value(
-                                    name = "libraries_to_link.type",
-                                    value = "object_file",
-                                ),
-                            ),
-                            flag_group(
-                                flags = ["%{libraries_to_link.object_files}"],
-                                iterate_over = "libraries_to_link.object_files",
-                                expand_if_equal = variable_with_value(
-                                    name = "libraries_to_link.type",
-                                    value = "object_file_group",
-                                ),
-                            ),
-                        ],
-                        expand_if_available = "libraries_to_link",
-                    ),
-                ],
-            ),
-            flag_set(
-                flag_groups = [
-                    flag_group(
-                        flags = ["@%{linker_param_file}"],
-                        expand_if_available = "linker_param_file",
-                    ),
-                ],
-            ),
-        ],
-        tools = [archive_tool],
-    )
-
-    c_compile_action = action_config(
-        action_name = ACTION_NAMES.c_compile,
-        tools = [clang_tool],
-    )
-
-    linkstamp_compile_action = action_config(
-        action_name = ACTION_NAMES.linkstamp_compile,
-        tools = [clang_tool],
-    )
-
-    assemble_action = action_config(
-        action_name = ACTION_NAMES.assemble,
-        tools = [clang_tool],
-    )
-
-    cpp_link_executable_action = action_config(
-        action_name = ACTION_NAMES.cpp_link_executable,
-        tools = [link_tool],
-    )
-
-    cpp_link_nodeps_dynamic_library_action = action_config(
-        action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library,
-        tools = [link_tool],
-    )
-
-    action_configs = [
-        strip_action,
-        c_compile_action,
-        cpp_compile_action,
-        linkstamp_compile_action,
-        assemble_action,
-        preprocess_assemble_action,
-        cpp_header_parsing_action,
-        cpp_module_compile_action,
-        cpp_module_codegen_action,
-        cpp_link_executable_action,
-        cpp_link_dynamic_library_action,
-        cpp_link_nodeps_dynamic_library_action,
-        cpp_link_static_library_action,
-        clif_match_action,
-    ]
-
-    all_compile_actions = [
-        ACTION_NAMES.c_compile,
-        ACTION_NAMES.cpp_compile,
-        ACTION_NAMES.linkstamp_compile,
-        ACTION_NAMES.assemble,
-        ACTION_NAMES.preprocess_assemble,
-        ACTION_NAMES.cpp_header_parsing,
-        ACTION_NAMES.cpp_module_compile,
-        ACTION_NAMES.cpp_module_codegen,
-        ACTION_NAMES.clif_match,
-        ACTION_NAMES.lto_backend,
-    ]
-
-    all_cpp_compile_actions = [
-        ACTION_NAMES.cpp_compile,
-        ACTION_NAMES.linkstamp_compile,
-        ACTION_NAMES.cpp_header_parsing,
-        ACTION_NAMES.cpp_module_compile,
-        ACTION_NAMES.cpp_module_codegen,
-        ACTION_NAMES.clif_match,
-    ]
-
-    preprocessor_compile_actions = [
-        ACTION_NAMES.c_compile,
-        ACTION_NAMES.cpp_compile,
-        ACTION_NAMES.linkstamp_compile,
-        ACTION_NAMES.preprocess_assemble,
-        ACTION_NAMES.cpp_header_parsing,
-        ACTION_NAMES.cpp_module_compile,
-        ACTION_NAMES.clif_match,
-    ]
-
-    all_link_actions = [
-        ACTION_NAMES.cpp_link_executable,
-        ACTION_NAMES.cpp_link_dynamic_library,
-        ACTION_NAMES.cpp_link_nodeps_dynamic_library,
-    ]
-
-    ################################################################
-    # Features
-    ################################################################
-
-    features = [
-        # This set of magic "feature"s are important configuration information for blaze.
-        feature(name = "no_legacy_features", enabled = True),
-        feature(
-            name = "has_configured_linker_path",
-            enabled = True,
-        ),
-
-        # Blaze requests this feature by default, but we don't care.
-        feature(name = "dependency_file"),
-
-        # Blaze requests this feature by default, but we don't care.
-        feature(name = "random_seed"),
-
-        # Formerly "needsPic" attribute
-        feature(name = "supports_pic", enabled = False),
-
-        # Blaze requests this feature by default.
-        # Blaze also tests if this feature is supported, before setting the "pic" build-variable.
-        feature(name = "pic"),
-
-        # Blaze requests this feature if fission is requested
-        # Blaze also tests if it's supported to see if we support fission.
-        feature(name = "per_object_debug_info"),
-
-        # Blaze requests this feature by default.
-        # Blaze also tests if this feature is supported before setting preprocessor_defines
-        # (...but why?)
-        feature(name = "preprocessor_defines"),
-
-        # Blaze requests this feature by default.
-        # Blaze also tests if this feature is supported before setting includes. (...but why?)
-        feature(name = "include_paths"),
-
-        # Blaze tests if this feature is enabled in order to create implicit
-        # "nodeps" .so outputs from cc_library rules.
-        feature(name = "supports_dynamic_linker", enabled = False),
-
-        # Blaze requests this feature when linking a cc_binary which is
-        # "dynamic" aka linked against nodeps-dynamic-library cc_library
-        # outputs.
-        feature(name = "dynamic_linking_mode"),
-
-        #### Configuration features
-        feature(
-            name = "crosstool_cpu",
-            enabled = True,
-            implies = ["crosstool_cpu_" + target_cpu],
-        ),
-        feature(
-            name = "crosstool_cpu_asmjs",
-            provides = ["variant:crosstool_cpu"],
-        ),
-        feature(
-            name = "crosstool_cpu_wasm",
-            provides = ["variant:crosstool_cpu"],
-        ),
-
-        # These 3 features will be automatically enabled by blaze in the
-        # corresponding build mode.
-        feature(
-            name = "opt",
-            provides = ["variant:crosstool_build_mode"],
-        ),
-        feature(
-            name = "dbg",
-            provides = ["variant:crosstool_build_mode"],
-        ),
-        feature(
-            name = "fastbuild",
-            provides = ["variant:crosstool_build_mode"],
-        ),
-
-        #### User-settable features
-
-        # Set if enabling exceptions.
-        feature(name = "exceptions"),
-
-        # This feature overrides the default optimization to prefer execution speed
-        # over binary size (like clang -O3).
-        feature(
-            name = "optimized_for_speed",
-            provides = ["variant:crosstool_optimization_mode"],
-        ),
-
-        # This feature overrides the default optimization to prefer binary size over
-        # execution speed (like clang -Oz).
-        feature(
-            name = "optimized_for_size",
-            provides = ["variant:crosstool_optimization_mode"],
-        ),
-
-        # Convenience aliases / alt-spellings.
-        feature(
-            name = "optimize_for_speed",
-            implies = ["optimized_for_speed"],
-        ),
-        feature(
-            name = "optimize_for_size",
-            implies = ["optimized_for_size"],
-        ),
-
-        # This feature allows easier use of profiling tools by preserving mangled
-        # C++ names. This does everything profiling_funcs does and more.
-        feature(name = "profiling"),
-
-        # This feature emits only enough debug info for function names to appear
-        # in profiles.
-        feature(name = "profiling_funcs"),
-
-        # This feature allows source maps to be generated.
-        feature(
-            name = "source_maps",
-            implies = ["full_debug_info"],
-        ),
-        feature(
-            name = "dwarf_debug_info",
-            implies = ["profiling"],
-        ),
-
-        # Turns on full debug info (-g4).
-        feature(name = "full_debug_info"),
-
-        # Enables the use of "Emscripten" Pthread implementation.
-        # https://kripken.github.io/emscripten-site/docs/porting/pthreads.html
-        # https://github.com/kripken/emscripten/wiki/Pthreads-with-WebAssembly
-        feature(name = "use_pthreads"),
-
-        # If enabled, the runtime will exit when main() completes.
-        feature(name = "exit_runtime"),
-
-        # Primarily for toolchain maintainers:
-        feature(name = "emcc_debug"),
-        feature(name = "emcc_debug_link"),
-        feature(
-            name = "llvm_backend",
-            requires = [feature_set(features = ["crosstool_cpu_wasm"])],
-            enabled = True,
-        ),
-
-        # Remove once flag is flipped.
-        # See https://github.com/bazelbuild/bazel/issues/7687
-        feature(
-            name = "do_not_split_linking_cmdline",
-        ),
-
-        # Adds simd support, only available with the llvm backend.
-        feature(
-            name = "wasm_simd",
-            requires = [feature_set(features = ["llvm_backend"])],
-        ),
-        feature(
-            name = "precise_long_double_printf",
-            enabled = True,
-        ),
-        feature(
-            name = "wasm_warnings_as_errors",
-            enabled = True,
-        ),
-
-        # ASan and UBSan. See also:
-        # https://emscripten.org/docs/debugging/Sanitizers.html
-        feature(name = "wasm_asan"),
-        feature(name = "wasm_ubsan"),
-
-        feature(
-            name = "output_format_js",
-            enabled = True,
-        ),
-    ]
-
-    crosstool_default_flag_sets = [
-        # Compile, Link, and CC_FLAGS make variable
-        flag_set(
-            actions = [
-                ACTION_NAMES.c_compile,
-                ACTION_NAMES.cpp_compile,
-                ACTION_NAMES.linkstamp_compile,
-                ACTION_NAMES.assemble,
-                ACTION_NAMES.preprocess_assemble,
-                ACTION_NAMES.cpp_header_parsing,
-                ACTION_NAMES.cpp_module_compile,
-                ACTION_NAMES.cpp_module_codegen,
-                ACTION_NAMES.clif_match,
-                ACTION_NAMES.cpp_link_executable,
-                ACTION_NAMES.cpp_link_dynamic_library,
-                ACTION_NAMES.cpp_link_nodeps_dynamic_library,
-            ],
-            flag_groups = [
-                flag_group(
-                    flags = ["--sysroot=%{sysroot}"],
-                    expand_if_available = "sysroot",
-                ),
-            ],
-        ),
-        # Compile + Link
-        flag_set(
-            actions = [
-                ACTION_NAMES.c_compile,
-                ACTION_NAMES.cpp_compile,
-                ACTION_NAMES.linkstamp_compile,
-                ACTION_NAMES.assemble,
-                ACTION_NAMES.preprocess_assemble,
-                ACTION_NAMES.cpp_header_parsing,
-                ACTION_NAMES.cpp_module_compile,
-                ACTION_NAMES.cpp_module_codegen,
-                ACTION_NAMES.clif_match,
-                ACTION_NAMES.cpp_link_executable,
-                ACTION_NAMES.cpp_link_dynamic_library,
-                ACTION_NAMES.cpp_link_nodeps_dynamic_library,
-            ],
-            # This forces color diagnostics even on Forge (where we don't have an
-            # attached terminal).
-            flags = [
-                "-fdiagnostics-color",
-            ],
-        ),
-        # C++ compiles (and implicitly link)
-        flag_set(
-            actions = all_cpp_compile_actions,
-            flags = [
-                "-fno-exceptions",
-            ],
-            not_features = ["exceptions"],
-        ),
-        flag_set(
-            actions = all_cpp_compile_actions,
-            flags = [
-                "-fexceptions",
-            ],
-            features = ["exceptions"],
-        ),
-        # All compiles (and implicitly link)
-        flag_set(
-            actions = all_compile_actions +
-                      all_link_actions,
-            flags = [
-                "-fno-strict-aliasing",
-                "-funsigned-char",
-                "-no-canonical-prefixes",
-            ],
-        ),
-        # Language Features
-        flag_set(
-            actions = all_cpp_compile_actions,
-            flags = ["-std=gnu++17", "-nostdinc", "-nostdinc++",],
-        ),
-
-        # Emscripten-specific settings:
-        flag_set(
-            actions = all_compile_actions + all_link_actions,
-            flags = ["-s", "WASM=0"],
-            features = ["crosstool_cpu_asmjs"],
-        ),
-        flag_set(
-            actions = all_compile_actions +
-                      all_link_actions,
-            flags = ["-s", "USE_PTHREADS=1"],
-            features = ["use_pthreads"],
-        ),
-        flag_set(
-            actions = all_link_actions,
-            flags = ["-s", "EXIT_RUNTIME=1"],
-            features = ["exit_runtime"],
-        ),
-        flag_set(
-            actions = all_compile_actions + all_link_actions,
-            flags = ["-pthread"],
-            features = ["llvm_backend", "use_pthreads"],
-        ),
-        flag_set(
-            actions = all_compile_actions + all_link_actions,
-            flags = ["-msimd128"],
-            features = ["wasm_simd"],
-        ),
-        flag_set(
-            actions = all_link_actions,
-            flags = ["-s", "PRINTF_LONG_DOUBLE=1"],
-            features = ["precise_long_double_printf"],
-        ),
-        flag_set(
-            actions = all_link_actions,
-            flags = ["--oformat=js"],
-            features = ["output_format_js"],
-        ),
-
-        # Opt
-        flag_set(
-            actions = preprocessor_compile_actions,
-            flags = ["-DNDEBUG"],
-            features = ["opt"],
-        ),
-        flag_set(
-            actions = all_compile_actions,
-            flags = ["-fomit-frame-pointer"],
-            features = ["opt"],
-        ),
-        flag_set(
-            actions = all_compile_actions +
-                      all_link_actions,
-            flags = ["-O3"],
-            features = ["opt"],
-        ),
-        # Users can override opt-level with semantic names...
-        flag_set(
-            actions = all_compile_actions +
-                      all_link_actions,
-            flags = ["-Oz"],
-            features = ["optimized_for_size", "opt"],
-        ),
-        flag_set(
-            actions = all_compile_actions +
-                      all_link_actions,
-            flags = ["-O3"],
-            features = ["optimized_for_speed", "opt"],
-        ),
-
-        # Fastbuild
-        flag_set(
-            actions = all_compile_actions,
-            flags = ["-fomit-frame-pointer"],
-            features = ["fastbuild"],
-        ),
-        flag_set(
-            actions = all_compile_actions +
-                      all_link_actions,
-            flags = ["-O2"],
-            features = ["fastbuild"],
-        ),
-
-        # Dbg
-        flag_set(
-            actions = all_compile_actions,
-            flags = ["-fno-omit-frame-pointer"],
-            features = ["dbg"],
-        ),
-        flag_set(
-            actions = all_compile_actions +
-                      all_link_actions,
-            flags = ["-g", "-O0"],
-            features = ["dbg"],
-        ),
-        flag_set(
-            actions = all_compile_actions +
-                      all_link_actions,
-            flags = [
-                "-g4",
-                "-fsanitize=address",
-                "-O1",
-                "-DADDRESS_SANITIZER=1",
-                "-fno-omit-frame-pointer",
-            ],
-            features = ["wasm_asan"],
-        ),
-        flag_set(
-            actions = all_compile_actions +
-                      all_link_actions,
-            flags = [
-                "-g4",
-                "-fsanitize=undefined",
-                "-O1",
-                "-DUNDEFINED_BEHAVIOR_SANITIZER=1",
-                "-fno-omit-frame-pointer",
-                "-fno-sanitize=vptr",
-            ],
-            features = ["wasm_ubsan"],
-        ),
-
-        # Profiling provides full debug info and a special --profiling flag
-        # to control name mangling
-        flag_set(
-            actions = all_link_actions,
-            flags = ["--profiling"],
-            features = ["profiling"],
-        ),
-        flag_set(
-            actions = all_link_actions,
-            flags = ["--profiling_funcs"],
-            features = ["profiling_funcs"],
-        ),
-        flag_set(
-            actions = all_compile_actions +
-                      all_link_actions,
-            flags = ["-g4"],
-            features = ["full_debug_info"],
-        ),
-        flag_set(
-            actions = all_link_actions,
-            flags = ["-gseparate-dwarf"],
-            features = ["dwarf_debug_info"],
-        ),
-        flag_set(
-            actions = all_compile_actions +
-                      all_link_actions,
-            flags = ["-fdebug-compilation-dir=."],
-            features = ["dwarf_debug_info"],
-        ),
-        # Generic warning flag list
-        flag_set(
-            actions = all_compile_actions,
-            flags = CROSSTOOL_DEFAULT_WARNINGS,
-        ),
-
-        # Defines and Includes and Paths and such
-        flag_set(
-            actions = all_compile_actions,
-            flag_groups = [
-                flag_group(flags = ["-fPIC"], expand_if_available = "pic"),
-            ],
-        ),
-        flag_set(
-            actions = preprocessor_compile_actions,
-            flag_groups = [
-                flag_group(
-                    flags = ["-D%{preprocessor_defines}"],
-                    iterate_over = "preprocessor_defines",
-                ),
-            ],
-        ),
-        flag_set(
-            actions = preprocessor_compile_actions,
-            flag_groups = [
-                flag_group(
-                    flags = ["-include", "%{includes}"],
-                    iterate_over = "includes",
-                    expand_if_available = "includes",
-                ),
-            ],
-        ),
-        flag_set(
-            actions = preprocessor_compile_actions,
-            flag_groups = [
-                flag_group(
-                    flags = ["-iquote", "%{quote_include_paths}"],
-                    iterate_over = "quote_include_paths",
-                ),
-                flag_group(
-                    flags = ["-I%{include_paths}"],
-                    iterate_over = "include_paths",
-                ),
-                flag_group(
-                    flags = ["-isystem", "%{system_include_paths}"],
-                    iterate_over = "system_include_paths",
-                ),
-            ],
-        ),
-
-        ## Linking options (not libs -- those go last)
-
-        # Generic link options
-        flag_set(
-            actions = [
-                ACTION_NAMES.cpp_link_dynamic_library,
-                ACTION_NAMES.cpp_link_nodeps_dynamic_library,
-            ],
-            flags = ["-shared"],
-        ),
-
-        # Linker search paths and objects:
-        flag_set(
-            actions = all_link_actions,
-            flag_groups = [
-                flag_group(
-                    iterate_over = "runtime_library_search_directories",
-                    flag_groups = [
-                        flag_group(
-                            flags = [
-                                "-Wl,-rpath,$EXEC_ORIGIN/%{runtime_library_search_directories}",
-                            ],
-                            expand_if_true = "is_cc_test",
-                        ),
-                        flag_group(
-                            flags = [
-                                "-Wl,-rpath,$ORIGIN/%{runtime_library_search_directories}",
-                            ],
-                            expand_if_false = "is_cc_test",
-                        ),
-                    ],
-                    expand_if_available = "runtime_library_search_directories",
-                ),
-            ],
-        ),
-        flag_set(
-            actions = all_link_actions,
-            flag_groups = [
-                flag_group(
-                    flags = ["-L%{library_search_directories}"],
-                    iterate_over = "library_search_directories",
-                    expand_if_available = "library_search_directories",
-                ),
-            ],
-        ),
-        flag_set(
-            actions = all_link_actions,
-            flag_groups = [
-                flag_group(
-                    # This is actually a list of object files from the linkstamp steps
-                    flags = ["%{linkstamp_paths}"],
-                    iterate_over = "linkstamp_paths",
-                    expand_if_available = "linkstamp_paths",
-                ),
-            ],
-        ),
-        flag_set(
-            actions = all_link_actions,
-            flag_groups = [
-                flag_group(
-                    flags = ["@%{thinlto_param_file}"],
-                    expand_if_available = "libraries_to_link",
-                    expand_if_true = "thinlto_param_file",
-                ),
-                flag_group(
-                    iterate_over = "libraries_to_link",
-                    flag_groups = [
-                        flag_group(
-                            flags = ["-Wl,--start-lib"],
-                            expand_if_equal = variable_with_value(
-                                name = "libraries_to_link.type",
-                                value = "object_file_group",
-                            ),
-                        ),
-                        flag_group(
-                            flags = ["-Wl,-whole-archive"],
-                            expand_if_true = "libraries_to_link.is_whole_archive",
-                        ),
-                        flag_group(
-                            flags = ["%{libraries_to_link.object_files}"],
-                            iterate_over = "libraries_to_link.object_files",
-                            expand_if_equal = variable_with_value(
-                                name = "libraries_to_link.type",
-                                value = "object_file_group",
-                            ),
-                        ),
-                        flag_group(
-                            flags = ["%{libraries_to_link.name}"],
-                            expand_if_equal = variable_with_value(
-                                name = "libraries_to_link.type",
-                                value = "object_file",
-                            ),
-                        ),
-                        flag_group(
-                            flags = ["%{libraries_to_link.name}"],
-                            expand_if_equal = variable_with_value(
-                                name = "libraries_to_link.type",
-                                value = "interface_library",
-                            ),
-                        ),
-                        flag_group(
-                            flags = ["%{libraries_to_link.name}"],
-                            expand_if_equal = variable_with_value(
-                                name = "libraries_to_link.type",
-                                value = "static_library",
-                            ),
-                        ),
-                        flag_group(
-                            flags = ["-l%{libraries_to_link.name}"],
-                            expand_if_equal = variable_with_value(
-                                name = "libraries_to_link.type",
-                                value = "dynamic_library",
-                            ),
-                        ),
-                        flag_group(
-                            flags = ["-l:%{libraries_to_link.name}"],
-                            expand_if_equal = variable_with_value(
-                                name = "libraries_to_link.type",
-                                value = "versioned_dynamic_library",
-                            ),
-                        ),
-                        flag_group(
-                            flags = ["-Wl,-no-whole-archive"],
-                            expand_if_true = "libraries_to_link.is_whole_archive",
-                        ),
-                        flag_group(
-                            flags = ["-Wl,--end-lib"],
-                            expand_if_equal = variable_with_value(
-                                name = "libraries_to_link.type",
-                                value = "object_file_group",
-                            ),
-                        ),
-                    ],
-                    expand_if_available = "libraries_to_link",
-                ),
-            ],
-        ),
-
-        # Configure the header parsing and preprocessing.
-        flag_set(
-            actions = [ACTION_NAMES.cpp_header_parsing],
-            flags = ["-xc++-header", "-fsyntax-only"],
-            features = ["parse_headers"],
-        ),
-
-        # Note: user compile flags should be nearly last -- you probably
-        # don't want to put any more features after this!
-        flag_set(
-            actions = [
-                ACTION_NAMES.c_compile,
-                ACTION_NAMES.cpp_compile,
-                ACTION_NAMES.linkstamp_compile,
-                ACTION_NAMES.assemble,
-                ACTION_NAMES.preprocess_assemble,
-                ACTION_NAMES.cpp_header_parsing,
-                ACTION_NAMES.cpp_module_compile,
-                ACTION_NAMES.cpp_module_codegen,
-                ACTION_NAMES.clif_match,
-            ],
-            flag_groups = [
-                flag_group(
-                    flags = ["%{user_compile_flags}"],
-                    iterate_over = "user_compile_flags",
-                    expand_if_available = "user_compile_flags",
-                ),
-            ],
-        ),
-        flag_set(
-            actions = all_link_actions,
-            flag_groups = [
-                flag_group(
-                    flags = ["%{user_link_flags}"],
-                    iterate_over = "user_link_flags",
-                    expand_if_available = "user_link_flags",
-                ),
-            ],
-        ),
-        ## Options which need to go late -- after all the user options -- go here.
-        flag_set(
-            # One might hope that these options would only be needed for C++
-            # compiles. But, sadly, users compile ".c" files with custom
-            # copts=["-x", "c++"], and expect that to be able to find C++ stdlib
-            # headers. It might be worth pondering how blaze could support this sort
-            # of use-case better.
-            actions = preprocessor_compile_actions +
-                      [ACTION_NAMES.cc_flags_make_variable],
-            flags = [
-                "-iwithsysroot" + "/include/c++/v1",
-                "-iwithsysroot" + "/include/compat",
-                "-iwithsysroot" + "/include",
-                "-isystem", "external/emscripten/lib/clang/13.0.0/include",
-            ],
-        ),
-        # Inputs and outputs
-        flag_set(
-            actions = [
-                ACTION_NAMES.c_compile,
-                ACTION_NAMES.cpp_compile,
-                ACTION_NAMES.linkstamp_compile,
-                ACTION_NAMES.assemble,
-                ACTION_NAMES.preprocess_assemble,
-                ACTION_NAMES.cpp_header_parsing,
-                ACTION_NAMES.cpp_module_compile,
-                ACTION_NAMES.cpp_module_codegen,
-                ACTION_NAMES.clif_match,
-            ],
-            flag_groups = [
-                flag_group(
-                    flags = ["-MD", "-MF", "%{dependency_file}"],
-                    expand_if_available = "dependency_file",
-                ),
-            ],
-        ),
-        flag_set(
-            actions = [
-                ACTION_NAMES.c_compile,
-                ACTION_NAMES.cpp_compile,
-                ACTION_NAMES.linkstamp_compile,
-                ACTION_NAMES.assemble,
-                ACTION_NAMES.preprocess_assemble,
-                ACTION_NAMES.cpp_header_parsing,
-                ACTION_NAMES.cpp_module_compile,
-                ACTION_NAMES.cpp_module_codegen,
-                ACTION_NAMES.clif_match,
-            ],
-            flag_groups = [
-                flag_group(
-                    flags = ["-c", "%{source_file}"],
-                    expand_if_available = "source_file",
-                ),
-            ],
-        ),
-        flag_set(
-            actions = [
-                ACTION_NAMES.c_compile,
-                ACTION_NAMES.cpp_compile,
-                ACTION_NAMES.linkstamp_compile,
-                ACTION_NAMES.assemble,
-                ACTION_NAMES.preprocess_assemble,
-                ACTION_NAMES.cpp_header_parsing,
-                ACTION_NAMES.cpp_module_compile,
-                ACTION_NAMES.cpp_module_codegen,
-                ACTION_NAMES.clif_match,
-            ],
-            flag_groups = [
-                flag_group(
-                    flags = ["-S"],
-                    expand_if_available = "output_assembly_file",
-                ),
-                flag_group(
-                    flags = ["-E"],
-                    expand_if_available = "output_preprocess_file",
-                ),
-                flag_group(
-                    flags = ["-o", "%{output_file}"],
-                    expand_if_available = "output_file",
-                ),
-            ],
-        ),
-        flag_set(
-            actions = all_link_actions,
-            flag_groups = [
-                flag_group(
-                    flags = ["-o", "%{output_execpath}"],
-                    expand_if_available = "output_execpath",
-                ),
-            ],
-        ),
-        # And finally, the params file!
-        flag_set(
-            actions = all_link_actions,
-            flag_groups = [
-                flag_group(
-                    flags = ["@%{linker_param_file}"],
-                    expand_if_available = "linker_param_file",
-                ),
-            ],
-        ),
-        flag_set(
-            actions = all_compile_actions,
-            flags = [
-                "-Wno-builtin-macro-redefined",
-                # Genrules may not escape quotes enough for these, so
-                # don't put them into $(CC_FLAGS):
-                '-D__DATE__="redacted"',
-                '-D__TIMESTAMP__="redacted"',
-                '-D__TIME__="redacted"',
-            ],
-        ),
-        flag_set(
-            actions = all_compile_actions,
-            flags = ["-Werror"],
-            features = ["wasm_warnings_as_errors"],
-        ),
-    ]
-
-    crosstool_default_env_sets = [
-        # Use llvm backend.  Off by default, enabled via --features=llvm_backend
-        env_set(
-            actions = all_compile_actions +
-                      all_link_actions +
-                      [ACTION_NAMES.cpp_link_static_library],
-            env_entries = [env_entry(key = "EMCC_WASM_BACKEND", value = "1")],
-            with_features = [with_feature_set(features = ["llvm_backend"])],
-        ),
-        # Debug compile and link. Off by default, enabled via --features=emcc_debug
-        env_set(
-            actions = all_compile_actions,
-            env_entries = [env_entry(key = "EMCC_DEBUG", value = "1")],
-            with_features = [with_feature_set(features = ["emcc_debug"])],
-        ),
-
-        # Debug only link step. Off by default, enabled via --features=emcc_debug_link
-        env_set(
-            actions = all_link_actions,
-            env_entries = [env_entry(key = "EMCC_DEBUG", value = "1")],
-            with_features = [
-                with_feature_set(features = ["emcc_debug"]),
-                with_feature_set(features = ["emcc_debug_link"]),
-            ],
-        ),
-    ]
-
-    crosstool_default_flags_feature = feature(
-        name = "crosstool_default_flags",
-        enabled = True,
-        flag_sets = crosstool_default_flag_sets,
-        env_sets = crosstool_default_env_sets,
-    )
-
-    features.append(crosstool_default_flags_feature)
-
-    cxx_builtin_include_directories = [
-        "external/emscripten/emscripten/cache/sysroot/include/c++/v1",
-        "external/emscripten/emscripten/cache/sysroot/include/compat",
-        "external/emscripten/emscripten/cache/sysroot/include",
-        "external/emscripten/lib/clang/13.0.0/include",
-    ]
-
-    artifact_name_patterns = []
-
-    make_variables = []
-
-    out = ctx.actions.declare_file(ctx.label.name)
-    ctx.actions.write(out, "Fake executable")
-    return [
-        cc_common.create_cc_toolchain_config_info(
-            ctx = ctx,
-            features = features,
-            action_configs = action_configs,
-            artifact_name_patterns = artifact_name_patterns,
-            cxx_builtin_include_directories = cxx_builtin_include_directories,
-            toolchain_identifier = toolchain_identifier,
-            host_system_name = host_system_name,
-            target_system_name = target_system_name,
-            target_cpu = target_cpu,
-            target_libc = target_libc,
-            compiler = compiler,
-            abi_version = abi_version,
-            abi_libc_version = abi_libc_version,
-            tool_paths = tool_paths,
-            make_variables = make_variables,
-            builtin_sysroot = builtin_sysroot,
-            cc_target_os = cc_target_os,
-        ),
-        DefaultInfo(
-            executable = out,
-        ),
-    ]
-
-emscripten_cc_toolchain_config_rule = rule(
-    implementation = _impl,
-    attrs = {
-        "cpu": attr.string(mandatory = True, values = ["asmjs", "wasm"]),
-        "emscripten_version": attr.string(mandatory = True),
-    },
-    provides = [CcToolchainConfigInfo],
-    executable = True,
-)
diff --git a/emscripten_toolchain/emar.sh b/emscripten_toolchain/emar.sh
deleted file mode 100755
index 965442e..0000000
--- a/emscripten_toolchain/emar.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-
-source emscripten_toolchain/env.sh
-
-exec python3 $EMSCRIPTEN/emar.py "$@"
diff --git a/emscripten_toolchain/emcc.sh b/emscripten_toolchain/emcc.sh
deleted file mode 100755
index 66d00b6..0000000
--- a/emscripten_toolchain/emcc.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-
-source emscripten_toolchain/env.sh
-
-exec python3 external/emscripten/emscripten/emcc.py "$@"
diff --git a/emscripten_toolchain/emcc_link.sh b/emscripten_toolchain/emcc_link.sh
deleted file mode 100755
index 9d0f8e2..0000000
--- a/emscripten_toolchain/emcc_link.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-
-source emscripten_toolchain/env.sh
-
-exec python3 emscripten_toolchain/link_wrapper.py "$@"
diff --git a/emscripten_toolchain/emscripten.BUILD b/emscripten_toolchain/emscripten.BUILD
deleted file mode 100644
index 6f11852..0000000
--- a/emscripten_toolchain/emscripten.BUILD
+++ /dev/null
@@ -1,6 +0,0 @@
-package(default_visibility = ['//visibility:public'])
-
-filegroup(
-    name = "all",
-    srcs = glob(["**"]),
-)
diff --git a/emscripten_toolchain/emscripten_config b/emscripten_toolchain/emscripten_config
deleted file mode 100644
index b7948ac..0000000
--- a/emscripten_toolchain/emscripten_config
+++ /dev/null
@@ -1,12 +0,0 @@
-import os
-import platform
-
-ROOT_DIR = os.environ["ROOT_DIR"]
-EMSCRIPTEN_ROOT = os.environ["EMSCRIPTEN"]
-LLVM_ROOT = ROOT_DIR + "/external/emscripten/bin"
-BINARYEN_ROOT = ROOT_DIR + "/external/emscripten"
-FROZEN_CACHE = True
-
-system = platform.system()
-nodejs_binary = "node.exe" if(system =="Windows") else "bin/node"
-NODE_JS = ROOT_DIR + "/external/nodejs_{}_amd64/{}".format(system.lower(), nodejs_binary)
diff --git a/emscripten_toolchain/env.sh b/emscripten_toolchain/env.sh
deleted file mode 100755
index dfb4ddc..0000000
--- a/emscripten_toolchain/env.sh
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/bash
-
-export ROOT_DIR=`(pwd -P)`
-export EMSCRIPTEN=${ROOT_DIR}/external/emscripten/emscripten
-export EM_CONFIG=${ROOT_DIR}/emscripten_toolchain/emscripten_config
diff --git a/emscripten_toolchain/link_wrapper.py b/emscripten_toolchain/link_wrapper.py
deleted file mode 100644
index 1e26bde..0000000
--- a/emscripten_toolchain/link_wrapper.py
+++ /dev/null
@@ -1,169 +0,0 @@
-#!/usr/bin/env python
-"""wrapper around emcc link step.
-
-This wrapper currently serves the following purposes.
-
-1. When building with --config=wasm the final output is multiple files, usually
-   at least one .js and one .wasm file. Since the cc_binary link step only
-   allows a single output, we must tar up the outputs into a single file.
-
-2. Add quotes around arguments that need them in the response file to work
-   around a bazel quirk.
-
-3. Ensure the external_debug_info section of the wasm points at the correct
-   bazel path.
-"""
-
-from __future__ import print_function
-
-import argparse
-import os
-import subprocess
-import sys
-
-# Only argument should be @path/to/parameter/file
-assert sys.argv[1][0] == '@'
-param_filename = sys.argv[1][1:]
-param_file_args = [l.strip() for l in open(param_filename, 'r').readlines()]
-
-# Re-write response file if needed.
-if any(' ' in a for a in param_file_args):
-  new_param_filename = param_filename + '.modified'
-  with open(new_param_filename, 'w') as f:
-    for param in param_file_args:
-      if ' ' in param:
-        f.write('"%s"' % param)
-      else:
-        f.write(param)
-      f.write('\n')
-  sys.argv[1] = '@' + new_param_filename
-
-emcc_py = os.path.join(os.environ['EMSCRIPTEN'], 'emcc.py')
-rtn = subprocess.call(['python3', emcc_py] + sys.argv[1:])
-if rtn != 0:
-  sys.exit(1)
-
-# Parse the arguments that we gave to the linker to determine what the output
-# file is named and what the output format is.
-parser = argparse.ArgumentParser(add_help=False)
-parser.add_argument('-o')
-parser.add_argument('--oformat')
-options = parser.parse_known_args(param_file_args)[0]
-output_file = options.o
-oformat = options.oformat
-outdir = os.path.dirname(output_file)
-base_name = os.path.basename(output_file)
-
-# The output file name is the name of the build rule that was built.
-# Add an appropriate file extension based on --oformat.
-if oformat is not None:
-  base_name_split = os.path.splitext(base_name)
-
-  # If the output name has no extension, give it the appropriate extension.
-  if not base_name_split[1]:
-    os.rename(output_file, output_file + '.' + oformat)
-
-  # If the output name does have an extension and it matches the output format,
-  # change the base_name so it doesn't have an extension.
-  elif base_name_split[1] == '.' + oformat:
-    base_name = base_name_split[0]
-
-  # If the output name does have an extension and it does not match the output
-  # format, change the base_name so it doesn't have an extension and rename
-  # the output_file so it has the proper extension.
-  # Note that if you do something like name your build rule "foo.js" and pass
-  # "--oformat=html", emscripten will write to the same file for both the js and
-  # html output, overwriting the js output entirely with the html.
-  # Please don't do that.
-  else:
-    base_name = base_name_split[0]
-    os.rename(output_file, os.path.join(outdir, base_name + '.' + oformat))
-
-files = []
-extensions = [
-    '.js',
-    '.wasm',
-    '.wasm.map',
-    '.js.mem',
-    '.fetch.js',
-    '.worker.js',
-    '.data',
-    '.js.symbols',
-    '.wasm.debug.wasm',
-    '.html'
-]
-
-for ext in extensions:
-  filename = base_name + ext
-  if os.path.exists(os.path.join(outdir, filename)):
-    files.append(filename)
-
-wasm_base = os.path.join(outdir, base_name + '.wasm')
-if os.path.exists(wasm_base + '.debug.wasm') and os.path.exists(wasm_base):
-  # If we have a .wasm.debug.wasm file and a .wasm file, we need to rewrite the
-  # section in the .wasm file that refers to it. The path that's in there
-  # is the blaze output path; we want it to be just the filename.
-
-  llvm_objcopy = os.path.join(
-      os.environ['EMSCRIPTEN'], 'llvm-bin/llvm-objcopy')
-  # First, check to make sure the .wasm file has the header that needs to be
-  # rewritten.
-  rtn = subprocess.call([
-      llvm_objcopy,
-      '--dump-section=external_debug_info=/dev/null',
-      wasm_base], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-  if rtn == 0:
-    # If llvm-objcopy did not return an error, the external_debug_info section
-    # must exist, so we're good to continue.
-
-    # Next we need to convert length of the filename to LEB128.
-    # Start by converting the length of the filename to a bit string.
-    bit_string = '{0:b}'.format(len(base_name + '.wasm.debug.wasm'))
-
-    # Pad the bit string with 0s so that its length is a multiple of 7.
-    while len(bit_string) % 7 != 0:
-      bit_string = '0' + bit_string
-
-    # Break up our bit string into chunks of 7.
-    # We do this backwards because the final format is little-endian.
-    final_bytes = bytearray()
-    for i in reversed(range(0, len(bit_string), 7)):
-      binary_part = bit_string[i:i + 7]
-      if i != 0:
-        # Every chunk except the last one needs to be prepended with '1'.
-        # The length of each chunk is 7, so that one has an implicit '0'.
-        binary_part = '1' + binary_part
-      final_bytes.append(int(binary_part, 2))
-    # Finally, add the actual filename.
-    final_bytes.extend((base_name + '.wasm.debug.wasm').encode())
-
-    # Write our length + filename bytes to a temp file.
-    with open('debugsection.tmp', 'wb+') as f:
-      f.write(final_bytes)
-      f.close()
-
-    # First delete the old section.
-    subprocess.check_call([
-        llvm_objcopy,
-        wasm_base,
-        '--remove-section=external_debug_info'])
-    # Rewrite section with the new size and filename from the temp file.
-    subprocess.check_call([
-        llvm_objcopy,
-        wasm_base,
-        '--add-section=external_debug_info=debugsection.tmp'])
-
-# If we have more than one output file then create tarball
-if len(files) > 1:
-  cmd = ['tar', 'cf', 'tmp.tar'] + files
-  subprocess.check_call(cmd, cwd=outdir)
-  os.rename(os.path.join(outdir, 'tmp.tar'), output_file)
-elif len(files) == 1:
-  # Otherwise, if only have a single output than move it to the expected name
-  if files[0] != os.path.basename(output_file):
-    os.rename(os.path.join(outdir, files[0]), output_file)
-else:
-  print('emcc.py did not appear to output any known files!')
-  sys.exit(1)
-
-sys.exit(0)
diff --git a/emscripten_toolchain/wasm_binary.py b/emscripten_toolchain/wasm_binary.py
deleted file mode 100644
index 641c0d6..0000000
--- a/emscripten_toolchain/wasm_binary.py
+++ /dev/null
@@ -1,84 +0,0 @@
-"""Unpackages a bazel emscripten archive for use in a bazel BUILD rule.
-
-This script will take a tar archive containing the output of the emscripten
-toolchain. This file contains any output files produced by a wasm_cc_binary or a
-cc_binary built with --config=wasm. The files are extracted into the given
-output path.
-
-The name of archive is expected to be of the format `foo` or `foo.XXX` and
-the contents are expected to be foo.js and foo.wasm.
-
-Several optional files may also be in the archive, including but not limited to
-foo.js.mem, pthread-main.js, and foo.wasm.map.
-
-If the file is not a tar archive, the passed file will simply be copied to its
-destination.
-
-This script and its accompanying Bazel rule should allow you to extract a
-WebAssembly binary into a larger web application.
-"""
-
-import argparse
-import os
-import subprocess
-import sys
-
-
-def ensure(f):
-  if not os.path.exists(f):
-    with open(f, 'w'):
-      pass
-
-
-def check(f):
-  if not os.path.exists(f):
-    raise Exception('Expected file in archive: %s' % f)
-
-
-def main():
-  parser = argparse.ArgumentParser()
-  parser.add_argument('--archive', help='The archive to extract from.')
-  parser.add_argument('--output_path', help='The path to extract into.')
-  args = parser.parse_args()
-
-  basename = os.path.basename(args.archive)
-  stem = basename.split('.')[0]
-
-  # Check the type of the input file
-  mimetype_bytes = subprocess.check_output(['file', '-Lb', '--mime-type', '--mime-encoding', args.archive])
-  mimetype = mimetype_bytes.decode(sys.stdout.encoding)
-
-  # If we have a tar, extract all files. If we have just a single file, copy it.
-  if 'tar' in mimetype:
-    subprocess.check_call(
-        ['tar', 'xf', args.archive, '-C', args.output_path])
-  elif 'binary' in mimetype:
-    subprocess.check_call([
-        'cp',
-        args.archive,
-        os.path.join(args.output_path, stem + '.wasm')])
-  elif 'text' in mimetype:
-    subprocess.check_call([
-        'cp',
-        args.archive,
-        os.path.join(args.output_path, stem + '.js')])
-  else:
-    subprocess.check_call(['cp', args.archive, args.output_path])
-
-  # At least one of these two files should exist at this point.
-  ensure(os.path.join(args.output_path, stem + '.js'))
-  ensure(os.path.join(args.output_path, stem + '.wasm'))
-
-  # And can optionally contain these extra files.
-  ensure(os.path.join(args.output_path, stem + '.wasm.map'))
-  ensure(os.path.join(args.output_path, stem + '.worker.js'))
-  ensure(os.path.join(args.output_path, stem + '.js.mem'))
-  ensure(os.path.join(args.output_path, stem + '.data'))
-  ensure(os.path.join(args.output_path, stem + '.fetch.js'))
-  ensure(os.path.join(args.output_path, stem + '.js.symbols'))
-  ensure(os.path.join(args.output_path, stem + '.wasm.debug.wasm'))
-  ensure(os.path.join(args.output_path, stem + '.html'))
-
-
-if __name__ == '__main__':
-  main()
diff --git a/emscripten_toolchain/wasm_cc_binary.bzl b/emscripten_toolchain/wasm_cc_binary.bzl
deleted file mode 100644
index de758b0..0000000
--- a/emscripten_toolchain/wasm_cc_binary.bzl
+++ /dev/null
@@ -1,152 +0,0 @@
-"""wasm_cc_binary rule for compiling C++ targets to WebAssembly.
-"""
-
-def _wasm_transition_impl(settings, attr):
-    _ignore = (settings, attr)
-
-    features = list(settings["//command_line_option:features"])
-    linkopts = list(settings["//command_line_option:linkopt"])
-
-    if attr.threads == "emscripten":
-        # threads enabled
-        features.append("use_pthreads")
-    elif attr.threads == "off":
-        # threads disabled
-        features.append("-use_pthreads")
-
-    if attr.exit_runtime == True:
-        features.append("exit_runtime")
-
-    if attr.backend == "llvm":
-        features.append("llvm_backend")
-    elif attr.backend == "emscripten":
-        features.append("-llvm_backend")
-
-    if attr.simd:
-        features.append("wasm_simd")
-
-    return {
-        "//command_line_option:compiler": "emscripten",
-        "//command_line_option:crosstool_top": "//emscripten_toolchain:everything",
-        "//command_line_option:cpu": "wasm",
-        "//command_line_option:features": features,
-        "//command_line_option:dynamic_mode": "off",
-        "//command_line_option:linkopt": linkopts,
-#        "//command_line_option:platforms": [],
-        "//command_line_option:custom_malloc": "//emscripten_toolchain:malloc",
-    }
-
-_wasm_transition = transition(
-    implementation = _wasm_transition_impl,
-    inputs = [
-        "//command_line_option:features",
-        "//command_line_option:linkopt",
-    ],
-    outputs = [
-        "//command_line_option:compiler",
-        "//command_line_option:cpu",
-        "//command_line_option:crosstool_top",
-        "//command_line_option:features",
-        "//command_line_option:dynamic_mode",
-        "//command_line_option:linkopt",
-#        "//command_line_option:platforms",
-        "//command_line_option:custom_malloc",
-    ],
-)
-
-def _wasm_binary_impl(ctx):
-    cc_target = ctx.attr.cc_target[0]
-
-    args = [
-        "--output_path={}".format(ctx.outputs.loader.dirname),
-    ] + [
-        ctx.expand_location("--archive=$(location {})".format(
-            cc_target.label,
-        ), [cc_target]),
-    ]
-    outputs = [
-        ctx.outputs.loader,
-        ctx.outputs.wasm,
-        ctx.outputs.map,
-        ctx.outputs.mem,
-        ctx.outputs.fetch,
-        ctx.outputs.worker,
-        ctx.outputs.data,
-        ctx.outputs.symbols,
-        ctx.outputs.dwarf,
-        ctx.outputs.html,
-    ]
-
-    ctx.actions.run(
-        inputs = ctx.files.cc_target,
-        outputs = outputs,
-        arguments = args,
-        executable = ctx.executable._wasm_binary_extractor,
-    )
-
-    return DefaultInfo(
-        files = depset(outputs),
-        # This is needed since rules like web_test usually have a data
-        # dependency on this target.
-        data_runfiles = ctx.runfiles(transitive_files = depset(outputs)),
-    )
-
-def _wasm_binary_outputs(name, cc_target):
-    basename = cc_target.name
-    basename = basename.split(".")[0]
-    outputs = {
-        "loader": "{}/{}.js".format(name, basename),
-        "wasm": "{}/{}.wasm".format(name, basename),
-        "map": "{}/{}.wasm.map".format(name, basename),
-        "mem": "{}/{}.js.mem".format(name, basename),
-        "fetch": "{}/{}.fetch.js".format(name, basename),
-        "worker": "{}/{}.worker.js".format(name, basename),
-        "data": "{}/{}.data".format(name, basename),
-        "symbols": "{}/{}.js.symbols".format(name, basename),
-        "dwarf": "{}/{}.wasm.debug.wasm".format(name, basename),
-        "html": "{}/{}.html".format(name, basename),
-    }
-
-    return outputs
-
-# Wraps a C++ Blaze target, extracting the appropriate files.
-#
-# This rule will transition to the emscripten toolchain in order
-# to build the the cc_target as a WebAssembly binary.
-#
-# Args:
-#   name: The name of the rule.
-#   cc_target: The cc_binary or cc_library to extract files from.
-wasm_cc_binary = rule(
-    implementation = _wasm_binary_impl,
-    attrs = {
-        "backend": attr.string(
-            default = "_default",
-            values = ["_default", "emscripten", "llvm"],
-        ),
-        "cc_target": attr.label(
-            cfg = _wasm_transition,
-            mandatory = True,
-        ),
-        "exit_runtime": attr.bool(
-            default = False,
-        ),
-        "threads": attr.string(
-            default = "_default",
-            values = ["_default", "emscripten", "off"],
-        ),
-        "simd": attr.bool(
-            default = False,
-        ),
-        "_allowlist_function_transition": attr.label(
-            default = "@bazel_tools//tools/allowlists/function_transition_allowlist",
-        ),
-        "_wasm_binary_extractor": attr.label(
-            executable = True,
-            allow_files = True,
-            cfg = "exec",
-            default = Label("//emscripten_toolchain:wasm_binary"),
-        ),
-    },
-    outputs = _wasm_binary_outputs,
-)
diff --git a/emscripten_toolchain/wasm_rules.bzl b/emscripten_toolchain/wasm_rules.bzl
deleted file mode 100644
index 1c1c409..0000000
--- a/emscripten_toolchain/wasm_rules.bzl
+++ /dev/null
@@ -1,6 +0,0 @@
-"""Rules related to C++ and WebAssembly.
-"""
-
-load("//emscripten_toolchain:wasm_cc_binary.bzl", _wasm_cc_binary = "wasm_cc_binary")
-
-wasm_cc_binary = _wasm_cc_binary
diff --git a/libedgetpu b/libedgetpu
index 286f44b..999ad40 160000
--- a/libedgetpu
+++ b/libedgetpu
@@ -1 +1 @@
-Subproject commit 286f44b99c4473d81ace83d389a859ee70865530
+Subproject commit 999ad407bbaac56d53fc03a2c1d9c281cde970ef
diff --git a/tflite/BUILD b/tflite/BUILD
index 199ac67..a3525b9 100644
--- a/tflite/BUILD
+++ b/tflite/BUILD
@@ -1,4 +1,4 @@
-load("//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
+load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
 
 cc_binary(
     name = "interpreter",