Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade to rules_js 2.0 #146

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions .aspect/bazelrc/ci.bazelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# We recommend enforcing a policy that keeps your CI from being slowed down
# by individual test targets that should be optimized
# or split up into multiple test targets with sharding or manually.
# Set this flag to exclude targets that have their timeout set to eternal (>15m) from running on CI.
# Docs: https://bazel.build/docs/user-manual#test-timeout-filters
test --test_timeout_filters=-eternal

# Set this flag to enable re-tries of failed tests on CI.
# When any test target fails, try one or more times. This applies regardless of whether the "flaky"
# tag appears on the target definition.
Expand Down
19 changes: 1 addition & 18 deletions .aspect/bazelrc/javascript.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,4 @@
# details.
# Docs: https://nodejs.org/en/docs/guides/debugging-getting-started/#command-line-options
run:debug -- --node_options=--inspect-brk

# Enable runfiles on all platforms. Runfiles are on by default on Linux and MacOS but off on
# Windows.
#
# In general, rules_js and derivate rule sets assume that runfiles are enabled and do not support no
# runfiles case because it does not scale to teach all Node.js tools to use the runfiles manifest.
#
# If you are developing on Windows, you must either run bazel with administrator privileges or
# enable developer mode. If you do not you may hit this error on Windows:
#
# Bazel needs to create symlinks to build the runfiles tree.
# Creating symlinks on Windows requires one of the following:
# 1. Bazel is run with administrator privileges.
# 2. The system version is Windows 10 Creators Update (1703) or later
# and developer mode is enabled.
#
# Docs: https://bazel.build/reference/command-line-reference#flag--enable_runfiles
build --enable_runfiles
test:debug --test_env=NODE_OPTIONS=--inspect-brk
9 changes: 0 additions & 9 deletions .aspect/bazelrc/performance.bazelrc
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
# Speed up all builds by not checking if output files have been modified. Lets you make changes to
# the output tree without triggering a build for local debugging. For example, you can modify
# [rules_js](https://github.com/aspect-build/rules_js) 3rd party npm packages in the output tree
# when local debugging.
# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/pkgcache/PackageOptions.java#L185
build --noexperimental_check_output_files
fetch --noexperimental_check_output_files
query --noexperimental_check_output_files

# Don't apply `--noremote_upload_local_results` and `--noremote_accept_cached` to the disk cache.
# If you have both `--noremote_upload_local_results` and `--disk_cache`, then this fixes a bug where
# Bazel doesn't write to the local disk cache as it treats as a remote cache.
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/bazel6.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ build --reuse_sandbox_directories
# Avoid this flag being enabled by remote_download_minimal or remote_download_toplevel
# See https://meroton.com/blog/bazel-6-errors-build-without-the-bytes/
build --noexperimental_action_cache_store_output_metadata

# Speed up all builds by not checking if output files have been modified. Lets you make changes to
# the output tree without triggering a build for local debugging. For example, you can modify
# [rules_js](https://github.com/aspect-build/rules_js) 3rd party npm packages in the output tree
# when local debugging.
# Docs: https://github.com/bazelbuild/bazel/blob/1af61b21df99edc2fc66939cdf14449c2661f873/src/main/java/com/google/devtools/build/lib/pkgcache/PackageOptions.java#L185
# NB: This flag is in bazel6.bazelrc as when used in Bazel 7 is has been observed to break
# "build without the bytes" --remote_download_outputs=toplevel. See https://github.com/aspect-build/bazel-lib/pull/711
# for more info.
build --noexperimental_check_output_files
fetch --noexperimental_check_output_files
query --noexperimental_check_output_files
4 changes: 0 additions & 4 deletions .github/workflows/bazel7.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,3 @@ query --noexperimental_check_external_repository_files
# build.
# Docs: https://bazel.build/reference/command-line-reference#flag--reuse_sandbox_directories
build --reuse_sandbox_directories

# Avoid this flag being enabled by remote_download_minimal or remote_download_toplevel
# See https://meroton.com/blog/bazel-6-errors-build-without-the-bytes/
build --noexperimental_action_cache_store_output_metadata
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
- uses: actions/checkout@v4

- name: Mount bazel caches
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cache/bazel-disk-cache
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4
- name: Mount bazel caches
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
"~/.cache/bazel"
Expand Down
7 changes: 3 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ module(
)

# Lower-bounds (minimum) versions for direct runtime dependencies
bazel_dep(name = "aspect_bazel_lib", version = "1.38.1")
bazel_dep(name = "aspect_rules_js", version = "1.34.0")
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "aspect_bazel_lib", version = "2.7.3")
bazel_dep(name = "aspect_rules_js", version = "2.0.0-rc0")
bazel_dep(name = "bazel_skylib", version = "1.5.0")

