Skip to content

Commit

Permalink
feat: add bzlmod support
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Apr 21, 2024
1 parent a2a2b96 commit 5cbccc3
Show file tree
Hide file tree
Showing 28 changed files with 243 additions and 1,149 deletions.
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

# 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 .bazeliskrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BAZELISK_BASE_URL=https://github.com/aspect-build/aspect-cli/releases/download
USE_BAZEL_VERSION=aspect/5.7.2
USE_BAZEL_VERSION=aspect/5.9.25
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.1
9 changes: 8 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ jobs:
fail-fast: false
matrix:
bazelversion: ${{ fromJSON(needs.matrix-prep-bazelversion.outputs.bazelversions) }}
bzlmod: [1, 0]
folder:
- "."
- "e2e/workspace"
Expand Down Expand Up @@ -87,4 +88,10 @@ jobs:
# Bazelisk will download bazel to here, ensure it is cached between runs.
XDG_CACHE_HOME: ~/.cache/bazel-repo
working-directory: ${{ matrix.folder }}
run: bazel --bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc --bazelrc=.bazelrc test //...
run: |
bazel \
--bazelrc=$GITHUB_WORKSPACE/.github/workflows/ci.bazelrc \
--bazelrc=.bazelrc \
test \
--enable_bzlmod=${{ matrix.bzlmod }} \
//...
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ bazel-*
.idea/
.ijwb/
node_modules

# Don't commit lockfile for now as it is unstable. Do allow for it to be
# created, however, since it gives a performance boost for local development.
# https://github.com/bazelbuild/bazel/issues/19026
# https://github.com/bazelbuild/bazel/issues/19621
# https://github.com/bazelbuild/bazel/issues/19971
# https://github.com/bazelbuild/bazel/issues/20272
# https://github.com/bazelbuild/bazel/issues/20369
MODULE.bazel.lock
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ default_stages: [commit]
repos:
# Check formatting and lint for starlark code
- repo: https://github.com/keith/pre-commit-buildifier
rev: 4.0.1.1
rev: 6.4.0
hooks:
- id: buildifier
- id: buildifier-lint
# Enforce that commit messages allow for later changelog generation
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.18.0
rev: v3.24.0
hooks:
# Requires that commitizen is already installed
- id: commitizen
stages: [commit-msg]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v2.4.0"
rev: v3.1.0
hooks:
- id: prettier
13 changes: 10 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@buildifier_prebuilt//:rules.bzl", "buildifier")

buildifier(
name = "buildifier",
exclude_patterns = ["./.git/*"],
lint_mode = "fix",
mode = "fix",
tags = ["manual"], # tag as manual so windows ci does not build it by default
)

buildifier(
name = "buildifier.check",
exclude_patterns = [
"./.git/*",
],
exclude_patterns = ["./.git/*"],
lint_mode = "warn",
mode = "diff",
tags = ["manual"], # tag as manual so windows ci does not build it by default
)

bzl_library(
Expand Down
55 changes: 55 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"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 = "aspect_bazel_lib", version = "1.42.3")
bazel_dep(name = "aspect_rules_js", version = "1.41.2")
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "platforms", version = "0.0.5")
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")

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

bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")
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",
],
)
30 changes: 30 additions & 0 deletions WORKSPACE → WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ load("@aspect_rules_cypress//cypress:dependencies.bzl", "rules_cypress_dependenc
# Fetch dependencies which users need as well
rules_cypress_dependencies()

load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies")

rules_js_dependencies()

load("@bazel_features//:deps.bzl", "bazel_features_deps")

bazel_features_deps()

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

aspect_bazel_lib_dependencies(override_local_config_platform = True)
Expand All @@ -34,6 +42,28 @@ load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")

bazel_skylib_workspace()

############################################
# Stardoc
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

load("@io_bazel_stardoc//:deps.bzl", "stardoc_external_deps")

stardoc_external_deps()

load("@stardoc_maven//:defs.bzl", stardoc_pinned_maven_install = "pinned_maven_install")

stardoc_pinned_maven_install()

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

Expand Down
Empty file added WORKSPACE.bzlmod
Empty file.
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
12 changes: 6 additions & 6 deletions cypress/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ def rules_cypress_dependencies():

http_archive(
name = "aspect_bazel_lib",
sha256 = "e3151d87910f69cf1fc88755392d7c878034a69d6499b287bcfc00b1cf9bb415",
strip_prefix = "bazel-lib-1.32.1",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.32.1/bazel-lib-v1.32.1.tar.gz",
sha256 = "d0529773764ac61184eb3ad3c687fb835df5bee01afedf07f0cf1a45515c96bc",
strip_prefix = "bazel-lib-1.42.3",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.42.3/bazel-lib-v1.42.3.tar.gz",
)

http_archive(
name = "aspect_rules_js",
sha256 = "7cb2d84b7d5220194627c9a0267ae599e357350e75ea4f28f337a25ca6219b83",
strip_prefix = "rules_js-1.29.2",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.29.2/rules_js-v1.29.2.tar.gz",
sha256 = "bc9b4a01ef8eb050d8a7a050eedde8ffb1e45a56b0e4094e26f06c17d5fcf1d5",
strip_prefix = "rules_js-1.41.2",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.41.2/rules_js-v1.41.2.tar.gz",
)

http_archive(
Expand Down
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
Loading

0 comments on commit 5cbccc3

Please sign in to comment.