Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit 8c5074a

Browse files
committed
build: add Bazel rules
1 parent 1b1050b commit 8c5074a

Some content is hidden

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

49 files changed

+1295
-6586
lines changed

.circleci/bazel.rc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# These options are enabled when running on CI
2+
# We do this by copying this file to /etc/bazel.bazelrc at the start of the build.
3+
# See remote cache documentation in /docs/BAZEL.md
4+
5+
# Don't be spammy in the logs
6+
build --noshow_progress
7+
8+
# Don't run manual tests
9+
test --test_tag_filters=-manual
10+
11+
# Print all the options that apply to the build.
12+
# This helps us diagnose which options override others
13+
# (e.g. /etc/bazel.bazelrc vs. tools/bazel.rc)
14+
build --announce_rc
15+
16+
# Create dist/bin symlink to $(bazel info bazel-bin)
17+
# We use this when uploading artifacts after the build finishes
18+
build --symlink_prefix=dist/bazel/
19+
20+
# Enable experimental CircleCI bazel remote cache proxy
21+
# See remote cache documentation in /docs/BAZEL.md
22+
build --experimental_remote_spawn_cache --remote_rest_cache=http://localhost:7643
23+
24+
# Prevent unstable environment variables from tainting cache keys
25+
build --experimental_strict_action_env
26+
27+
# Save downloaded repositories such as the go toolchain
28+
# This directory can then be included in the CircleCI cache
29+
# It should save time running the first build
30+
build --experimental_repository_cache=/home/circleci/bazel_repository_cache
31+
32+
# Workaround https://github.com/bazelbuild/bazel/issues/3645
33+
# Bazel doesn't calculate the memory ceiling correctly when running under Docker.
34+
# Limit Bazel to consuming resources that fit in CircleCI "xlarge" class
35+
# https://circleci.com/docs/2.0/configuration-reference/#resource_class
36+
build --local_resources=14336,8.0,1.0
37+
38+
# Retry in the event of flakes, eg. https://circleci.com/gh/angular/angular/31309
39+
test --flaky_test_attempts=2