####### Dev dependencies ########

bazel_dep(name = "bazel_features", version = "0.1.0", dev_dependency = True)
bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.5.0", dev_dependency = True)
bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.36.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "rules_go", version = "0.46.0", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
15 changes: 3 additions & 12 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,11 @@ load("//webpack:dependencies.bzl", "rules_webpack_dependencies")

rules_webpack_dependencies()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies", "register_coreutils_toolchains")
load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")

aspect_bazel_lib_dependencies()
rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

register_coreutils_toolchains()

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
name = "nodejs",
node_version = DEFAULT_NODE_VERSION,
)

load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
Expand Down
9 changes: 3 additions & 6 deletions e2e/loaders/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ rules_webpack_dependencies()

# Fetch and register a nodejs interpreter, if you haven't already

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)
rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

# brought as a dep by webpack ruleset
load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
Expand Down
6 changes: 3 additions & 3 deletions e2e/smoke/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ local_path_override(
path = "../..",
)

bazel_dep(name = "aspect_bazel_lib", version = "1.32.0", dev_dependency = True)
bazel_dep(name = "aspect_rules_js", version = "1.33.1", dev_dependency = True)
bazel_dep(name = "bazel_skylib", version = "1.4.1", dev_dependency = True)
bazel_dep(name = "aspect_bazel_lib", version = "2.7.3", dev_dependency = True)
bazel_dep(name = "aspect_rules_js", version = "2.0.0-rc0", dev_dependency = True)
bazel_dep(name = "bazel_skylib", version = "1.5.0", dev_dependency = True)

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm", dev_dependency = True)
npm.npm_translate_lock(
Expand Down
9 changes: 3 additions & 6 deletions e2e/smoke/WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ rules_webpack_dependencies()

# Fetch and register a nodejs interpreter, if you haven't already

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)
rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")

