* Optimize sandbox performance Link just the files needed to compile, link, or archive, rather than the entire directory tree. This drastically improves build times on macOS, where the sandbox is known to be slow (https://github.com/bazelbuild/bazel/issues/8230). * Linux wants clang to link * all_files not needed? * Linux wants llc * And llvm-ar * Templated build_file_content
147 lines
4.9 KiB
Python
147 lines
4.9 KiB
Python
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
|
|
load("@build_bazel_rules_nodejs//:index.bzl", "npm_install", "node_repositories")
|
|
load(":revisions.bzl", "EMSCRIPTEN_TAGS")
|
|
|
|
def _parse_version(v):
|
|
return [int(u) for u in v.split(".")]
|
|
|
|
BUILD_FILE_CONTENT_TEMPLATE = """
|
|
package(default_visibility = ['//visibility:public'])
|
|
|
|
filegroup(
|
|
name = "includes",
|
|
srcs = glob([
|
|
"emscripten/cache/sysroot/include/c++/v1/**",
|
|
"emscripten/cache/sysroot/include/compat/**",
|
|
"emscripten/cache/sysroot/include/**",
|
|
"lib/clang/15.0.0/include/**",
|
|
]),
|
|
)
|
|
|
|
filegroup(
|
|
name = "compiler_files",
|
|
srcs = [
|
|
"emscripten/emcc.py",
|
|
"bin/clang{bin_extension}",
|
|
"bin/clang++{bin_extension}",
|
|
":includes",
|
|
],
|
|
)
|
|
|
|
filegroup(
|
|
name = "linker_files",
|
|
srcs = [
|
|
"emscripten/emcc.py",
|
|
"bin/clang{bin_extension}",
|
|
"bin/llc{bin_extension}",
|
|
"bin/llvm-ar{bin_extension}",
|
|
"bin/llvm-nm{bin_extension}",
|
|
"bin/llvm-objcopy{bin_extension}",
|
|
"bin/wasm-emscripten-finalize{bin_extension}",
|
|
"bin/wasm-ld{bin_extension}",
|
|
"bin/wasm-opt{bin_extension}",
|
|
],
|
|
)
|
|
|
|
filegroup(
|
|
name = "ar_files",
|
|
srcs = [
|
|
"emscripten/emar.py",
|
|
"bin/llvm-ar{bin_extension}",
|
|
],
|
|
)
|
|
"""
|
|
|
|
def emscripten_deps(emscripten_version = "latest"):
|
|
version = emscripten_version
|
|
|
|
if version == "latest":
|
|
version = reversed(sorted(EMSCRIPTEN_TAGS.keys(), key = _parse_version))[0]
|
|
|
|
if version not in EMSCRIPTEN_TAGS.keys():
|
|
error_msg = "Emscripten version {} not found.".format(version)
|
|
error_msg += " Look at @emsdk//:revisions.bzl for the list "
|
|
error_msg += "of currently supported versions."
|
|
fail(error_msg)
|
|
|
|
revision = EMSCRIPTEN_TAGS[version]
|
|
|
|
emscripten_url = "https://storage.googleapis.com/webassembly/emscripten-releases-builds/{}/{}/wasm-binaries{}.{}"
|
|
|
|
# This could potentially backfire for projects with multiple emscripten
|
|
# dependencies that use different emscripten versions
|
|
excludes = native.existing_rules().keys()
|
|
if "nodejs_toolchains" not in excludes:
|
|
# Node 16 is the first version that supports darwin_arm64
|
|
node_repositories(
|
|
node_version = "16.6.2",
|
|
)
|
|
|
|
if "emscripten_bin_linux" not in excludes:
|
|
http_archive(
|
|
name = "emscripten_bin_linux",
|
|
strip_prefix = "install",
|
|
url = emscripten_url.format("linux", revision.hash, "", "tbz2"),
|
|
sha256 = revision.sha_linux,
|
|
build_file_content = BUILD_FILE_CONTENT_TEMPLATE.format(bin_extension=""),
|
|
type = "tar.bz2",
|
|
)
|
|
|
|
if "emscripten_bin_mac" not in excludes:
|
|
http_archive(
|
|
name = "emscripten_bin_mac",
|
|
strip_prefix = "install",
|
|
url = emscripten_url.format("mac", revision.hash, "", "tbz2"),
|
|
sha256 = revision.sha_mac,
|
|
build_file_content = BUILD_FILE_CONTENT_TEMPLATE.format(bin_extension=""),
|
|
type = "tar.bz2",
|
|
)
|
|
|
|
if "emscripten_bin_mac_arm64" not in excludes:
|
|
http_archive(
|
|
name = "emscripten_bin_mac_arm64",
|
|
strip_prefix = "install",
|
|
url = emscripten_url.format("mac", revision.hash, "-arm64", "tbz2"),
|
|
sha256 = revision.sha_mac_arm64,
|
|
build_file_content = BUILD_FILE_CONTENT_TEMPLATE.format(bin_extension=""),
|
|
type = "tar.bz2",
|
|
)
|
|
|
|
if "emscripten_bin_win" not in excludes:
|
|
http_archive(
|
|
name = "emscripten_bin_win",
|
|
strip_prefix = "install",
|
|
url = emscripten_url.format("win", revision.hash, "", "zip"),
|
|
sha256 = revision.sha_win,
|
|
build_file_content = BUILD_FILE_CONTENT_TEMPLATE.format(bin_extension=".exe"),
|
|
type = "zip",
|
|
)
|
|
|
|
if "emscripten_npm_linux" not in excludes:
|
|
npm_install(
|
|
name = "emscripten_npm_linux",
|
|
package_json = "@emscripten_bin_linux//:emscripten/package.json",
|
|
package_lock_json = "@emscripten_bin_linux//:emscripten/package-lock.json",
|
|
)
|
|
|
|
if "emscripten_npm_mac" not in excludes:
|
|
npm_install(
|
|
name = "emscripten_npm_mac",
|
|
package_json = "@emscripten_bin_mac//:emscripten/package.json",
|
|
package_lock_json = "@emscripten_bin_mac//:emscripten/package-lock.json",
|
|
)
|
|
|
|
if "emscripten_npm_mac_arm64" not in excludes:
|
|
npm_install(
|
|
name = "emscripten_npm_mac",
|
|
package_json = "@emscripten_bin_mac_arm64//:emscripten/package.json",
|
|
package_lock_json = "@emscripten_bin_mac_arm64//:emscripten/package-lock.json",
|
|
)
|
|
|
|
if "emscripten_npm_win" not in excludes:
|
|
npm_install(
|
|
name = "emscripten_npm_win",
|
|
package_json = "@emscripten_bin_win//:emscripten/package.json",
|
|
package_lock_json = "@emscripten_bin_win//:emscripten/package-lock.json",
|
|
)
|