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

chore(deps): Migrate to bzl mod dependencies #61

Merged
merged 2 commits into from
Apr 11, 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
12 changes: 12 additions & 0 deletions .aspect/bazelrc/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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these caused by bzlmod using a newer version of aspect_bazel_lib then what we had declared in WORKSPACE? Now bzlmod takes the latest declared dep instead of the first declared...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, you nailed it

# 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
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
13 changes: 13 additions & 0 deletions .aspect/bazelrc/correctness.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,16 @@ query --experimental_allow_tags_propagation
# https://github.com/bazelbuild/bazel/issues/10076.
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_default_to_explicit_init_py
build --incompatible_default_to_explicit_init_py

# Set default value of `allow_empty` to `False` in `glob()`. This prevents a common mistake when
# attempting to use `glob()` to match files in a subdirectory that is opaque to the current package
# because it contains a BUILD file. See https://github.com/bazelbuild/bazel/issues/8195.
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_disallow_empty_glob
common --incompatible_disallow_empty_glob

# Always download coverage files for tests from the remote cache. By default, coverage files are not
# downloaded on test result cahce hits when --remote_download_minimal is enabled, making it impossible
# to generate a full coverage report.
# Docs: https://bazel.build/reference/command-line-reference#flag--experimental_fetch_all_coverage_outputs
# detching remote cache results
test --experimental_fetch_all_coverage_outputs
18 changes: 0 additions & 18 deletions .aspect/bazelrc/javascript.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,3 @@
# 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
18 changes: 0 additions & 18 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 All @@ -27,12 +18,3 @@ build --experimental_reuse_sandbox_directories
# author.
# Docs: https://bazel.build/reference/command-line-reference#flag--legacy_external_runfiles
build --nolegacy_external_runfiles

# Some actions are always IO-intensive but require little compute. It's wasteful to put the output
# in the remote cache, it just saturates the network and fills the cache storage causing earlier
# evictions. It's also not worth sending them for remote execution.
# For actions like PackageTar it's usually faster to just re-run the work locally every time.
# You'll have to look at an execution log to figure out what other action mnemonics you care about.
# In some cases you may need to patch rulesets to add a mnemonic to actions that don't have one.
# https://bazel.build/reference/command-line-reference#flag--modify_execution_info
build --modify_execution_info=PackageTar=+no-remote
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Import Aspect bazelrc presets
import %workspace%/.aspect/bazelrc/bazel6.bazelrc
import %workspace%/.aspect/bazelrc/bazel7.bazelrc
import %workspace%/.aspect/bazelrc/convenience.bazelrc
import %workspace%/.aspect/bazelrc/correctness.bazelrc
import %workspace%/.aspect/bazelrc/debug.bazelrc
Expand Down
8 changes: 1 addition & 7 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
6.3.2
# The first line of this file is used by Bazelisk and Bazel to be sure
# the right version of Bazel is used to build and test this repo.
# This also defines which version is used on CI.
#
# Note that you should also run integration_tests against other Bazel
# versions you support.
7.1.0
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ bazel-*
.idea/
.ijwb/
node_modules
MODULE.bazel.lock
e2e/workspace/MODULE.bazel.lock
14 changes: 6 additions & 8 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@buildifier_prebuilt//:rules.bzl", "buildifier")