npm_translate_lock(
name = "v4-npm",
Expand Down
9 changes: 3 additions & 6 deletions e2e/worker/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ rules_webpack_dependencies()

# Fetch and register a nodejs interpreter, if you haven't already

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")

nodejs_register_toolchains(
name = "node",
node_version = DEFAULT_NODE_VERSION,
)
rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

load("@aspect_rules_js//npm:npm_import.bzl", "npm_translate_lock")
load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")

npm_translate_lock(
name = "npm",
Expand Down
8 changes: 0 additions & 8 deletions internal_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ load("//webpack/private:maybe.bzl", http_archive = "maybe_http_archive")
def rules_webpack_internal_deps():
"Fetch repositories used for developing the rules"

# opt-in to 2.0 without forcing users to do so
http_archive(
name = "aspect_bazel_lib",
sha256 = "c858cc637db5370f6fd752478d1153955b4b4cbec7ffe95eb4a47a48499a79c3",
strip_prefix = "bazel-lib-2.0.3",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.0.3/bazel-lib-v2.0.3.tar.gz",
)

http_archive(
name = "io_bazel_rules_go",
sha256 = "80a98277ad1311dacd837f9b16db62887702e9f1d1c4c9f796d0121a46c8e184",
Expand Down
6 changes: 3 additions & 3 deletions webpack/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@aspect_bazel_lib//lib:utils.bzl", bazel_lib_utils = "utils")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("//webpack/private:is_bazel_7_or_greater.bzl", "is_bazel_7_or_greater")

exports_files(["defs.bzl"])

Expand All @@ -10,7 +10,7 @@ bzl_library(
deps = [
"//webpack/private:webpack_bundle",
"//webpack/private:webpack_devserver",
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if is_bazel_7_or_greater() else []),
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if bazel_lib_utils.is_bazel_7_or_greater() else []),
)

bzl_library(
Expand All @@ -20,5 +20,5 @@ bzl_library(
deps = [
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if is_bazel_7_or_greater() else []),
] + (["@bazel_tools//tools/build_defs/repo:cache.bzl"] if bazel_lib_utils.is_bazel_7_or_greater() else []),
)
21 changes: 11 additions & 10 deletions webpack/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,29 @@ load("//webpack/private:maybe.bzl", http_archive = "maybe_http_archive")
def rules_webpack_dependencies():
http_archive(
name = "bazel_skylib",
sha256 = "b8a1527901774180afc798aeb28c4634bdccf19c4d98e7bdd1ce79d1fe9aaad7",
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz"],
sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94",
urls = ["https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz"],
)

http_archive(
name = "aspect_bazel_lib",
sha256 = "262e3d6693cdc16dd43880785cdae13c64e6a3f63f75b1993c716295093d117f",
strip_prefix = "bazel-lib-1.38.1",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.38.1/bazel-lib-v1.38.1.tar.gz",
sha256 = "87ab4ec479ebeb00d286266aca2068caeef1bb0b1765e8f71c7b6cfee6af4226",
strip_prefix = "bazel-lib-2.7.3",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v2.7.3/bazel-lib-v2.7.3.tar.gz",
)

http_archive(
name = "aspect_rules_js",
sha256 = "d9ceb89e97bb5ad53b278148e01a77a3e9100db272ce4ebdcd59889d26b9076e",
strip_prefix = "rules_js-1.34.0",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.34.0/rules_js-v1.34.0.tar.gz",
sha256 = "389021e29b3aeed2f6fb3a7a1478f8fc52947a6500b198a7ec0f3358c2842415",
strip_prefix = "rules_js-2.0.0-rc0",
url = "https://github.com/aspect-build/rules_js/releases/download/v2.0.0-rc0/rules_js-v2.0.0-rc0.tar.gz",
)

http_archive(
name = "rules_nodejs",
sha256 = "764a3b3757bb8c3c6a02ba3344731a3d71e558220adcb0cf7e43c9bba2c37ba8",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/5.8.2/rules_nodejs-core-5.8.2.tar.gz"],
sha256 = "dddd60acc3f2f30359bef502c9d788f67e33814b0ddd99aa27c5a15eb7a41b8c",
strip_prefix = "rules_nodejs-6.1.0",
url = "https://github.com/bazelbuild/rules_nodejs/releases/download/v6.1.0/rules_nodejs-v6.1.0.tar.gz",
)

http_archive(
Expand Down
7 changes: 0 additions & 7 deletions webpack/private/is_bazel_7_or_greater.bzl

This file was deleted.

37 changes: 17 additions & 20 deletions webpack/private/webpack_bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,13 @@ def _impl(ctx):
inputs.extend(ctx.files.entry_points)
inputs = depset(
copy_files_to_bin_actions(ctx, inputs) + no_copy_bin_inputs,
transitive = [webpack_runfiles] + [js_lib_helpers.gather_files_from_js_providers(
transitive = [webpack_runfiles] + [js_lib_helpers.gather_files_from_js_infos(
targets = ctx.attr.srcs + ctx.attr.deps,
include_sources = True,
include_types = False,
include_transitive_sources = True,
# Upstream Type-check actions should not be triggered by bundling
include_declarations = False,
include_npm_linked_packages = True,
include_transitive_types = False,
include_npm_sources = True,
)],
)

Expand All @@ -184,14 +185,14 @@ def _impl(ctx):
env = env,
)

npm_linked_packages = js_lib_helpers.gather_npm_linked_packages(
# If a subset of linked npm dependencies are not bundled, it is up to the user to re-specify
# these in `data` if they are runtime dependencies to progagate to binary rules or `srcs` if
# they are to be propagated to downstream build targets.
npm_sources = js_lib_helpers.gather_npm_sources(
srcs = ctx.attr.srcs,
deps = [],
)

npm_package_store_deps = js_lib_helpers.gather_npm_package_store_deps(
# Since we're bundling, only propagate `data` npm packages to the direct dependencies of
# downstream linked `npm_package` targets instead of the common `data` and `deps` pattern.
npm_package_store_infos = js_lib_helpers.gather_npm_package_store_infos(
targets = ctx.attr.data,
)

Expand All @@ -207,19 +208,15 @@ def _impl(ctx):

return [
js_info(
npm_linked_package_files = npm_linked_packages.direct_files,
npm_linked_packages = npm_linked_packages.direct,
npm_package_store_deps = npm_package_store_deps,
target = ctx.label,
sources = output_sources_depset,
# Since we're bundling, we don't propagate linked npm packages from dependencies since
# they are bundled and the dependencies are dropped. If a subset of linked npm
# dependencies are not bundled it is up the the user to re-specify these in `data` if
# they are runtime dependencies to propagate to binary rules or `srcs` if they are to be
# propagated to downstream build targets.
transitive_npm_linked_package_files = npm_linked_packages.transitive_files,
transitive_npm_linked_packages = npm_linked_packages.transitive,
# Since we're bundling, we don't propagate any transitive output_sources from dependencies
types = depset(), # webpack does not emit types directly
# Since we're bundling, don't propogate any transitive sources or declarations since sources
# are typically bundled into the output.
transitive_sources = output_sources_depset,
transitive_types = depset(),
npm_sources = npm_sources,
npm_package_store_infos = npm_package_store_infos,
),
DefaultInfo(
files = output_sources_depset,
Expand Down