Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 2c753be

Browse files
committed
build: add Bazel rules
1 parent 5814448 commit 2c753be

File tree

148 files changed

+3781
-428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+3781
-428
lines changed

.bazelignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
**/package.json
3+
**/node_modules

.bazelrc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
###############################
2+
# Filesystem interactions #
3+
###############################
4+
5+
# Don't create bazel-* symlinks in the WORKSPACE directory.
6+
# These require .gitignore and may scare users. Also, it's a workaround for
7+
# https://github.com/bazelbuild/rules_typescript/issues/12 which affects the common case of
8+
# having `tsconfig.json` in the WORKSPACE directory. Instead, you should run
9+
# `bazel info output_base` to find out where the outputs went.
10+
build --symlink_prefix=/
11+
12+
# Performance: avoid stat'ing input files
13+
build --watchfs
14+
15+
# Turn off legacy external runfiles
16+
run --nolegacy_external_runfiles
17+
test --nolegacy_external_runfiles
18+
19+
###############################
20+
# Output control #
21+
###############################
22+
23+
# A more useful default output mode for bazel query
24+
# Prints eg. "ng_module rule //foo:bar" rather than just "//foo:bar"
25+
query --output=label_kind
26+
27+
# By default, failing tests don't print any output, it goes to the log file
28+
test --test_output=errors
29+
30+
# Show which actions are run under workers,
31+
# and print all the actions running in parallel.
32+
# Helps to demonstrate that bazel uses all the cores on the machine.
33+
build --experimental_ui
34+
test --experimental_ui
35+
36+
#################################
37+
# Release configuration. #
38+
# Run with "--config=release" #
39+
#################################
40+
41+
# Configures script to do version stamping.
42+
# See https://docs.bazel.build/versions/master/user-manual.html#flag--workspace_status_command
43+
build:release --workspace_status_command=./tools/bazel-stamp-vars.sh
44+
45+
###############################
46+
# Typescript / Angular / Sass #
47+
###############################
48+
49+
# Make compilation fast, by keeping a few copies of the compilers
50+
# running as daemons, and cache SourceFile AST's to reduce parse time.
51+
build --strategy=TypeScriptCompile=worker
52+
build --strategy=AngularTemplateCompile=worker
53+
54+
################################
55+
# Temporary Settings for Ivy #
56+
################################
57+
58+
# Use the legacy AOT compiler strategy. We don't want to compile with Ivy nor with "ngtsc" which
59+
# does not generate factory files which are needed for AOT.
60+
build --define=compile=legacy

.circleci/bazel.rc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Bazel configuration that will be copied to /etc/bazel.bazelrc in CircleCI containers.
2+
# This allows us adding specific configuration flags for builds within CircleCI.
3+
# See more: https://docs.bazel.build/versions/master/user-manual.html#where-are-the-bazelrc-files
4+
5+
# Save downloaded repositories in a location that can be cached by CircleCI. This helps us
6+
# speeding up the analysis time significantly with Bazel managed node dependencies on the CI.
7+
build --experimental_repository_cache=/home/circleci/bazel_repository_cache

.circleci/config.yml

Lines changed: 74 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,39 @@ var_6: &save_cache
4747
var_7: &yarn_install
4848
run: yarn install --frozen-lockfile --non-interactive
4949

50+
# Copies the Bazel config which is specifically for CircleCI to a location where Bazel picks it
51+
# up and merges it with the project-wide bazel configuration (tools/bazel.rc)
52+
var_8: &copy_bazel_config
53+
# Set up the CircleCI specific bazel configuration.
54+
run: sudo cp ./.circleci/bazel.rc /etc/bazel.bazelrc
55+
5056
# Sets up a different Docker image that includes a moe recent Firefox version which
5157
# is needed for headless testing.
52-
var_8: &docker-firefox-image
58+
var_9: &docker-firefox-image
5359
# TODO(devversion): Temporarily use a image that includes Firefox 62 because the
5460
# ngcontainer image does include an old Firefox version that does not support headless.
5561
# See the PR that fixes this: https://github.com/angular/angular/pull/26435
5662
- image: circleci/node:10.12-browsers
5763

