Mercurial
comparison third_party/emsdk/bazel/emscripten_deps.bzl @ 179:8d17f6e6e290
[ThirdParty] Added emsdk bazel rules that can be supported by bazel 9.0.0
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Thu, 22 Jan 2026 21:23:17 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 178:94705b5986b3 | 179:8d17f6e6e290 |
|---|---|
| 1 load(":remote_emscripten_repository.bzl", "remote_emscripten_repository") | |
| 2 load(":revisions.bzl", "EMSCRIPTEN_TAGS") | |
| 3 | |
| 4 def _parse_version(v): | |
| 5 return [int(u) for u in v.split(".")] | |
| 6 | |
| 7 def _empty_repository_impl(ctx): | |
| 8 ctx.file("MODULE.bazel", """module(name = "{}")""".format(ctx.name)) | |
| 9 ctx.file("BUILD.bazel", "") | |
| 10 | |
| 11 _empty_repository = repository_rule( | |
| 12 implementation = _empty_repository_impl, | |
| 13 ) | |
| 14 | |
| 15 def emscripten_repo_name(name): | |
| 16 return "emscripten_bin_{}".format(name) | |
| 17 | |
| 18 def _emscripten_deps_impl(ctx): | |
| 19 version = None | |
| 20 | |
| 21 for mod in ctx.modules: | |
| 22 for config in mod.tags.config: | |
| 23 if config.version and version != None: | |
| 24 fail("More than one emscripten version specified!") | |
| 25 version = config.version | |
| 26 if version == None: | |
| 27 version = "latest" | |
| 28 | |
| 29 if version == "latest": | |
| 30 version = reversed(sorted(EMSCRIPTEN_TAGS.keys(), key = _parse_version))[0] | |
| 31 | |
| 32 revision = EMSCRIPTEN_TAGS[version] | |
| 33 | |
| 34 emscripten_url = "https://storage.googleapis.com/webassembly/emscripten-releases-builds/{}/{}/wasm-binaries{}.{}" | |
| 35 | |
| 36 remote_emscripten_repository( | |
| 37 name = emscripten_repo_name("linux"), | |
| 38 bin_extension = "", | |
| 39 sha256 = revision.sha_linux, | |
| 40 strip_prefix = "install", | |
| 41 type = "tar.xz", | |
| 42 url = emscripten_url.format("linux", revision.hash, "", "tar.xz"), | |
| 43 ) | |
| 44 | |
| 45 # Not all versions have a linux/arm64 release: https://github.com/emscripten-core/emsdk/issues/547 | |
| 46 if hasattr(revision, "sha_linux_arm64"): | |
| 47 remote_emscripten_repository( | |
| 48 name = emscripten_repo_name("linux_arm64"), | |
| 49 bin_extension = "", | |
| 50 sha256 = revision.sha_linux_arm64, | |
| 51 strip_prefix = "install", | |
| 52 type = "tar.xz", | |
| 53 url = emscripten_url.format("linux", revision.hash, "-arm64", "tar.xz"), | |
| 54 ) | |
| 55 else: | |
| 56 _empty_repository( | |
| 57 name = emscripten_repo_name("linux_arm64"), | |
| 58 ) | |
| 59 | |
| 60 remote_emscripten_repository( | |
| 61 name = emscripten_repo_name("mac"), | |
| 62 bin_extension = "", | |
| 63 sha256 = revision.sha_mac, | |
| 64 strip_prefix = "install", | |
| 65 type = "tar.xz", | |
| 66 url = emscripten_url.format("mac", revision.hash, "", "tar.xz"), | |
| 67 ) | |
| 68 | |
| 69 remote_emscripten_repository( | |
| 70 name = emscripten_repo_name("mac_arm64"), | |
| 71 bin_extension = "", | |
| 72 sha256 = revision.sha_mac_arm64, | |
| 73 strip_prefix = "install", | |
| 74 type = "tar.xz", | |
| 75 url = emscripten_url.format("mac", revision.hash, "-arm64", "tar.xz"), | |
| 76 ) | |
| 77 | |
| 78 remote_emscripten_repository( | |
| 79 name = emscripten_repo_name("win"), | |
| 80 bin_extension = ".exe", | |
| 81 sha256 = revision.sha_win, | |
| 82 strip_prefix = "install", | |
| 83 type = "zip", | |
| 84 url = emscripten_url.format("win", revision.hash, "", "zip"), | |
| 85 ) | |
| 86 | |
| 87 emscripten_deps = module_extension( | |
| 88 tag_classes = { | |
| 89 "config": tag_class( | |
| 90 attrs = { | |
| 91 "version": attr.string( | |
| 92 doc = "Version to use. 'latest' to use latest.", | |
| 93 values = ["latest"] + EMSCRIPTEN_TAGS.keys(), | |
| 94 ), | |
| 95 }, | |
| 96 ), | |
| 97 }, | |
| 98 implementation = _emscripten_deps_impl, | |
| 99 ) |