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(angular-ngc): migrate to bzlmod #376

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions angular-ngc/.aspect/bazelrc/bazel6.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,34 @@ 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/bazel-contrib/bazel-lib/pull/711
# for more info.
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.
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_remote_results_ignore_disk
# NB: This flag is in bazel6.bazelrc because it became a no-op in Bazel 7 and has been removed
# in Bazel 8.
build --incompatible_remote_results_ignore_disk

# Propagate tags from a target declaration to the actions' execution requirements.
# Ensures that tags applied in your BUILD file, like `tags=["no-remote"]`
# get propagated to actions created by the rule.
# Without this option, you rely on rules authors to manually check the tags you passed
# and apply relevant ones to the actions they create.
# See https://github.com/bazelbuild/bazel/issues/8830 for details.
# Docs: https://bazel.build/reference/command-line-reference#flag--experimental_allow_tags_propagation
build --experimental_allow_tags_propagation
fetch --experimental_allow_tags_propagation
query --experimental_allow_tags_propagation
2 changes: 1 addition & 1 deletion angular-ngc/.aspect/bazelrc/convenience.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
build --keep_going

# Output test errors to stderr so users don't have to `cat` or open test failure log files when test
# fail. This makes the log noiser in exchange for reducing the time-to-feedback on test failures for
# fail. This makes the log noisier in exchange for reducing the time-to-feedback on test failures for
# users.
# Docs: https://bazel.build/docs/user-manual#test-output
test --test_output=errors
Expand Down
26 changes: 14 additions & 12 deletions angular-ngc/.aspect/bazelrc/correctness.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test --test_verbose_timeout_warnings
# Allow the Bazel server to check directory sources for changes. Ensures that the Bazel server
# notices when a directory changes, if you have a directory listed in the srcs of some target.
# Recommended when using
# [copy_directory](https://github.com/aspect-build/bazel-lib/blob/main/docs/copy_directory.md) and
# [copy_directory](https://github.com/bazel-contrib/bazel-lib/blob/main/docs/copy_directory.md) and
# [rules_js](https://github.com/aspect-build/rules_js) since npm package are source directories
# inputs to copy_directory actions.
# Docs: https://bazel.build/reference/command-line-reference#flag--host_jvm_args
Expand All @@ -42,21 +42,23 @@ test --incompatible_exclusive_test_sandboxed
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_strict_action_env
build --incompatible_strict_action_env

# Propagate tags from a target declaration to the actions' execution requirements.
# Ensures that tags applied in your BUILD file, like `tags=["no-remote"]`
# get propagated to actions created by the rule.
# Without this option, you rely on rules authors to manually check the tags you passed
# and apply relevant ones to the actions they create.
# See https://github.com/bazelbuild/bazel/issues/8830 for details.
# Docs: https://bazel.build/reference/command-line-reference#flag--experimental_allow_tags_propagation
build --experimental_allow_tags_propagation
fetch --experimental_allow_tags_propagation
query --experimental_allow_tags_propagation

# Do not automatically create `__init__.py` files in the runfiles of Python targets. Fixes the wrong
# default that comes from Google's internal monorepo by using `__init__.py` to delimit a Python
# package. Precisely, when a `py_binary` or `py_test` target has `legacy_create_init` set to `auto (the
# default), it is treated as false if and only if this flag is set. See
# 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 cache 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
19 changes: 1 addition & 18 deletions angular-ngc/.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
35 changes: 12 additions & 23 deletions angular-ngc/.aspect/bazelrc/performance.bazelrc
Original file line number Diff line number Diff line change
@@ -1,18 +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.
# Docs: https://bazel.build/reference/command-line-reference#flag--incompatible_remote_results_ignore_disk
build --incompatible_remote_results_ignore_disk

# Directories used by sandboxed non-worker execution may be reused to avoid unnecessary setup costs.
# Save time on Sandbox creation and deletion when many of the same kind of action run during the
# build.
Expand All @@ -28,11 +13,15 @@ build --experimental_reuse_sandbox_directories
# 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
# Avoid creating a runfiles tree for binaries or tests until it is needed.
# Docs: https://bazel.build/reference/command-line-reference#flag--build_runfile_links
# See https://github.com/bazelbuild/bazel/issues/6627
#
# This may break local workflows that `build` a binary target, then run the resulting program
# outside of `bazel run`. In those cases, the script will need to call
# `bazel build --build_runfile_links //my/binary:target` and then execute the resulting program.
build --nobuild_runfile_links