buildifier(
Expand All @@ -10,12 +9,11 @@ buildifier(
mode = "diff",
)

bzl_library(
name = "internal_deps",
srcs = ["internal_deps.bzl"],
visibility = ["//visibility:public"],
deps = [
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",
buildifier(
name = "buildifier.fix",
exclude_patterns = [
"./.git/*",
],
lint_mode = "fix",
mode = "fix",
)
58 changes: 58 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"aspect-build/rules_cypress"

module(
name = "aspect_rules_cypress",
version = "0.0.0",
compatibility_level = 1,
)

cypress = use_extension("//cypress:extensions.bzl", "cypress")
cypress.toolchain(cypress_version = "12.3.0")
use_repo(cypress, "cypress_toolchains")

register_toolchains("@cypress_toolchains//:all")

bazel_dep(name = "platforms", version = "0.0.5")
bazel_dep(name = "aspect_rules_js", version = "1.38.0")
bazel_dep(name = "rules_nodejs", version = "5.8.2")

node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node")
node.toolchain(node_version = "16.14.2")
#################################

bazel_dep(name = "rules_go", version = "0.39.1", dev_dependency = True, repo_name = "io_bazel_rules_go")
bazel_dep(name = "gazelle", version = "0.31.0", dev_dependency = True, repo_name = "bazel_gazelle")
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")

bazel_dep(name = "aspect_bazel_lib", version = "2.5.3")
bazel_dep(name = "bazel_skylib", version = "1.5.0")

bazel_dep(
name = "buildifier_prebuilt",
version = "6.4.0",
dev_dependency = True,
)

http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# To update CHROME_REVISION, use the below script
#
# LASTCHANGE_URL="https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2FLAST_CHANGE?alt=media"
# CHROME_REVISION=$(curl -s -S $LASTCHANGE_URL)
# echo "latest CHROME_REVISION_LINUX is $CHROME_REVISION"
CHROME_REVISION_LINUX = "1072361"

http_archive(
name = "chrome_linux",
build_file_content = """filegroup(
name = "all",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)""",
dev_dependency = True,
sha256 = "0df22f743facd1e090eff9b7f8d8bdc293fb4dc31ce9156d2ef19b515974a72b",
strip_prefix = "chrome-linux",
urls = [
"https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux_x64%2F" + CHROME_REVISION_LINUX + "%2Fchrome-linux.zip?alt=media",
],
)
42 changes: 0 additions & 42 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,44 +1,2 @@
# Declare the local Bazel workspace.
workspace(name = "aspect_rules_cypress")

load(":internal_deps.bzl", "rules_cypress_internal_deps")

# Fetch deps needed only locally for development
rules_cypress_internal_deps()

load("@aspect_rules_cypress//cypress:dependencies.bzl", "rules_cypress_dependencies")

# Fetch dependencies which users need as well
rules_cypress_dependencies()

load("@aspect_bazel_lib//lib:repositories.bzl", "aspect_bazel_lib_dependencies")

aspect_bazel_lib_dependencies(override_local_config_platform = True)

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_cypress//cypress:repositories.bzl", "cypress_register_toolchains")

cypress_register_toolchains(
name = "cypress",
cypress_version = "12.3.0",
)

# For running our own unit tests
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

# Buildifier
load("@buildifier_prebuilt//:deps.bzl", "buildifier_prebuilt_deps")

buildifier_prebuilt_deps()

load("@buildifier_prebuilt//:defs.bzl", "buildifier_prebuilt_register_toolchains")

buildifier_prebuilt_register_toolchains()
10 changes: 0 additions & 10 deletions cypress/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ bzl_library(
],
)

bzl_library(
name = "dependencies",
srcs = ["dependencies.bzl"],
visibility = ["//visibility:public"],
deps = [
"@bazel_tools//tools/build_defs/repo:http.bzl",
"@bazel_tools//tools/build_defs/repo:utils.bzl",
],
)

bzl_library(
name = "toolchain",
srcs = ["toolchain.bzl"],
Expand Down
2 changes: 1 addition & 1 deletion cypress/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"Public API re-exports"

load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")
load("@aspect_rules_cypress//cypress/private:cypress_test.bzl", "cypress_test_lib")
load("@aspect_rules_js//js:libs.bzl", "js_binary_lib")
load("@aspect_bazel_lib//lib:directory_path.bzl", "directory_path")

_cypress_test = rule(
doc = """Identical to js_test with the addition of the cypress toolchain made available.""",
Expand Down
37 changes: 0 additions & 37 deletions cypress/dependencies.bzl

This file was deleted.

27 changes: 27 additions & 0 deletions cypress/extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"extensions for bzlmod"

load("@aspect_rules_cypress//cypress:repositories.bzl", "cypress_register_toolchains")

def _toolchain_extension(module_ctx):
for mod in module_ctx.modules:
for toolchain in mod.tags.toolchain:
cypress_register_toolchains(
name = toolchain.name,
cypress_version = toolchain.cypress_version,
register = False,
)

cypress = module_extension(
implementation = _toolchain_extension,
tag_classes = {
"toolchain": tag_class(attrs = {
"name": attr.string(
doc = "Base name for generated repositories",
default = "cypress",
),
"cypress_version": attr.string(
doc = "Version of cypress to download",
),
}),
},
)
8 changes: 6 additions & 2 deletions cypress/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ cypress_repositories = repository_rule(
)

# Wrapper macro around everything above, this is the primary API
def cypress_register_toolchains(name, cypress_version = None, cypress_integrity = None):
def cypress_register_toolchains(name, cypress_version = None, cypress_integrity = None, register = True):
"""
Convenience macro for setting up cypress toolchain for all supported platforms.

Expand All @@ -64,6 +64,9 @@ def cypress_register_toolchains(name, cypress_version = None, cypress_integrity
Alternatively, download a binary manually to compute its integrity hash, see https://docs.cypress.io/guides/references/advanced-installation#Download-URLs

Once downloaded, run `shasum -a 256` to get the integrity hash
register: Whether to call Bazel register_toolchains on the created toolchains.
Should be True when used from a WORKSPACE file, and False used from bzlmod
which has its own toolchain registration syntax.
"""
if not cypress_integrity:
if cypress_version not in TOOL_VERSIONS.keys():
Expand All @@ -81,7 +84,8 @@ Alternately, you may manually specify platform integrity hashes with cypress_int
platform = platform,
sha256 = cypress_integrity.get(platform, None),
)
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))
if register:
native.register_toolchains("@%s_toolchains//:%s_toolchain" % (name, platform))

toolchains_repo(
name = name + "_toolchains",
Expand Down
10 changes: 5 additions & 5 deletions docs/defs.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading