diff --git a/packages/bazel/BUILD.bazel b/packages/bazel/BUILD.bazel index 89ee85b4a46..95ec943ee01 100644 --- a/packages/bazel/BUILD.bazel +++ b/packages/bazel/BUILD.bazel @@ -8,6 +8,7 @@ pkg_npm( exclude = ["yarn.lock"], ) + [ "//packages/bazel/src:package_assets", + "//packages/bazel/src/ng_module:package_assets", "//packages/bazel/src/api-extractor:package_assets", "//packages/bazel/src/ng_package:package_assets", "//packages/bazel/src/ngc-wrapped:package_assets", @@ -15,6 +16,10 @@ pkg_npm( ], substitutions = { "(#|//)\\s+BEGIN-DEV-ONLY[\\w\\W]+?(#|//)\\s+END-DEV-ONLY": "", + # The partial compilation transition is applied in the user workspace. We do not want to require + # users having to define the build setting, so we directly point the flag label to the place where + # we expect `@angular/bazel` being located. Note: This expects the `@npm//` workspace to be used. + "//packages/bazel/src:partial_compilation": "@npm//@angular/bazel/src:partial_compilation", "//packages/bazel/": "//@angular/bazel/", "@npm//@bazel/typescript/internal:": "//@bazel/typescript/internal:", }, diff --git a/packages/bazel/src/BUILD.bazel b/packages/bazel/src/BUILD.bazel index e1498ab4dc9..6ebd35696e2 100644 --- a/packages/bazel/src/BUILD.bazel +++ b/packages/bazel/src/BUILD.bazel @@ -1,3 +1,4 @@ +load("//packages/bazel/src/ng_module:partial_compilation.bzl", "ng_partial_compilation_flag") # BEGIN-DEV-ONLY package(default_visibility = ["//packages/bazel:__subpackages__"]) @@ -7,3 +8,9 @@ filegroup( srcs = glob(["*"]), ) # END-DEV-ONLY + +ng_partial_compilation_flag( + name = "partial_compilation", + build_setting_default = False, + visibility = ["//visibility:public"], +) diff --git a/packages/bazel/src/ng_module/BUILD.bazel b/packages/bazel/src/ng_module/BUILD.bazel new file mode 100644 index 00000000000..ff253742bd6 --- /dev/null +++ b/packages/bazel/src/ng_module/BUILD.bazel @@ -0,0 +1,8 @@ +# BEGIN-DEV-ONLY +package(default_visibility = ["//packages/bazel:__subpackages__"]) + +filegroup( + name = "package_assets", + srcs = glob(["*"]), +) +# END-DEV-ONLY diff --git a/packages/bazel/src/ng_module/partial_compilation.bzl b/packages/bazel/src/ng_module/partial_compilation.bzl new file mode 100644 index 00000000000..15b79845482 --- /dev/null +++ b/packages/bazel/src/ng_module/partial_compilation.bzl @@ -0,0 +1,25 @@ +# Copyright Google LLC All Rights Reserved. +# +# Use of this source code is governed by an MIT-style license that can be +# found in the LICENSE file at https://angular.io/license + +NgPartialCompilationInfo = provider( + fields = {"enabled": "Whether partial compilation is enabled."}, +) + +def _ng_partial_compilation_flag_impl(ctx): + return NgPartialCompilationInfo(enabled = ctx.build_setting_value) + +ng_partial_compilation_flag = rule( + implementation = _ng_partial_compilation_flag_impl, + build_setting = config.bool(flag = True), +) + +def _partial_compilation_transition_impl(settings, attr): + return {"//packages/bazel/src:partial_compilation": True} + +partial_compilation_transition = transition( + implementation = _partial_compilation_transition_impl, + inputs = [], + outputs = ["//packages/bazel/src:partial_compilation"], +)