# Needed prior to Bazel 8; see
# https://github.com/bazelbuild/bazel/issues/20577
coverage --build_runfile_links
100 changes: 100 additions & 0 deletions angular-ngc/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"Bazel module dependencies"

bazel_dep(name = "aspect_bazel_lib", version = "2.9.4")
bazel_dep(name = "aspect_rules_esbuild", version = "0.21.0")
bazel_dep(name = "aspect_rules_js", version = "2.1.0")
bazel_dep(name = "aspect_rules_ts", version = "3.3.1")
bazel_dep(name = "rules_nodejs", version = "6.3.2")

# Duplicates the definition in sass_workaround.bzl.
# Required because MODULE.bazel cannot load() symbols from other starlark code.
# TODO(alexeagle): find a better way
SASS_DEPS = ["@angular/cdk"] + [
"@material/" + p
for p in [
"animation",
"base",
"button",
"card",
"checkbox",
"chips",
"circular-progress",
"data-table",
"density",
"dialog",
"dom",
"elevation",
"fab",
"feature-targeting",
"floating-label",
"focus-ring",
"form-field",
"line-ripple",
"linear-progress",
"list",
"menu",
"menu-surface",
"notched-outline",
"icon-button",
"radio",
"ripple",
"rtl",
"select",
"shape",
"slider",
"snackbar",
"switch",
"tab",
"tab-bar",
"tab-indicator",
"tab-scroller",
"textfield",
"theme",
"tooltip",
"touch-target",
"tokens",
"typography",
]
]

pnpm = use_extension("@aspect_rules_js//npm:extensions.bzl", "pnpm")

node = use_extension("@rules_nodejs//nodejs:extensions.bzl", "node", dev_dependency = True)

npm = use_extension("@aspect_rules_js//npm:extensions.bzl", "npm")

ts = use_extension("@aspect_rules_ts//ts:extensions.bzl", "ext")

node.toolchain(node_version = "16.14.2")

npm.npm_translate_lock(
name = "npm",
bins = {
"@angular/compiler-cli": [
"ngcc=./bundles/ngcc/main-ngcc.js",
],
},
custom_postinstalls = {
# ngcc wants to write a lockfile in its own, so we must make that writeable.
# https://github.com/angular/angular/blob/15.2.10/packages/compiler-cli/ngcc/src/locking/lock_file.ts#L23
"@angular/compiler-cli": "chmod -R a+X .",
"ng2-dragula": "ngcc --source .",
},
npm_package_target_name = "{dirname}",
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
public_hoist_packages = {
p: ["packages/lib-a"]
for p in SASS_DEPS
},
verify_node_modules_ignored = "//:.bazelignore",
)

use_repo(pnpm, "pnpm")

use_repo(npm, "npm")

ts.deps(
ts_version_from = "@npm//:typescript/resolved.json",
)
use_repo(ts, "npm_typescript")
97 changes: 1 addition & 96 deletions angular-ngc/WORKSPACE.bazel
Original file line number Diff line number Diff line change
@@ -1,96 +1 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "aspect_rules_js",
sha256 = "7ab2fbe6d79fb3909ad2bf6dcacfae39adcb31c514efa239dd730b4f147c8097",
strip_prefix = "rules_js-1.32.1",
url = "https://github.com/aspect-build/rules_js/releases/download/v1.32.1/rules_js-v1.32.1.tar.gz",
)

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

rules_js_dependencies()

http_archive(
name = "aspect_rules_esbuild",
sha256 = "2ea31bd97181a315e048be693ddc2815fddda0f3a12ca7b7cc6e91e80f31bac7",
strip_prefix = "rules_esbuild-0.14.4",
url = "https://github.com/aspect-build/rules_esbuild/releases/download/v0.14.4/rules_esbuild-v0.14.4.tar.gz",
)

load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependencies")

rules_esbuild_dependencies()

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

aspect_bazel_lib_dependencies()

register_jq_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("//tools:sass_workaround.bzl", "SASS_DEPS")