.circleci/config.yml

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Configuration file for https://circleci.com/gh/angular/flex-layout
2+
3+
# Note: YAML anchors allow an object to be re-used, reducing duplication.
4+
# The ampersand declares an alias for an object, then later the `<<: *name`
5+
# syntax dereferences it.
6+
# See http://blog.daemonl.com/2016/02/yaml.html
7+
# To validate changes, use an online parser, eg.
8+
# http://yaml-online-parser.appspot.com/
9+
10+
## IMPORTANT
11+
# If you change the `docker_image` version, also change the `cache_key` suffix and the version of
12+
# `com_github_bazelbuild_buildtools` in the `/WORKSPACE` file.
13+
var_1: &docker_image angular/ngcontainer:0.3.0
14+
var_2: &cache_key v2-preboot-{{ .Branch }}-{{ checksum "npm-shrinkwrap.json" }}-0.3.0
15+
16+
# Define common ENV vars
17+
var_3: &define_env_vars
18+
run: echo "export PROJECT_ROOT=$(pwd)" >> $BASH_ENV
19+
20+
# See remote cache documentation in /docs/BAZEL.md
21+
var_4: &setup-bazel-remote-cache
22+
run:
23+
name: Start up bazel remote cache proxy
24+
command: ~/bazel-remote-proxy -backend circleci://
25+
background: true
26+
27+
# Settings common to each job
28+
anchor_1: &job_defaults
29+
working_directory: ~/ng
30+
docker:
31+
- image: *docker_image
32+
33+
# After checkout, rebase on top of master.
34+
# Similar to travis behavior, but not quite the same.
35+
# By default, PRs are not rebased on top of master, which we want.
36+
# See https://discuss.circleci.com/t/1662
37+
anchor_2: &post_checkout
38+
post: git pull --ff-only origin "refs/pull/${CI_PULL_REQUEST//*pull\//}/merge"
39+
40+
version: 2
41+
jobs:
42+
lint:
43+
<<: *job_defaults
44+
steps:
45+
- checkout:
46+
<<: *post_checkout
47+
48+
# Enforce that BUILD files are formatted. Note that this uses the version of buildifier
49+
# from the docker image above - take care that you use the same version when you run
50+
# buildifier locally on your change.
51+
- run: 'buildifier -mode=check $(find . -type f \( -name BUILD.bazel -or -name BUILD \)) ||
52+
(echo "BUILD files not formatted. Please run ''npm run buildifier''" ; exit 1)'
53+
54+
# Run the skylark linter to check our Bazel rules
55+
- run: 'find . -type f -name "*.bzl" |
56+
xargs java -jar /usr/local/bin/Skylint_deploy.jar ||
57+
(echo -e "\n.bzl files have lint errors. Please run ''npm run skylint''"; exit 1)'
58+
59+
- restore_cache:
60+
key: *cache_key
61+
62+
- run: npm install --frozen-lockfile --non-interactive
63+
- run: npm run lint
64+
65+
build:
66+
<<: *job_defaults
67+
resource_class: large
68+
steps:
69+
- checkout:
70+
<<: *post_checkout
71+
# See remote cache documentation in /docs/BAZEL.md
72+
- run: .circleci/setup_cache.sh
73+
- run: sudo cp .circleci/bazel.rc /etc/bazel.bazelrc
74+
- *setup-bazel-remote-cache
75+
- restore_cache:
76+
key: *cache_key
77+
78+
- run: bazel info release
79+
- run: bazel run @nodejs//:npm install
80+
# For some reason, circleci needs the postinstall to be run explicitly.
81+
# This may be unnecessary once rules_nodejs uses nodejs 8
82+
- run: bazel run @nodejs//:npm run postinstall
83+
# Use bazel query so that we explicitly ask for all buildable targets to be built as well
84+
# This avoids waiting for the slowest build target to finish before running the first test
85+
# See https://github.com/bazelbuild/bazel/issues/4257
86+
# NOTE: Angular developers should typically just bazel build //... or bazel test //...
87+
- run: bazel query --output=label //... | xargs bazel test
88+
89+
# Save the npm packages from //packages/... for other workflow jobs to read
90+
# https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs
91+
# - persist_to_workspace:
92+
# root: dist
93+
# paths:
94+
# - dist
95+
96+
- save_cache:
97+
key: *cache_key
98+
paths:
99+
- "node_modules"
100+
101+
# Save the npm packages from //packages/... for other workflow jobs to read
102+
# https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs
103+
- persist_to_workspace:
104+
root: dist
105+
paths:
106+
- bazel/**/*
107+
108+
# We run the integration tests outside of Bazel for now.
109+
# They are a separate workflow job so that they can be easily re-run.
110+
# When the tests are ported to bazel test targets, they should move to the "test"
111+
# job above, as part of the bazel test command. That has flaky_test_attempts so the
112+
# need to re-run manually should be alleviated.
113+
integration_test:
114+
<<: *job_defaults
115+
steps:
116+
- *define_env_vars
117+
- checkout:
118+
<<: *post_checkout
119+
- attach_workspace:
120+
at: dist
121+
- run: npm install --frozen-lockfile --non-interactive
122+
- run: npm run e2e
123+
124+
workflows:
125+
version: 2
126+
default_workflow:
127+
jobs:
128+
- lint
129+
- build
130+
- integration_test:
131+
requires:
132+
- build
133+
134+
general:
135+
branches:
136+
only:
137+
- master

.circleci/setup_cache.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
# Install bazel remote cache proxy
3+
# This is temporary until the feature is no longer experimental on CircleCI.
4+
# See remote cache documentation in /docs/BAZEL.md
5+
6+
set -u -e
7+
8+
readonly DOWNLOAD_URL="https://5-116431813-gh.circle-artifacts.com/0/pkg/bazel-remote-proxy-$(uname -s)_$(uname -m)"
9+
10+
curl --fail -o ~/bazel-remote-proxy "$DOWNLOAD_URL"
11+
chmod +x ~/bazel-remote-proxy

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ logs
55
.vscode
66
.DS_Store
77
**/.DS_Store
8+
bazel-out
9+
yarn.lock
810

