Skip to content

Commit

Permalink
bazel: update rules_nodejs and migrate to rules_js (#1436)
Browse files Browse the repository at this point in the history
This finishes the work started in
#1388 by fixing CI. It
avoids a breaking change by:
* Using the latest rules_js 1.x.x version, instead of updating to
rules_js 2 (which removes support for bazel 5).
* Copying the contents of
[rules_js_dependencies](https://github.com/aspect-build/rules_js/blob/main/js/repositories.bzl)
instead of calling it, as the call would need to be added by users in
their `WORKSPACE` files

Context from the previous PR:

> Bazel's Node.js dependency comes from
[rules_nodejs](https://github.com/bazelbuild/rules_nodejs/). Previously,
bazel/deps.bzl was using rules_nodejs 5.8.0, released in 2022 and only
supported Node.js toolchains up to 18.12.1.

> This PR bumps rules_nodejs to latest 6.1.1. It also replaces
build_bazel_rules_nodejs with
[rules_js](https://github.com/aspect-build/rules_js), since npm_install
that bazel/emscripten_deps.bzl used was deprecated. The README of
rules_nodejs now recommends migrating to rules_js for everything other
than the Node.js toolchain:
(bazel-contrib/rules_nodejs@371e8ca)

> Impetus
Our repo builds with Bazel and uses Emscripten and Node.js. Tried to
upgrade Node.js 18 to Node.js 20 and saw that emsdk didn't support
rules_nodejs 6+ in the same workspace.

Similarly, it's not possible to update to rules_js v2 in a workspace
that also references `emsdk`.
  • Loading branch information
eric-higgins-ai authored Dec 5, 2024
1 parent 6abe512 commit c7d7853
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 23 deletions.
29 changes: 23 additions & 6 deletions bazel/deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,30 @@ def deps():
)
maybe(
http_archive,
name = "rules_nodejs",
sha256 = "08337d4fffc78f7fe648a93be12ea2fc4e8eb9795a4e6aa48595b66b34555626",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.0/rules_nodejs-core-5.8.0.tar.gz"],
name = "aspect_rules_js",
strip_prefix = "rules_js-1.42.0",
sha256 = "5a00869efaeb308245f8132a671fe86524bdfc4f8bfd1976d26f862b316dc3c9",
urls = ["https://github.com/aspect-build/rules_js/releases/download/v1.42.0/rules_js-v1.42.0.tar.gz"],
)
# Transitive dependencies of aspect_rules_js. We explicitly pull them here instead of calling their
# provided function to avoid requiring a call to rules_js_dependencies in WORKSPACE.
maybe(
http_archive,
name = "aspect_bazel_lib",
sha256 = "714cf8ce95a198bab0a6a3adaffea99e929d2f01bf6d4a59a2e6d6af72b4818c",
strip_prefix = "bazel-lib-2.7.8",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.7.8/bazel-lib-v2.7.8.tar.gz",
)
maybe(
http_archive,
name = "build_bazel_rules_nodejs",
sha256 = "dcc55f810142b6cf46a44d0180a5a7fb923c04a5061e2e8d8eb05ccccc60864b",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.0/rules_nodejs-5.8.0.tar.gz"],
name = "rules_nodejs",
strip_prefix = "rules_nodejs-6.2.0",
sha256 = "87c6171c5be7b69538d4695d9ded29ae2626c5ed76a9adeedce37b63c73bef67",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/v6.2.0/rules_nodejs-v6.2.0.tar.gz"],
)
http_archive(
name = "bazel_features",
sha256 = "f3082bfcdca73dc77dcd68faace806135a2e08c230b02b1d9fbdbd7db9d9c450",
strip_prefix = "bazel_features-0.1.0",
url = "https://github.com/bazel-contrib/bazel_features/releases/download/v0.1.0/bazel_features-v0.1.0.tar.gz",
)
35 changes: 18 additions & 17 deletions bazel/emscripten_deps.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "npm_install")
load("@rules_nodejs//nodejs:repositories.bzl", "nodejs_register_toolchains")
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")
load(":revisions.bzl", "EMSCRIPTEN_TAGS")

def _parse_version(v):
Expand Down Expand Up @@ -118,7 +119,7 @@ def emscripten_deps(emscripten_version = "latest"):
excludes = native.existing_rules().keys()
if "nodejs_toolchains" not in excludes:
# Node 16 is the first version that supports darwin_arm64
node_repositories(
nodejs_register_toolchains(
node_version = "16.6.2",
)

Expand Down Expand Up @@ -174,36 +175,36 @@ def emscripten_deps(emscripten_version = "latest"):
)

if "emscripten_npm_linux" not in excludes:
npm_install(
npm_translate_lock(
name = "emscripten_npm_linux",
package_json = "@emscripten_bin_linux//:emscripten/package.json",
package_lock_json = "@emscripten_bin_linux//:emscripten/package-lock.json",
data = ["@emscripten_bin_linux//:emscripten/package.json"],
npm_package_lock = "@emscripten_bin_linux//:emscripten/package-lock.json",
)

if "emscripten_npm_linux_arm64" not in excludes:
npm_install(
npm_translate_lock(
name = "emscripten_npm_linux_arm64",
package_json = "@emscripten_bin_linux_arm64//:emscripten/package.json",
package_lock_json = "@emscripten_bin_linux_arm64//:emscripten/package-lock.json",
data = ["@emscripten_bin_linux_arm64//:emscripten/package.json"],
npm_package_lock = "@emscripten_bin_linux_arm64//:emscripten/package-lock.json",
)

if "emscripten_npm_mac" not in excludes:
npm_install(
npm_translate_lock(
name = "emscripten_npm_mac",
package_json = "@emscripten_bin_mac//:emscripten/package.json",
package_lock_json = "@emscripten_bin_mac//:emscripten/package-lock.json",
data = ["@emscripten_bin_mac//:emscripten/package.json"],
npm_package_lock = "@emscripten_bin_mac//:emscripten/package-lock.json",
)

if "emscripten_npm_mac_arm64" not in excludes:
npm_install(
npm_translate_lock(
name = "emscripten_npm_mac",
package_json = "@emscripten_bin_mac_arm64//:emscripten/package.json",
package_lock_json = "@emscripten_bin_mac_arm64//:emscripten/package-lock.json",
data = ["@emscripten_bin_mac_arm64//:emscripten/package.json"],
npm_package_lock = "@emscripten_bin_mac_arm64//:emscripten/package-lock.json",
)

if "emscripten_npm_win" not in excludes:
npm_install(
npm_translate_lock(
name = "emscripten_npm_win",
package_json = "@emscripten_bin_win//:emscripten/package.json",
package_lock_json = "@emscripten_bin_win//:emscripten/package-lock.json",
data = ["@emscripten_bin_win//:emscripten/package.json"],
npm_package_lock = "@emscripten_bin_win//:emscripten/package-lock.json",
)

0 comments on commit c7d7853

Please sign in to comment.