Skip to content

Commit

Permalink
fix: allow for Bazel 7 flag rename (#1178)
Browse files Browse the repository at this point in the history
* fix: allow for Bazel 7 flag rename

fixes #1102

* chore: improve docs

* docs: ensure our WORKSPACE snippet mentions bazel_features init code

* fix: don't double-register bazel_features

* move bazel_features_deps where needed
  • Loading branch information
alexeagle committed Jul 27, 2023
1 parent eea8ec9 commit dbafe9e
Show file tree
Hide file tree
Showing 19 changed files with 60 additions and 35 deletions.
3 changes: 3 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ module(
compatibility_level = 1,
)

# Lower-bounds for runtime dependencies.
# Do not bump these unless rules_js requires a newer version to function.
bazel_dep(name = "aspect_bazel_lib", version = "1.31.2")
bazel_dep(name = "bazel_features", version = "0.1.0")
bazel_dep(name = "bazel_skylib", version = "1.4.1")
bazel_dep(name = "rules_nodejs", version = "5.8.2")
bazel_dep(name = "platforms", version = "0.0.4")
Expand Down
4 changes: 2 additions & 2 deletions docs/js_binary.md

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

4 changes: 4 additions & 0 deletions e2e/vendored_node/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ 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("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
Expand Down
4 changes: 4 additions & 0 deletions e2e/worker/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ nodejs_register_toolchains(
# nodejs 14 is used intentionally here, to assert AbortController polyfill is installed properly.
node_version = "14.20.0",
)

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

bazel_features_deps()
5 changes: 5 additions & 0 deletions e2e/workspace/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ nodejs_register_toolchains(
node_version = DEFAULT_NODE_VERSION,
)

# For convenience, npm_translate_lock does this call automatically.
# Uncomment if you don't call npm_translate_lock at all.
#load("@bazel_features//:deps.bzl", "bazel_features_deps")
#bazel_features_deps()

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

npm_translate_lock(
Expand Down
4 changes: 2 additions & 2 deletions js/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def js_binary(**kwargs):
"//conditions:default": False,
}),
unresolved_symlinks_enabled = select({
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}),
**kwargs
Expand All @@ -46,7 +46,7 @@ def js_test(**kwargs):
"//conditions:default": False,
}),
unresolved_symlinks_enabled = select({
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}),
**kwargs
Expand Down
5 changes: 3 additions & 2 deletions js/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@aspect_bazel_lib//lib:write_source_files.bzl", "write_source_files")
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@bazel_features//:features.bzl", "bazel_features")
load("//js:defs.bzl", "js_binary")