5864
# Attaches the release output which has been stored in the workspace to the current job.
5965
# https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs
60-
var_9: &attach_release_output
66+
var_10: &attach_release_output
6167
attach_workspace:
6268
at: dist/releases
6369

70+
# Branch filter that we can specify for jobs that should only run on publish branches. This filter
71+
# is used to ensure that not all upstream branches will be published as Github builds
72+
# (e.g. revert branches, feature branches)
73+
var_11: &publish_branches_filter
74+
branches:
75+
only:
76+
- master
77+
# 6.0.x, 7.1.x, etc.
78+
- /\d+\.\d+\.x/
79+
# 6.x, 7.x, 8.x etc
80+
- /\d+\.x/
81+
82+
6483
# -----------------------------
6584
# Container version of CircleCI
6685
# -----------------------------
@@ -73,21 +92,36 @@ version: 2
7392
jobs:
7493

7594
# -----------------------------------
76-
# Build job
95+
# Build and test job that uses Bazel.
7796
# -----------------------------------
7897
build:
7998
<<: *job_defaults
99+
resource_class: xlarge
80100
steps:
81101
- *checkout_code
82102
- *restore_cache
83-
- *yarn_install
103+
- *copy_bazel_config
84104

85-
- run: yarn gulp :publish:build-releases
105+
- run: bazel build src/lib/...
106+
- run: bazel test src/lib/...
86107

87108
# Note: We want to save the cache in this job because the workspace cache also
88-
# includes the build cache that will be updated in this job.
109+
# includes the Bazel repository cache that will be updated in this job.
89110
- *save_cache
90111

112+
# --------------------------------------------------------------------------------------------
113+
# Job that runs ts-api-guardian against our API goldens in "tools/public_api_guard".
114+
# This job fails whenever an API has been updated but not explicitly approved through goldens.
115+
# --------------------------------------------------------------------------------------------
116+
api_golden_checks:
117+
resource_class: xlarge
118+
<<: *job_defaults
119+
steps:
120+
- *checkout_code
121+
- *restore_cache
122+
123+
- run: bazel test tools/public_api_guard/...
124+
91125
# ------------------------------------------------------------------------------------------
92126
# Job that runs the unit tests on locally installed browsers (Chrome and Firefox headless).
93127
# The available browsers are installed through the angular/ngcontainer Docker image.
@@ -261,6 +295,20 @@ jobs:
261295

262296
- run: ./scripts/circleci/publish-snapshots.sh
263297

298+
# ----------------------------------------------------------------------------
299+
# Job that runs the local browser tests against the Angular Github snapshots
300+
# ----------------------------------------------------------------------------
301+
snapshot_tests_local_browsers:
302+
docker: *docker-firefox-image
303+
resource_class: xlarge
304+
steps:
305+
- *checkout_code
306+
- *restore_cache
307+
- *yarn_install
308+
309+
- run: node ./scripts/circleci/setup-angular-snapshots.js
310+
- run: ./scripts/circleci/run-local-browser-tests.sh
311+
264312
# ----------------------------------------------------------------------------------------
265313
# Workflow definitions. A workflow usually groups multiple jobs together. This is useful if
266314
# one job depends on another.
@@ -276,6 +324,7 @@ workflows:
276324
build:
277325
jobs:
278326
- build
327+
- api_golden_checks
279328

280329
unit_tests:
281330
jobs:
@@ -294,6 +343,7 @@ workflows:
294343
jobs:
295344
- build_release_packages
296345
- publish_snapshots:
346+
filters: *publish_branches_filter
297347
requires:
298348
- build_release_packages
299349

@@ -302,14 +352,21 @@ workflows:
302352
jobs:
303353
- lint
304354

