Generating iree/builtins/device using our own clang.
This removes the checked in bitcode files and instead compiles them
from source as a normal part of building the compiler.

Ergonomic improvements are needed before scaling this out such as a
matrix rule for reducing the BUILD boilerplate. iree/builtins/musl will
need to move off of using make but iree/builtins/ukernel should be
easier to glob and use directly but has grown a bit too complex to
directly use this right now (arch/config rewriting goo).
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c8c966f..7c098db 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -431,6 +431,7 @@
 include(iree_tablegen_library)
 include(iree_tablegen_doc)
 include(iree_c_embed_data)
+include(iree_bitcode_library)
 include(iree_bytecode_module)
 include(iree_c_module)
 include(iree_python)
diff --git a/build_tools/bazel/iree_bitcode_library.bzl b/build_tools/bazel/iree_bitcode_library.bzl
new file mode 100644
index 0000000..a38fa45
--- /dev/null
+++ b/build_tools/bazel/iree_bitcode_library.bzl
@@ -0,0 +1,83 @@
+# Copyright 2023 The IREE Authors
+#
+# Licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+"""Rules for compiling with clang to produce bitcode libraries."""
+
+def iree_bitcode_library(
+        name,
+        srcs,
+        hdrs = [],
+        copts = [],
+        defines = [],
+        data = [],
+        out = None,
+        clang_tool = "@llvm-project//clang:clang",
+        link_tool = "@llvm-project//llvm:llvm-link",
+        builtin_headers_dep = "@llvm-project//clang:builtin_headers_gen",
+        builtin_headers_path = "external/llvm-project/clang/staging/include/",
+        **kwargs):
+    """Builds an LLVM bitcode library from an input file via clang.
+
+    Args:
+        name: Name of the target.
+        srcs: source files to pass to clang.
+        hdrs: additional headers included by the source files.
+        copts: additional flags to pass to clang.
+        defines: preprocessor definitions to pass to clang.
+        data: additional data required during compilation.
+        out: output file name (defaults to name.bc).
+        clang_tool: the clang to use to compile the source.
+        link_tool: llvm-link tool used for linking bitcode files.
+        builtin_headers_dep: clang builtin headers (stdbool, stdint, etc).
+        builtin_headers_path: relative path to the builtin headers rule.
+        **kwargs: any additional attributes to pass to the underlying rules.
+    """
+
+    bitcode_files = []
+    for bitcode_src in srcs:
+        bitcode_out = "%s_%s.bc" % (name, bitcode_src)
+        bitcode_files.append(bitcode_out)
+        native.genrule(
+            name = "gen_%s" % (bitcode_out),
+            srcs = [bitcode_src],
+            outs = [bitcode_out],
+            cmd = " && ".join([
+                " ".join([
+                    "$(location %s)" % (clang_tool),
+                    "-isystem $(BINDIR)/%s" % (builtin_headers_path),
+                    " ".join(copts),
+                    " ".join(["-D%s" % (define) for define in defines]),
+                    "-o $(location %s)" % (bitcode_out),
+                    "$(location %s)" % (bitcode_src),
+                ]),
+            ]),
+            tools = hdrs + data + [
+                clang_tool,
+                builtin_headers_dep,
+            ],
+            message = "Compiling %s to %s..." % (bitcode_src, bitcode_out),
+            output_to_bindir = 1,
+            **kwargs
+        )
+
+    if not out:
+        out = "%s.bc" % (name)
+    native.genrule(
+        name = name,
+        srcs = bitcode_files,
+        outs = [out],
+        cmd = " && ".join([
+            " ".join([
+                "$(location %s)" % (link_tool),
+                "-o $(location %s)" % (out),
+                " ".join(["$(locations %s)" % (src) for src in bitcode_files]),
+            ]),
+        ]),
+        tools = data + [link_tool],
+        message = "Linking bitcode library %s to %s..." % (name, out),
+        output_to_bindir = 1,
+        **kwargs
+    )
diff --git a/build_tools/bazel_to_cmake/bazel_to_cmake_converter.py b/build_tools/bazel_to_cmake/bazel_to_cmake_converter.py
index a5eddee..09b7511 100644
--- a/build_tools/bazel_to_cmake/bazel_to_cmake_converter.py
+++ b/build_tools/bazel_to_cmake/bazel_to_cmake_converter.py
@@ -443,6 +443,39 @@
                             f"{flatten_block}"
                             f"  PUBLIC\n)\n\n")
 