911
package-lock.json
1012

BUILD.bazel

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
load("@build_bazel_rules_nodejs//:defs.bzl", "node_modules_filegroup")
4+
5+
# This rule belongs in node_modules/BUILD
6+
# It's here as a workaround for
7+
# https://github.com/bazelbuild/bazel/issues/374#issuecomment-296217940
8+
node_modules_filegroup(
9+
name = "node_modules",
10+
packages = [
11+
"bytebuffer",
12+
"jasmine",
13+
"minimist",
14+
"protobufjs",
15+
"protractor",
16+
"reflect-metadata",
17+
"rxjs",
18+
"tsickle",
19+
"tslib",
20+
"tsutils",
21+
"typescript",
22+
"zone.js",
23+
"@angular",
24+
"@types",
25+
],
26+
)
27+
28+
# Glob pattern that matches all Angular testing bundles.
29+
ANGULAR_TESTING = [
30+
"node_modules/@angular/*/bundles/*-testing.umd.js",
31+
# The compiler and the dynamic platform-browser should be visible only in tests
32+
"node_modules/@angular/compiler/bundles/*.umd.js",
33+
"node_modules/@angular/platform-browser-dynamic/bundles/*.umd.js",
34+
]
35+
36+
filegroup(
37+
name = "angular_bundles",
38+
srcs = glob(
39+
["node_modules/@angular/*/bundles/*.umd.js"],
40+
exclude = ANGULAR_TESTING,
41+
),
42+
)
43+
44+
filegroup(
45+
name = "angular_test_bundles",
46+
testonly = 1,
47+
srcs = glob(ANGULAR_TESTING),
48+
)
49+
50+
filegroup(
51+
name = "tslib_bundle",
52+
testonly = 1,
53+
srcs = glob(["node_modules/tslib/tslib.js"]),
54+
)
55+
56+
# Files necessary for unit tests that use zonejs
57+
filegroup(
58+
name = "web_test_bootstrap_scripts",
59+
# The order of these deps is important.
60+
# Do not sort.
61+
srcs = [
62+
"//:node_modules/reflect-metadata/Reflect.js",
63+
"//:node_modules/zone.js/dist/zone.js",
64+
"//:node_modules/zone.js/dist/async-test.js",
65+
"//:node_modules/zone.js/dist/sync-test.js",
66+
"//:node_modules/zone.js/dist/fake-async-test.js",
67+
"//:node_modules/zone.js/dist/proxy.js",
68+
"//:node_modules/zone.js/dist/jasmine-patch.js",
69+
],
70+
)