npm_translate_lock(
name = "npm",
bins = {
"@angular/compiler-cli": {
"ngcc": "./bundles/ngcc/main-ngcc.js",
},
},
custom_postinstalls = {
"ng2-dragula": "ngcc --source .",
},
# Workaround https://github.com/sass/dart-sass/issues/1765
# See comments in sass_workaround.bzl
public_hoist_packages = {p: ["packages/lib-a"] for p in SASS_DEPS},
npmrc = "//:.npmrc",
pnpm_lock = "//:pnpm-lock.yaml",
verify_node_modules_ignored = "//:.bazelignore",
)

load("@aspect_rules_esbuild//esbuild:repositories.bzl", "esbuild_register_toolchains", LATEST_ESBUILD_VERSION = "LATEST_VERSION")

esbuild_register_toolchains(
name = "esbuild",
esbuild_version = LATEST_ESBUILD_VERSION,
)

http_archive(
name = "rules_proto",
sha256 = "dc3fb206a2cb3441b485eb1e423165b231235a1ea9b031b4433cf7bc1fa460dd",
strip_prefix = "rules_proto-5.3.0-21.7",
urls = [
"https://github.com/bazelbuild/rules_proto/archive/refs/tags/5.3.0-21.7.tar.gz",
],
)

v2_branch_head = "e5932f883443233f42b61d3fb87b2287518fbcba"
http_archive(
name = "aspect_rules_ts",
#sha256 = "ace5b609603d9b5b875d56c9c07182357c4ee495030f40dcefb10d443ba8c208",
# ts_proto_library branch
strip_prefix = "rules_ts-" + v2_branch_head,
url = "https://github.com/aspect-build/rules_ts/archive/{}.tar.gz".format(v2_branch_head),
)

load("@aspect_rules_ts//ts:repositories.bzl", "rules_ts_dependencies")

rules_ts_dependencies(ts_version_from = "//:package.json")

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

npm_repositories()

###########################################
# Protobuf rules to use ts_proto_library
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies")

rules_proto_dependencies()
# Workaround https://github.com/bazelbuild/bazel-watcher/pull/647
13 changes: 7 additions & 6 deletions angular-ngc/defs.bzl
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
"Macros to make BUILD files more ergonomic."

load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
load("@aspect_rules_esbuild//esbuild:defs.bzl", "esbuild")
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@npm//:history-server/package_json.bzl", history_server_bin = "bin")
load("@npm//:html-insert-assets/package_json.bzl", html_insert_assets_bin = "bin")
load("@npm//:karma/package_json.bzl", _karma_bin = "bin")
load("//tools:karma.bzl", "generate_karma_config", "generate_test_bootstrap", "generate_test_setup")
load("//tools:ng.bzl", "ng_esbuild", "ng_project")
load("//tools:ts.bzl", "ts_project")
load("//tools:karma.bzl", "generate_karma_config", "generate_test_bootstrap", "generate_test_setup")

# Common dependencies of Angular applications
APPLICATION_DEPS = [
Expand Down Expand Up @@ -60,7 +62,7 @@ NG_PROD_DEFINE = {
"ngJitMode": "false",
}

def ng_application(name, deps = [], test_deps = [], assets = None, html_assets = APPLICATION_HTML_ASSETS, visibility = ["//visibility:public"], **kwargs):
def ng_application(name, deps = [], test_deps = [], assets = None, html_assets = APPLICATION_HTML_ASSETS, visibility = ["//visibility:public"]):
"""
Bazel macro for compiling an Angular application. Creates {name}, test, serve targets.

Expand All @@ -83,7 +85,6 @@ def ng_application(name, deps = [], test_deps = [], assets = None, html_assets =
html_assets: assets to insert into the index.html, [styles.css, favicon.ico] by default
assets: assets to include in the file bundle
visibility: visibility of the primary targets ({name}, 'test', 'serve')
**kwargs: extra args passed to main Angular CLI rules
"""
assets = assets if assets else native.glob(["assets/**/*"])
html_assets = html_assets if html_assets else []
Expand Down Expand Up @@ -246,7 +247,7 @@ def ng_pkg(name, srcs, deps = [], test_deps = [], visibility = ["//visibility:pu
visibility: visibility of the primary targets ('{name}', 'test')
"""

test_spec_srcs = native.glob(["src/**/*.spec.ts"])
test_spec_srcs = native.glob(["src/**/*.spec.ts"], allow_empty = True)

# An index file to allow direct imports of the directory similar to a package.json "main"
write_file(
Expand Down
Loading
Loading