+  def iree_bitcode_library(self,
+                           name,
+                           srcs,
+                           hdrs=None,
+                           copts=None,
+                           defines=None,
+                           data=None,
+                           clang_tool=None,
+                           builtin_headers=None,
+                           testonly=None):
+    name_block = _convert_string_arg_block("NAME", name, quote=False)
+    srcs_block = _convert_srcs_block(srcs)
+    hdrs_block = _convert_string_list_block("HDRS", hdrs, sort=True)
+    copts_block = _convert_string_list_block("COPTS", copts, sort=False)
+    defines_block = _convert_string_list_block("DEFINES", defines)
+    data_block = _convert_target_list_block("DATA", data)
+    clang_tool_block = _convert_target_block("CLANG_TOOL", clang_tool)
+    builtin_headers_block = _convert_target_list_block("BUILTIN_HEADERS",
+                                                       builtin_headers)
+    testonly_block = _convert_option_block("TESTONLY", testonly)
+
+    self.converter.body += (f"iree_bitcode_library(\n"
+                            f"{name_block}"
+                            f"{srcs_block}"
+                            f"{hdrs_block}"
+                            f"{copts_block}"
+                            f"{defines_block}"
+                            f"{data_block}"
+                            f"{clang_tool_block}"
+                            f"{builtin_headers_block}"
+                            f"{testonly_block}"
+                            f"  PUBLIC\n)\n\n")
+
   def iree_bytecode_module(self,
                            name,
                            src,
diff --git a/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py b/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
index dd1f773..fd5884e 100644
--- a/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
+++ b/build_tools/bazel_to_cmake/bazel_to_cmake_targets.py
@@ -32,6 +32,9 @@
     "@llvm-project//llvm:X86AsmParser": ["IREELLVMCPUTargetDeps"],
     "@llvm-project//llvm:X86CodeGen": ["IREELLVMCPUTargetDeps"],
 
+    # Clang
+    "@llvm-project//clang": ["${IREE_CLANG_TARGET}"],
+
     # LLD
     "@llvm-project//lld": ["${IREE_LLD_TARGET}"],
     "@llvm-project//lld:COFF": ["lldCOFF"],
@@ -45,6 +48,8 @@
     "@llvm-project//llvm:IPO": ["LLVMipo"],
     "@llvm-project//llvm:FileCheck": ["FileCheck"],
     "@llvm-project//llvm:not": ["not"],
+    "@llvm-project//llvm:llvm-link": ["${IREE_LLVM_LINK_TARGET}"],
+
     # MLIR
     "@llvm-project//mlir:AllPassesAndDialects": ["MLIRAllDialects"],
     "@llvm-project//mlir:DialectUtils": [""],
@@ -60,6 +65,7 @@
     "@llvm-project//mlir:MlirTableGenMain": ["MLIRTableGen"],
     "@llvm-project//mlir:MlirOptLib": ["MLIROptLib"],
     "@llvm-project//mlir:VectorOps": ["MLIRVector"],
+
     # MHLO.
     # TODO: Rework this upstream so that Bazel and CMake rules match up
     # better.
diff --git a/build_tools/cmake/iree_bitcode_library.cmake b/build_tools/cmake/iree_bitcode_library.cmake
new file mode 100644
index 0000000..0f17151
--- /dev/null
+++ b/build_tools/cmake/iree_bitcode_library.cmake
@@ -0,0 +1,103 @@
+# Copyright 2023 The IREE Authors
+#
+# Licensed under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+include(CMakeParseArguments)
+
+# iree_bitcode_library()
+#
+# Builds an LLVM bitcode library from an input file via clang
+#
+# Parameters:
+# NAME: Name of target (see Note).
+# SRCS: Source files to pass to clang.
+# HDRS: Additional headers included by the source files.
+# COPTS: additional flags to pass to clang.
+# DEFINES: Preprocessor definitions to pass to clang.
+# DATA: Additional data required during compilation.
+# OUT: Output file name (defaults to NAME.bc).
+# PUBLIC: Add this so that this library will be exported under ${PACKAGE}::
+#     Also in IDE, target will appear in ${PACKAGE} folder while non PUBLIC
+#     will be in ${PACKAGE}/internal.
+# TESTONLY: When added, this target will only be built if IREE_BUILD_TESTS=ON.
+function(iree_bitcode_library)
+  cmake_parse_arguments(
+    _RULE
+    "PUBLIC;TESTONLY"
+    "NAME;OUT"
+    "SRCS;HDRS;COPTS;DEFINES;DATA"
+    ${ARGN}
+  )
+
+  set(_CLANG_TOOL "$<TARGET_FILE:${IREE_CLANG_TARGET}>")
+  set(_LINK_TOOL "$<TARGET_FILE:${IREE_LLVM_LINK_TARGET}>")
+
+  # These are copied as part of the clang build; we could allow the user to
+  # override this but it should be harmless.
+  set(_BUILTIN_HEADERS_PATH "${IREE_BINARY_DIR}/third_party/llvm-project/llvm/lib/clang/${CLANG_VERSION_MAJOR}/include/")
+
+  if(_RULE_TESTONLY AND NOT IREE_BUILD_TESTS)
+    return()
+  endif()
+
+  if(DEFINED _RULE_OUT)
+    set(_OUT "${_RULE_OUT}")
+  else()
+    set(_OUT "${_RULE_NAME}.bc")
+  endif()
+
+  set(_ARGS "-isystem ${_BUILTIN_HEADERS_PATH}")
+  list(APPEND _ARGS "${_RULE_COPTS}")
+  foreach(_DEFINE ${_RULE_DEFINES})
+    list(APPEND _ARGS "-D${_DEFINE}")
+  endforeach()
+
+  set(_BITCODE_FILES)
+  foreach(_BITCODE_SRC ${_RULE_SRCS})
+    get_filename_component(_BITCODE_SRC_PATH "${_BITCODE_SRC}" REALPATH)
+    set(_BITCODE_FILE "${_RULE_NAME}_${_BITCODE_SRC}.bc")
+    list(APPEND _BITCODE_FILES ${_BITCODE_FILE})
+    add_custom_command(
+      OUTPUT
+        ${_BITCODE_FILE}
+      COMMAND
+        ${_CLANG_TOOL}
+        ${_ARGS}
+        "${_BITCODE_SRC_PATH}"
+        "-o"
+        "${_BITCODE_FILE}"
+      DEPENDS
+        ${_CLANG_TOOL}
+        ${_BITCODE_SRC}
+      COMMENT
+        "Compiling ${_BITCODE_SRC} to ${_BITCODE_FILE}"
+      VERBATIM
+    )
+  endforeach()
+
+  add_custom_command(
+    OUTPUT
+      ${_OUT}
+    COMMAND
+      ${_LINK_TOOL}
+      ${_BITCODE_FILES}
+      "-o"
+      "${_OUT}"
+    DEPENDS
+      ${_LINK_TOOL}
+      ${_RULE_SRCS}
+      ${_BITCODE_FILES}
+    COMMENT
+      "Linking bitcode to ${_OUT}"
+    VERBATIM
+  )
+
+  # Only add iree_${NAME} as custom target doesn't support aliasing to
+  # iree::${NAME}.
+  iree_package_name(_PACKAGE_NAME)
+  add_custom_target("${_PACKAGE_NAME}_${_RULE_NAME}"
+    DEPENDS "${_OUT}"
+  )
+endfunction()
diff --git a/build_tools/cmake/iree_llvm.cmake b/build_tools/cmake/iree_llvm.cmake
index 8ee65ab..d810c52 100644
--- a/build_tools/cmake/iree_llvm.cmake
+++ b/build_tools/cmake/iree_llvm.cmake
@@ -126,6 +126,9 @@
   set(IREE_CLANG_TARGET)
   set(IREE_LLD_TARGET)
 
+  # Unconditionally enable some other cheap LLVM tooling.
+  set(IREE_LLVM_LINK_TARGET llvm-link)
+
   # Unconditionally enable mlir.
   list(APPEND LLVM_ENABLE_PROJECTS mlir)
 
diff --git a/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/Builtins/BUILD b/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/Builtins/BUILD
index 38705f6..af24511 100644
--- a/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/Builtins/BUILD
+++ b/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/Builtins/BUILD
@@ -23,7 +23,7 @@
         "Musl.h",
     ],
     deps = [
-        "//runtime/src/iree/builtins/device/bin:libdevice",
+        "//runtime/src/iree/builtins/device:libdevice_bitcode",
         "//runtime/src/iree/builtins/musl/bin:libmusl",
         "@llvm-project//llvm:BitReader",
         "@llvm-project//llvm:Core",
diff --git a/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/Builtins/CMakeLists.txt b/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/Builtins/CMakeLists.txt
index 91d7179..82a90fb 100644
--- a/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/Builtins/CMakeLists.txt
+++ b/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/Builtins/CMakeLists.txt
@@ -25,7 +25,7 @@
     LLVMSupport
     LLVMTarget
     MLIRSupport
-    iree::builtins::device::bin::libdevice
+    iree::builtins::device::libdevice_bitcode
     iree::builtins::musl::bin::libmusl
   PUBLIC
 )