305-
# ---------------------------
306-
# General setup for CircleCI
307-
# ---------------------------
308-
general:
309-
branches:
310-
only:
311-
- master
312-
# 5.2.x, 6.0.x, etc
313-
- /\d+\.\d+\.x/
314-
# 5.x, 6.x, etc
315-
- /\d+\.x/
355+
# Snapshot tests workflow that is scheduled to run all specified jobs at midnight everyday.
356+
# This workflow runs various jobs against the Angular snapshot builds from Github.
357+
snapshot_tests:
358+
jobs:
359+
# Note that we need additional jobs for the nightly snapshot tests because there is no
360+
# easy way to detect whether a job runs inside of a cronjob or specific workflow.
361+
# See: https://circleci.com/ideas/?idea=CCI-I-295
362+
- snapshot_tests_local_browsers
363+
triggers:
364+
- schedule:
365+
cron: "0 0 * * *"
366+
filters:
367+
branches:
368+
only:
369+
# We only want to run the "master" branch against the snapshot builds because
370+
# it's not guaranteed that older versions of Angular Layout always work
371+
# with the latest Angular version.
372+
- master

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,8 @@ testem.log
2828
!/test/karma.conf.js
2929

3030
src/apps/universal-app/package-lock.json
31+
src/apps/universal-app/yarn.lock
3132
src/apps/demo-app/package-lock.json
33+
src/apps/demo-app/yarn.lock
3234
src/apps/hello-world/package-lock.json
35+
src/apps/hello-world/yarn.lock

BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
exports_files(["tsconfig.json"])