exports_files(
Expand All @@ -25,8 +26,8 @@ config_setting(
)

config_setting(
name = "experimental_allow_unresolved_symlinks",
values = {"experimental_allow_unresolved_symlinks": "true"},
name = "allow_unresolved_symlinks",
values = {bazel_features.flags.allow_unresolved_symlinks: "true"},
visibility = ["//visibility:public"],
)

Expand Down
4 changes: 3 additions & 1 deletion js/private/js_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,12 @@ _ATTRS = {
"unresolved_symlinks_enabled": attr.bool(
doc = """Whether unresolved symlinks are enabled in the current build configuration.
These are enabled with the --experimental_allow_unresolved_symlinks flag.
These are enabled with the `--allow_unresolved_symlinks` flag
(named `--experimental_allow_unresolved_symlinks in Bazel versions prior to 7.0).
Typical usage of this rule is via a macro which automatically sets this
attribute based on a `config_setting` rule.
See /js/private/BUILD.bazel in rules_js for an example.
""",
# TODO(2.0): make this mandatory so that downstream binary rules that inherit these attributes are required to set it
mandatory = False,
Expand Down
2 changes: 1 addition & 1 deletion js/private/js_run_devserver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def js_run_devserver(
"//conditions:default": False,
}),
unresolved_symlinks_enabled = select({
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}),
entry_point = "@aspect_rules_js//js/private:js_devserver_entrypoint",
Expand Down
4 changes: 2 additions & 2 deletions js/private/test/coverage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ coverage_fail_test(
}),
entry_point = "lib.js",
unresolved_symlinks_enabled = select({
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}),
)
Expand Down Expand Up @@ -61,7 +61,7 @@ coverage_pass_test(
}),
entry_point = "lib.js",
unresolved_symlinks_enabled = select({
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}),
)
2 changes: 1 addition & 1 deletion js/private/test/create_launcher/custom_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def custom_test(**kwargs):
"//conditions:default": False,
}),
unresolved_symlinks_enabled = select({
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}),
**kwargs
Expand Down
7 changes: 7 additions & 0 deletions js/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ def rules_js_dependencies():
strip_prefix = "bazel-lib-1.33.0",
url = "https://github.com/aspect-build/bazel-lib/releases/download/v1.33.0/bazel-lib-v1.33.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",
)
4 changes: 2 additions & 2 deletions npm/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
See https://bazel.build/docs/bzlmod#extension-definition
"""

load("//npm:repositories.bzl", "npm_import", "npm_translate_lock", "pnpm_repository", _LATEST_PNPM_VERSION = "LATEST_PNPM_VERSION")
load("//npm/private:npm_translate_lock.bzl", "npm_translate_lock_lib")
load("//npm:repositories.bzl", "npm_import", "pnpm_repository", _LATEST_PNPM_VERSION = "LATEST_PNPM_VERSION")
load("//npm/private:npm_translate_lock.bzl", "npm_translate_lock", "npm_translate_lock_lib")
load("//npm/private:npm_translate_lock_generate.bzl", npm_translate_lock_helpers = "helpers")
load("//npm/private:npm_translate_lock_macro_helpers.bzl", macro_helpers = "helpers")
load("//npm/private:npm_import.bzl", "npm_import_lib", "npm_import_links_lib")
Expand Down
12 changes: 6 additions & 6 deletions npm/private/npm_import.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def npm_imported_package_store(
dev = {dev},
tags = ["manual"],
use_declare_symlink = select({{
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}}),
)
Expand All @@ -84,7 +84,7 @@ def npm_imported_package_store(
deps = ref_deps,
tags = ["manual"],
use_declare_symlink = select({{
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}}),
)
Expand All @@ -100,7 +100,7 @@ def npm_imported_package_store(
visibility = visibility,
tags = ["manual"],
use_declare_symlink = select({{
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}}),
)
Expand All @@ -125,7 +125,7 @@ def npm_imported_package_store(
deps = ref_deps,
tags = ["manual"],
use_declare_symlink = select({{
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}}),
)
Expand All @@ -139,7 +139,7 @@ def npm_imported_package_store(
deps = lc_deps,
tags = ["manual"],
use_declare_symlink = select({{
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}}),
)
Expand Down Expand Up @@ -208,7 +208,7 @@ def npm_link_imported_package_store(
visibility = visibility,
tags = ["manual"],
use_declare_symlink = select({{
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}}),{maybe_bins}
)
Expand Down
4 changes: 2 additions & 2 deletions npm/private/npm_link_package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def npm_link_package(
visibility = visibility,
tags = tags,
use_declare_symlink = select({
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}),
**kwargs
Expand All @@ -97,7 +97,7 @@ def npm_link_package(
tags = tags,
visibility = visibility,
use_declare_symlink = select({
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}),
)
Expand Down
2 changes: 1 addition & 1 deletion npm/private/npm_link_package_store.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ If set, takes precendance over the package name in the src npm_package_store.
mandatory = True,
doc = """Whether unresolved symlinks are enabled in the current build configuration.
These are enabled with the --experimental_allow_unresolved_symlinks flag.
These are enabled with the --allow_unresolved_symlinks flag.
Typical usage of this rule is via a macro which automatically sets this
attribute based on a `config_setting` rule.
Expand Down
14 changes: 4 additions & 10 deletions npm/private/npm_package_store.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,12 @@ If set, takes precendance over the package version in the NpmPackageInfo src.
mandatory = True,
doc = """Whether to use ctx.actions.declare_symlink to create symlinks.
In Bazel 5.x these are enabled with the --experimental_allow_unresolved_symlinks flag.
These are enabled with the `--allow_unresolved_symlinks` flag
(named `--experimental_allow_unresolved_symlinks in Bazel versions prior to 7.0).
Typical usage of this rule is via a macro which automatically sets this
attribute with `select` based on a `config_setting` rule such as,
```
config_setting(
name = "experimental_allow_unresolved_symlinks",
values = {"experimental_allow_unresolved_symlinks": "true"},
visibility = ["//visibility:public"],
)
```
attribute with `select` based on a `config_setting` rule.
See /js/private/BUILD.bazel in rules_js for an example.
""",
),
"hardlink": attr.string(
Expand Down
4 changes: 2 additions & 2 deletions npm/private/npm_translate_lock_generate.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ _FP_STORE_TMPL = \
visibility = ["//visibility:public"],
tags = ["manual"],
use_declare_symlink = select({{
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}}),
)"""
Expand All @@ -55,7 +55,7 @@ _FP_DIRECT_TMPL = \
visibility = ["//visibility:public"],
tags = ["manual"],
use_declare_symlink = select({{
"@aspect_rules_js//js/private:experimental_allow_unresolved_symlinks": True,
"@aspect_rules_js//js/private:allow_unresolved_symlinks": True,
"//conditions:default": False,
}}),
)
Expand Down
7 changes: 6 additions & 1 deletion npm/repositories.bzl
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
"""Repository rules to fetch third-party npm packages"""

load("@bazel_features//:deps.bzl", "bazel_features_deps")
load("//npm/private:npm_import.bzl", _npm_import = "npm_import")
load("//npm/private:npm_translate_lock.bzl", _list_patches = "list_patches", _npm_translate_lock = "npm_translate_lock")
load("//npm/private:pnpm_repository.bzl", _LATEST_PNPM_VERSION = "LATEST_PNPM_VERSION", _pnpm_repository = "pnpm_repository")

npm_import = _npm_import
npm_translate_lock = _npm_translate_lock

def npm_translate_lock(**kwargs):
bazel_features_deps()
_npm_translate_lock(**kwargs)

pnpm_repository = _pnpm_repository
LATEST_PNPM_VERSION = _LATEST_PNPM_VERSION
list_patches = _list_patches

0 comments on commit dbafe9e

Please sign in to comment.