diff --git a/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/Builtins/Device.cpp b/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/Builtins/Device.cpp
index d1a6f54..98366e1 100644
--- a/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/Builtins/Device.cpp
+++ b/compiler/src/iree/compiler/Dialect/HAL/Target/LLVM/Builtins/Device.cpp
@@ -6,7 +6,7 @@
 
 #include "iree/compiler/Dialect/HAL/Target/LLVM/Builtins/Device.h"
 
-#include "iree/builtins/device/bin/libdevice.h"
+#include "iree/builtins/device/libdevice_bitcode.h"
 #include "llvm/Bitcode/BitcodeReader.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/Support/MemoryBufferRef.h"
@@ -18,8 +18,8 @@
 namespace HAL {
 
 static const iree_file_toc_t *lookupDeviceFile(StringRef filename) {
-  for (size_t i = 0; i < iree_builtins_libdevice_size(); ++i) {
-    const auto &file_toc = iree_builtins_libdevice_create()[i];
+  for (size_t i = 0; i < iree_builtins_libdevice_bitcode_size(); ++i) {
+    const auto &file_toc = iree_builtins_libdevice_bitcode_create()[i];
     if (filename == file_toc.name) return &file_toc;
   }
   return nullptr;
@@ -81,6 +81,14 @@
   if (!bitcodeModuleValue) return bitcodeModuleValue;
   auto bitcodeModule = std::move(bitcodeModuleValue.get());
 
+  // Clang adds its own per-function attributes that we need to strip so that
+  // our current executable variant target is used instead.
+  for (auto &func : bitcodeModule->functions()) {
+    func.removeFnAttr("target-cpu");
+    func.removeFnAttr("tune-cpu");
+    func.removeFnAttr("target-features");
+  }
+
   // Inject target-specific flags.
   overridePlatformGlobal(*bitcodeModule, "libdevice_platform_example_flag", 0u);
 
diff --git a/runtime/src/iree/builtins/device/BUILD b/runtime/src/iree/builtins/device/BUILD
index 0aba13c..29e48e6 100644
--- a/runtime/src/iree/builtins/device/BUILD
+++ b/runtime/src/iree/builtins/device/BUILD
@@ -4,7 +4,9 @@
 # See https://llvm.org/LICENSE.txt for license information.
 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 
-load("//build_tools/bazel:build_defs.oss.bzl", "iree_runtime_cc_library")
+load("//build_tools/bazel:build_defs.oss.bzl", "iree_cmake_extra_content", "iree_runtime_cc_library")
+load("//build_tools/bazel:iree_bitcode_library.bzl", "iree_bitcode_library")
+load("//build_tools/embed_data:build_defs.bzl", "c_embed_data")
 
 package(
     default_visibility = ["//visibility:public"],
@@ -12,12 +14,90 @@
     licenses = ["notice"],  # Apache 2.0
 )
 
+#===------------------------------------------------------------------------===#
+# Common sources
+#===------------------------------------------------------------------------===#
+
+BITCODE_SRCS = [
+    "device_generic.c",
+]
+
+BITCODE_HDRS = [
+    "device.h",
+]
+
+#===------------------------------------------------------------------------===#
+# Application-integrated static library
+#===------------------------------------------------------------------------===#
+
 iree_runtime_cc_library(
     name = "device",
+    srcs = BITCODE_SRCS,
+    hdrs = BITCODE_HDRS,
+)
+
+#===------------------------------------------------------------------------===#
+# Compiler bitcode files
+#===------------------------------------------------------------------------===#
+
+iree_cmake_extra_content(
+    content = """
+if(NOT IREE_BUILD_COMPILER)
+  return()
+endif()
+""",
+    inline = True,
+)
+
+# TODO(benvanik): rule for building a matrix of bitcode files.
+# TODO(benvanik): make some of these flags inside of iree_bitcode_library; maybe
+# via an iree_cpu_bitcode_library so that we can have an
+# iree_cuda_bitcode_library that can differ.
+
+BITCODE_COPTS = [
+    # C17 with no system deps.
+    "-std=c17",
+    "-nostdinc",
+    "-ffreestanding",
+
+    # Optimized and unstamped.
+    "-O3",
+    "-fno-ident",
+    "-fdiscard-value-names",
+
+    # Object file only in bitcode format:
+    "-c",
+    "-emit-llvm",
+
+    # Force the library into standalone mode (not linking into hosting apps).
+    "-DIREE_DEVICE_STANDALONE=1",
+]
+
+iree_bitcode_library(
+    name = "libdevice_wasm32_generic",
+    srcs = BITCODE_SRCS,
+    hdrs = BITCODE_HDRS,
+    copts = BITCODE_COPTS + ["--target=wasm32"],
+)
+
+iree_bitcode_library(
+    name = "libdevice_wasm64_generic",
+    srcs = BITCODE_SRCS,
+    hdrs = BITCODE_HDRS,
+    copts = BITCODE_COPTS + ["--target=wasm64"],
+)
+
+c_embed_data(
+    name = "libdevice_bitcode",
     srcs = [
-        "device_generic.c",
+        ":libdevice_wasm32_generic.bc",
+        ":libdevice_wasm64_generic.bc",
     ],
-    hdrs = [
-        "device.h",
+    c_file_output = "libdevice_bitcode.c",
+    flatten = True,
+    h_file_output = "libdevice_bitcode.h",
+    identifier = "iree_builtins_libdevice_bitcode",
+    deps = [
+        "//runtime/src:runtime_defines",
     ],
 )
diff --git a/runtime/src/iree/builtins/device/CMakeLists.txt b/runtime/src/iree/builtins/device/CMakeLists.txt
index b16043e..ca2bd01 100644
--- a/runtime/src/iree/builtins/device/CMakeLists.txt
+++ b/runtime/src/iree/builtins/device/CMakeLists.txt
@@ -22,4 +22,68 @@
   PUBLIC
 )
 
+if(NOT IREE_BUILD_COMPILER)
+  return()
+endif()
+
+iree_bitcode_library(
+  NAME
+    libdevice_wasm32_generic
+  SRCS
+    "device_generic.c"
+  HDRS
+    "device.h"
+  COPTS
+    "-std=c17"
+    "-nostdinc"
+    "-ffreestanding"
+    "-O3"
+    "-fno-ident"
+    "-fdiscard-value-names"
+    "-c"
+    "-emit-llvm"
+    "-DIREE_DEVICE_STANDALONE=1"
+    "--target=wasm32"
+  PUBLIC
+)
+
+iree_bitcode_library(
+  NAME
+    libdevice_wasm64_generic
+  SRCS
+    "device_generic.c"
+  HDRS
+    "device.h"
+  COPTS
+    "-std=c17"
+    "-nostdinc"
+    "-ffreestanding"
+    "-O3"
+    "-fno-ident"
+    "-fdiscard-value-names"
+    "-c"
+    "-emit-llvm"
+    "-DIREE_DEVICE_STANDALONE=1"
+    "--target=wasm64"
+  PUBLIC
+)
+
+iree_c_embed_data(
+  NAME
+    libdevice_bitcode
+  GENERATED_SRCS
+    "libdevice_wasm32_generic.bc"
+    "libdevice_wasm64_generic.bc"
+  DEPS
+
+  C_FILE_OUTPUT
+    "libdevice_bitcode.c"
+  H_FILE_OUTPUT
+    "libdevice_bitcode.h"
+  IDENTIFIER
+    "iree_builtins_libdevice_bitcode"
+  FLATTEN
+  PUBLIC
+)
+
 ### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###
diff --git a/runtime/src/iree/builtins/device/bin/BUILD b/runtime/src/iree/builtins/device/bin/BUILD
deleted file mode 100644
index 286e32a..0000000
--- a/runtime/src/iree/builtins/device/bin/BUILD
+++ /dev/null
@@ -1,28 +0,0 @@
-# Copyright 2021 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-load("//build_tools/embed_data:build_defs.bzl", "c_embed_data")
-
-package(
-    default_visibility = ["//visibility:public"],
-    features = ["layering_check"],
-    licenses = ["notice"],  # Apache 2.0
-)
-
-c_embed_data(
-    name = "libdevice",
-    srcs = [
-        "libdevice_wasm32_generic.bc",
-        "libdevice_wasm64_generic.bc",
-    ],
-    c_file_output = "libdevice.c",
-    flatten = True,
-    h_file_output = "libdevice.h",
-    identifier = "iree_builtins_libdevice",
-    deps = [
-        "//runtime/src:runtime_defines",
-    ],
-)
diff --git a/runtime/src/iree/builtins/device/bin/CMakeLists.txt b/runtime/src/iree/builtins/device/bin/CMakeLists.txt
deleted file mode 100644
index 105bf87..0000000
--- a/runtime/src/iree/builtins/device/bin/CMakeLists.txt
+++ /dev/null
@@ -1,31 +0,0 @@
-################################################################################
-# Autogenerated by build_tools/bazel_to_cmake/bazel_to_cmake.py from           #
-# runtime/src/iree/builtins/device/bin/BUILD                                   #
-#                                                                              #
-# Use iree_cmake_extra_content from iree/build_defs.oss.bzl to add arbitrary   #
-# CMake-only content.                                                          #
-#                                                                              #
-# To disable autogeneration for this file entirely, delete this header.        #
-################################################################################
-
-iree_add_all_subdirs()
-
-iree_c_embed_data(
-  NAME
-    libdevice
-  SRCS
-    "libdevice_wasm32_generic.bc"
-    "libdevice_wasm64_generic.bc"
-  DEPS
-
-  C_FILE_OUTPUT
-    "libdevice.c"
-  H_FILE_OUTPUT
-    "libdevice.h"
-  IDENTIFIER
-    "iree_builtins_libdevice"
-  FLATTEN
-  PUBLIC
-)
-
-### BAZEL_TO_CMAKE_PRESERVES_ALL_CONTENT_BELOW_THIS_LINE ###
diff --git a/runtime/src/iree/builtins/device/bin/build.sh b/runtime/src/iree/builtins/device/bin/build.sh
deleted file mode 100644
index 28f2ca3..0000000
--- a/runtime/src/iree/builtins/device/bin/build.sh
+++ /dev/null
@@ -1,72 +0,0 @@
-# Copyright 2021 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-# Example command line:
-#   LLVM_AS=/usr/bin/llvm-as \
-#   CLANG=/usr/bin/clang-13 \
-#   ./iree/builtins/device/bin/build.sh
-#
-# Or use the defaults by building them from the IREE tree:
-#   cmake --build ../build/ --target clang --target llvm-as
-#   ./iree/builtins/device/bin/build.sh
-
-set -x
-set -e
-
-IREE_SRC_DIR="$(git rev-parse --show-toplevel)"
-IREE_BUILD_DIR="${IREE_BUILD_DIR:-${IREE_SRC_DIR?}/../build}"
-
-CLANG="${CLANG:-${IREE_BUILD_DIR}/llvm-project/bin/bin/clang}"
-# TODO(benvanik): figure out how to get this path from clang itself.
-CLANG_INCLUDE="${CLANG_INCLUDE:-${IREE_BUILD_DIR}/llvm-project/bin/lib/clang/17/include/}"
-LLVM_AS="${LLVM_AS:-${IREE_BUILD_DIR}/llvm-project/bin/bin/llvm-as}"
-
-SCRIPT_DIR="$(realpath `dirname $0`)"
-OUT="${SCRIPT_DIR?}/"
-SRC="${SCRIPT_DIR?}/.."
-
-function make_arch_bc {
-  local ARCH=$1
-  local FEATURES=$2
-  local SOURCE_FILE=$3
-  local FILE_BASENAME="${OUT}/libdevice_${ARCH}_${FEATURES}"
-
-  # Generate an LLVM IR assembly listing so we can easily read the file.
-  # This is not checked in or used by the compiler.
-  ${CLANG?} \
-      "${@:4}" \
-      -isystem "${CLANG_INCLUDE?}" \
-      -std=c17 \
-      -O3 \
-      -fno-ident \
-      -fvisibility=hidden \
-      -nostdinc \
-      -S \
-      -emit-llvm \
-      -fdiscard-value-names \
-      -DIREE_DEVICE_STANDALONE \
-      -o "${FILE_BASENAME}.ll" \
-      -c \
-      "${SRC}/${SOURCE_FILE}"
-
-  # Clang adds a bunch of bad attributes and host-specific information that we
-  # don't want (so we get at least somewhat deterministic builds).
-  sed -i 's/^;.*$//' "${FILE_BASENAME}.ll"
-  sed -i 's/^source_filename.*$//' "${FILE_BASENAME}.ll"
-  sed -i 's/^target datalayout.*$//' "${FILE_BASENAME}.ll"
-  sed -i 's/^target triple.*$//' "${FILE_BASENAME}.ll"
-  sed -i 's/^\(attributes #[0-9]* = {\).*$/\1 inlinehint }/' "${FILE_BASENAME}.ll"
-
-  # Generate a binary bitcode file embedded into the compiler binary.
-  # NOTE: we do this from stdin so that the filename on the user's system is not
-  # embedded in the bitcode file (making it non-deterministic).
-  cat "${FILE_BASENAME}.ll" | ${LLVM_AS} -opaque-pointers=0 -o="${FILE_BASENAME}.bc"
-}
-
-make_arch_bc "wasm32" "generic" "device_generic.c" \
-    --target=wasm32
-make_arch_bc "wasm64" "generic" "device_generic.c" \
-    --target=wasm64
diff --git a/runtime/src/iree/builtins/device/bin/libdevice_wasm32_generic.bc b/runtime/src/iree/builtins/device/bin/libdevice_wasm32_generic.bc
deleted file mode 100644
index 6503997..0000000
--- a/runtime/src/iree/builtins/device/bin/libdevice_wasm32_generic.bc
+++ /dev/null
Binary files differ
diff --git a/runtime/src/iree/builtins/device/bin/libdevice_wasm64_generic.bc b/runtime/src/iree/builtins/device/bin/libdevice_wasm64_generic.bc
deleted file mode 100644
index 6503997..0000000
--- a/runtime/src/iree/builtins/device/bin/libdevice_wasm64_generic.bc
+++ /dev/null
Binary files differ