WORKSPACE

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
workspace(name = "angular_layout")
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
# Add NodeJS rules (explicitly used for sass bundle rules)
6+
http_archive(
7+
name = "build_bazel_rules_nodejs",
8+
url = "https://github.com/bazelbuild/rules_nodejs/archive/616ee38684dc46cba39635f03dd158ac6a931f48.zip",
9+
strip_prefix = "rules_nodejs-616ee38684dc46cba39635f03dd158ac6a931f48",
10+
)
11+
12+
# Add TypeScript rules
13+
http_archive(
14+
name = "build_bazel_rules_typescript",
15+
url = "https://github.com/bazelbuild/rules_typescript/archive/0.22.0.zip",
16+
strip_prefix = "rules_typescript-0.22.0",
17+
)
18+
19+
# Add Angular source and Bazel rules.
20+
http_archive(
21+
name = "angular",
22+
url = "https://github.com/angular/angular/archive/7.1.3.zip",
23+
strip_prefix = "angular-7.1.3",
24+
)
25+
26+
# Add RxJS as repository because those are needed in order to build Angular from source.
27+
# Also we cannot refer to the RxJS version from the node modules because self-managed
28+
# node modules are not guaranteed to be installed.
29+
# TODO(gmagolan): remove this once rxjs ships with an named UMD bundle and we
30+
# are no longer building it from source.
31+
http_archive(
32+
name = "rxjs",
33+
url = "https://registry.yarnpkg.com/rxjs/-/rxjs-6.3.3.tgz",
34+
strip_prefix = "package/src",
35+
sha256 = "72b0b4e517f43358f554c125e40e39f67688cd2738a8998b4a266981ed32f403",
36+
)
37+
38+
# Angular material
39+
# NOTE: using a `7.1.1-compat-ng-7.1.3` branch of material2 on a fork here
40+
# since Angular and rules_typescript version under Bazel checking is too strict
41+
# at the moment.
42+
# https://github.com/gregmagolan/material2/commit/e2090864cddf926445eefd39c7e90eada107013d
43+
# TODO(gregmagolan): update the next release of material that is compatible with
44+
# Angular 7.1.3 under Bazel
45+
http_archive(
46+
name = "angular_material",
47+
sha256 = "75bec457885ddf084219a9da152ff79831d84909bb036552141ca3aadee64a04",
48+
strip_prefix = "material2-7.1.1-compat-ng-7.1.3",
49+
url = "https://github.com/gregmagolan/material2/archive/7.1.1-compat-ng-7.1.3.zip",
50+
)
51+
52+
# We need to create a local repository called "npm" because currently Angular Layout
53+
# stores all of it's NPM dependencies in the "@layoutdeps" repository. This is necessary because
54+
# we don't want to reserve the "npm" repository that is commonly used by downstream projects.
55+
# Since we still need the "npm" repository in order to use the Angular or TypeScript Bazel
56+
# rules, we create a local repository that is just defined in **this** workspace and is not
57+
# being shipped to downstream projects. This can be removed once downstream projects can
58+
# consume Angular Layout completely from NPM.
59+
# TODO(CaerusKaru): remove once Angular Layout can be consumed from NPM with Bazel.
60+
local_repository(
61+
name = "npm",
62+
path = "tools/npm-workspace"
63+
)
64+
65+
# Add sass rules
66+
http_archive(
67+
name = "io_bazel_rules_sass",
68+
url = "https://github.com/bazelbuild/rules_sass/archive/1.15.2.zip",
69+
strip_prefix = "rules_sass-1.15.2",
70+
)
71+
72+
# Since we are explitly fetching @build_bazel_rules_typescript, we should explicitly ask for
73+
# its transitive dependencies in case those haven't been fetched yet.
74+
load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dependencies")
75+
rules_typescript_dependencies()
76+
77+
# Since we are explitly fetching @build_bazel_rules_nodejs, we should explicitly ask for
78+
# its transitive dependencies in case those haven't been fetched yet.
79+
load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dependencies")
80+
rules_nodejs_dependencies()
81+
82+
# Fetch transitive dependencies which are needed by the Angular build targets.
83+
load("@angular//packages/bazel:package.bzl", "rules_angular_dependencies")
84+
rules_angular_dependencies()
85+
86+
# Fetch transitive dependencies which are needed to use the Sass rules.
87+
load("@io_bazel_rules_sass//:package.bzl", "rules_sass_dependencies")
88+
rules_sass_dependencies()
89+
90+
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories")
91+
92+
# The minimum bazel version to use with this repo is 0.18.0
93+
check_bazel_version("0.18.0")
94+
95+
node_repositories(
96+
# For deterministic builds, specify explicit NodeJS and Yarn versions.
97+
node_version = "10.10.0",
98+
# Use latest yarn version to support integrity field (added in yarn 1.10)
99+
yarn_version = "1.12.1",
100+
)
101+
102+
# Setup TypeScript Bazel workspace
103+
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
104+
ts_setup_workspace()
105+
106+
# Setup the Sass rule repositories.
107+
load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories")
108+
sass_repositories()
109+
110+
# Setup Angular workspace for building (Bazel managed node modules)
111+
load("@angular//:index.bzl", "ng_setup_workspace")
112+
ng_setup_workspace()
113+
114+
# Setup Material workspace for building (Bazel managed node modules)
115+
load("@angular_material//:index.bzl", "angular_material_setup_workspace")
116+
angular_material_setup_workspace()
117+
118+
load("@angular_layout//:index.bzl", "angular_layout_setup_workspace")
119+
angular_layout_setup_workspace()
120+
121+
# Setup Go toolchain (required for Bazel web testing rules)
122+
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
123+
go_rules_dependencies()
124+
go_register_toolchains()
125+
126+
# Setup web testing. We need to setup a browser because the web testing rules for TypeScript need
127+
# a reference to a registered browser (ideally that's a hermetic version of a browser)
128+
load("@io_bazel_rules_webtesting//web:repositories.bzl", "browser_repositories",
129+
"web_test_repositories")
130+
131+
web_test_repositories()
132+
browser_repositories(
133+
chromium = True,
134+
)

index.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright Google LLC All Rights Reserved.
2+
#
3+
# Use of this source code is governed by an MIT-style license that can be
4+
# found in the LICENSE file at https://angular.io/license
5+
"""Public API surface is re-exported here.
6+
This API is exported for users building Angular Layout from source in
7+
downstream projects.
8+
"""
9+
10+
load("//tools:angular_layout_setup_workspace.bzl",
11+
_angular_layout_setup_workspace = "angular_layout_setup_workspace")
12+
13+
angular_layout_setup_workspace = _angular_layout_setup_workspace

0 commit comments

Comments
 (0)