WORKSPACE

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
workspace(name = "preboot")
2+
3+
#
4+
# Download Bazel toolchain dependencies as needed by build actions
5+
#
6+
7+
http_archive(
8+
name = "build_bazel_rules_nodejs",
9+
urls = ["https://github.com/bazelbuild/rules_nodejs/archive/0.11.2.zip"],
10+
strip_prefix = "rules_nodejs-0.11.2",
11+
sha256 = "c00d5381adeefb56e0ef959a7b168cae628535dab933cfad1c2cd1870cd7c9de",
12+
)
13+
14+
http_archive(
15+
name = "bazel_skylib",
16+
urls = ["https://github.com/bazelbuild/bazel-skylib/archive/0.3.1.zip"],
17+
strip_prefix = "bazel-skylib-0.3.1",
18+
sha256 = "95518adafc9a2b656667bbf517a952e54ce7f350779d0dd95133db4eb5c27fb1",
19+
)
20+
21+
http_archive(
22+
name = "io_bazel_rules_webtesting",
23+
url = "https://github.com/bazelbuild/rules_webtesting/archive/7ffe970bbf380891754487f66c3d680c087d67f2.zip",
24+
strip_prefix = "rules_webtesting-7ffe970bbf380891754487f66c3d680c087d67f2",
25+
sha256 = "4fb0dca8c9a90547891b7ef486592775a523330fc4555c88cd8f09270055c2ce",
26+
)
27+
28+
http_archive(
29+
name = "build_bazel_rules_typescript",
30+
url = "https://github.com/bazelbuild/rules_typescript/archive/1d9a4b0087f307e31af91e2b221a6447288994c6.zip",
31+
strip_prefix = "rules_typescript-1d9a4b0087f307e31af91e2b221a6447288994c6",
32+
sha256 = "e17ac3f33d5d3cd2a0c385c4fd28b814d0ad46c6c67ccaef97160be99d7a24eb",
33+
)
34+
35+
http_archive(
36+
name = "io_bazel_rules_go",
37+
url = "https://github.com/bazelbuild/rules_go/releases/download/0.10.3/rules_go-0.10.3.tar.gz",
38+
sha256 = "feba3278c13cde8d67e341a837f69a029f698d7a27ddbb2a202be7a10b22142a",
39+
)
40+
41+
# This commit matches the version of buildifier in angular/ngcontainer
42+
# If you change this, also check if it matches the version in the angular/ngcontainer
43+
# version in /.circleci/config.yml
44+
BAZEL_BUILDTOOLS_VERSION = "82b21607e00913b16fe1c51bec80232d9d6de31c"
45+
46+
http_archive(
47+
name = "com_github_bazelbuild_buildtools",
48+
url = "https://github.com/bazelbuild/buildtools/archive/%s.zip" % BAZEL_BUILDTOOLS_VERSION,
49+
strip_prefix = "buildtools-%s" % BAZEL_BUILDTOOLS_VERSION,
50+
sha256 = "edb24c2f9c55b10a820ec74db0564415c0cf553fa55e9fc709a6332fb6685eff",
51+
)
52+
53+
# Fetching the Bazel source code allows us to compile the Skylark linter
54+
http_archive(
55+
name = "io_bazel",
56+
url = "https://github.com/bazelbuild/bazel/archive/968f87900dce45a7af749a965b72dbac51b176b3.zip",
57+
strip_prefix = "bazel-968f87900dce45a7af749a965b72dbac51b176b3",
58+
sha256 = "e373d2ae24955c1254c495c9c421c009d88966565c35e4e8444c082cb1f0f48f",
59+
)
60+
61+
62+
#
63+
# Load and install our dependencies downloaded above.
64+
#
65+
66+
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories")
67+
68+
check_bazel_version("0.15.0")
69+
node_repositories(
70+
package_json = ["//:package.json"],
71+
preserve_symlinks = True,
72+
)
73+
74+
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
75+
76+
go_rules_dependencies()
77+
go_register_toolchains()
78+
79+
load("@io_bazel_rules_webtesting//web:repositories.bzl", "browser_repositories", "web_test_repositories")
80+
81+
web_test_repositories()
82+
browser_repositories(
83+
chromium = True,
84+
firefox = True,
85+
)
86+
87+
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
88+
89+
ts_setup_workspace()
90+
91+
92+
# Add Angular rules
93+
local_repository(
94+
name = "angular",
95+
path = "node_modules/@angular/bazel",
96+
)
97+
98+
# Add rxjs
99+
local_repository(
100+
name = "rxjs",
101+
path = "node_modules/rxjs/src",
102+
)
103+
104+
105+
load("@angular//:index.bzl", "ng_setup_workspace")
106+
107+
ng_setup_workspace()

angular.tsconfig.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// WORKAROUND https://github.com/angular/angular/issues/18810
2+
// This file is required to run ngc on angular libraries, to write files like
3+
// node_modules/@angular/core/core.ngsummary.json
4+
{
5+
"compilerOptions": {
6+
"lib": [
7+
"dom",
8+
"es2015"
9+
],
10+
"experimentalDecorators": true,
11+
"types": ["jasmine"]
12+
},
13+
"include": [
14+
"node_modules/@angular/**/*"
15+
],
16+
"exclude": [
17+
"node_modules/@angular/bazel/**",
18+
"node_modules/@angular/compiler-cli/**",
19+
"node_modules/@angular/*/testing/**"
20+
]
21+
}

0 commit comments

Comments
 (0)