build(ivy): support alternate compilation modes to enable Ivy testing (#24056)
Bazel has a restriction that a single output (eg. a compiled version of //packages/common) can only be produced by a single rule. This precludes the Angular repo from having multiple rules that build the same code. And the complexity of having a single rule produce multiple outputs (eg. an ngc-compiled version of //packages/common and an Ivy-enabled version) is too high. Additionally, the Angular repo has lots of existing tests which could be executed as-is under Ivy. Such testing is very valuable, and it would be nice to share not only the code, but the dependency graph / build config as well. Thus, this change introduces a --define flag 'compile' with three potential values. When --define=compile=X is set, the entire build system runs in a particular mode - the behavior of all existing targets is controlled by the flag. This allows us to reuse our entire build structure for testing in a variety of different manners. The flag has three possible settings: * legacy (the default): the traditional View Engine (ngc) build * local: runs the prototype ngtsc compiler, which does not rely on global analysis * jit: runs ngtsc in a mode which executes tsickle, but excludes the Angular related transforms, which approximates the behavior of plain tsc. This allows the main packages such as common to be tested with the JIT compiler. Additionally, the ivy_ng_module() rule still exists and runs ngc in a mode where Ivy-compiled output is produced from global analysis information, as a stopgap while ngtsc is being developed. PR Close #24056
This commit is contained in:

committed by
Matias Niemelä

parent
00c4751f37
commit
1eafd04eb3
@ -57,6 +57,6 @@ test --experimental_ui
|
||||
################################
|
||||
# Temporary Settings for Ivy #
|
||||
################################
|
||||
# to determine if the compiler used should be Ivy or ViewEngine one can use `--define=ivy=true` on
|
||||
# any bazel target. This is a temporary flag until codebase is permanently switched to ViewEngine.
|
||||
build --define=ivy=false
|
||||
# to determine if the compiler used should be Ivy or ViewEngine one can use `--define=compile=local` on
|
||||
# any bazel target. This is a temporary flag until codebase is permanently switched to Ivy.
|
||||
build --define=compile=legacy
|
@ -2,7 +2,7 @@
|
||||
load("@build_bazel_rules_nodejs//:defs.bzl", _npm_package = "npm_package")
|
||||
load("@build_bazel_rules_typescript//:defs.bzl", _ts_library = "ts_library", _ts_web_test_suite = "ts_web_test_suite")
|
||||
load("//packages/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "ng_package")
|
||||
load("//packages/bazel/src:ng_module.bzl", _ivy_ng_module = "internal_ivy_ng_module")
|
||||
load("//packages/bazel/src:ng_module.bzl", _internal_global_ng_module = "internal_global_ng_module")
|
||||
|
||||
DEFAULT_TSCONFIG = "//packages:tsconfig-build.json"
|
||||
|
||||
@ -49,6 +49,16 @@ def ng_module(name, tsconfig = None, entry_point = None, **kwargs):
|
||||
entry_point = "public_api.ts"
|
||||
_ng_module(name = name, flat_module_out_file = name, tsconfig = tsconfig, entry_point = entry_point, **kwargs)
|
||||
|
||||
# ivy_ng_module behaves like ng_module, and under --define=compile=legacy it runs ngc with global
|
||||
# analysis but produces Ivy outputs. Under other compile modes, it behaves as ng_module.
|
||||
# TODO(alxhub): remove when ngtsc supports the same use cases.
|
||||
def ivy_ng_module(name, tsconfig = None, entry_point = None, **kwargs):
|
||||
if not tsconfig:
|
||||
tsconfig = DEFAULT_TSCONFIG
|
||||
if not entry_point:
|
||||
entry_point = "public_api.ts"
|
||||
_internal_global_ng_module(name = name, flat_module_out_file = name, tsconfig = tsconfig, entry_point = entry_point, **kwargs)
|
||||
|
||||
def ng_package(name, readme_md = None, license_banner = None, **kwargs):
|
||||
if not readme_md:
|
||||
readme_md = "//packages:README.md"
|
||||
@ -91,8 +101,3 @@ def ts_web_test_suite(bootstrap = [], deps = [], **kwargs):
|
||||
# TODO(alexeagle): add remote browsers on SauceLabs
|
||||
],
|
||||
**kwargs)
|
||||
|
||||
def ivy_ng_module(name, tsconfig = None, **kwargs):
|
||||
if not tsconfig:
|
||||
tsconfig = DEFAULT_TSCONFIG
|
||||
_ivy_ng_module(name = name, tsconfig = tsconfig, **kwargs)
|
||||
|
Reference in New Issue
Block a user