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

Commit 2a03fea

Browse files
committed
build: add Bazel rules
1 parent 6e8417e commit 2a03fea

Some content is hidden

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

52 files changed

+1288
-6479
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: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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: ls -R dist/bazel | awk '
122+
/:$/&&f{s=$0;f=0}
123+
/:$/&&!f{sub(/:$/,"");s=$0;f=1;next}
124+
NF&&f{ print s"/"$0 }'
125+
- run: npm install --frozen-lockfile --non-interactive
126+
- run: npm run e2e
127+
128+
workflows:
129+
version: 2
130+
default_workflow:
131+
jobs:
132+
- lint
133+
- build
134+
- integration_test:
135+
requires:
136+
- build
137+
138+
general:
139+
branches:
140+
only:
141+
- 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: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
url = "https://github.com/bazelbuild/rules_nodejs/archive/0.8.0.zip",
10+
strip_prefix = "rules_nodejs-0.8.0",
11+
sha256 = "4e40dd49ae7668d245c3107645f2a138660fcfd975b9310b91eda13f0c973953",
12+
)
13+
14+
http_archive(
15+
name = "io_bazel_rules_webtesting",
16+
url = "https://github.com/alexeagle/rules_webtesting/archive/22d497fad3c45faa2b7b28635dfa15f74c655602.zip",
17+
strip_prefix = "rules_webtesting-22d497fad3c45faa2b7b28635dfa15f74c655602",
18+
#sha256 = "28c73cf9d310fa6dba30e66bdb98071341c99c3feb8662f2d3883a632de97d72",
19+
)
20+
21+
http_archive(
22+
name = "build_bazel_rules_typescript",
23+
url = "https://github.com/bazelbuild/rules_typescript/archive/v0.13.0.zip",
24+
strip_prefix = "rules_typescript-0.13.0",
25+
sha256 = "8f2767ff56ad68c80c62e9a1cdc2ba2c2ba0b19d350f713365e5333045df02e3",
26+
)
27+
28+
http_archive(
29+
name = "io_bazel_rules_go",
30+
url = "https://github.com/bazelbuild/rules_go/releases/download/0.10.3/rules_go-0.10.3.tar.gz",
31+
sha256 = "feba3278c13cde8d67e341a837f69a029f698d7a27ddbb2a202be7a10b22142a",
32+
)
33+
34+
# This commit matches the version of buildifier in angular/ngcontainer
35+
# If you change this, also check if it matches the version in the angular/ngcontainer
36+
# version in /.circleci/config.yml
37+
BAZEL_BUILDTOOLS_VERSION = "fd9878fd5de921e0bbab3dcdcb932c2627812ee1"
38+
39+
40+
# The Bazel buildtools repo contains tools like the BUILD file formatter, buildifier
41+
http_archive(
42+
name = "com_github_bazelbuild_buildtools",
43+
# Note, this commit matches the version of buildifier in angular/ngcontainer
44+
url = "https://github.com/bazelbuild/buildtools/archive/%s.zip" % BAZEL_BUILDTOOLS_VERSION,
45+
strip_prefix = "buildtools-%s" % BAZEL_BUILDTOOLS_VERSION,
46+
sha256 = "27bb461ade23fd44ba98723ad98f84ee9c83cd3540b773b186a1bc5037f3d862",
47+
)
48+
49+
# Fetching the Bazel source code allows us to compile the Skylark linter
50+
http_archive(
51+
name = "io_bazel",
52+
url = "https://github.com/bazelbuild/bazel/archive/968f87900dce45a7af749a965b72dbac51b176b3.zip",
53+
strip_prefix = "bazel-968f87900dce45a7af749a965b72dbac51b176b3",
54+
sha256 = "e373d2ae24955c1254c495c9c421c009d88966565c35e4e8444c082cb1f0f48f",
55+
)
56+
57+
58+
#
59+
# Load and install our dependencies downloaded above.
60+
#
61+
62+
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories")
63+
64+
check_bazel_version("0.13.0")
65+
node_repositories(package_json = ["//:package.json"])
66+
67+
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
68+
69+
go_rules_dependencies()
70+
go_register_toolchains()
71+
72+
load("@io_bazel_rules_webtesting//web:repositories.bzl", "browser_repositories", "web_test_repositories")
73+
74+
web_test_repositories()
75+
browser_repositories(
76+
chromium = True,
77+
firefox = True,
78+
)
79+
80+
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
81+
82+
ts_setup_workspace()
83+
84+
# Add Angular rules
85+
local_repository(
86+
name = "angular",
87+
path = "node_modules/@angular/bazel",
88+
)
89+
90+
# Add rxjs
91+
local_repository(
92+
name = "rxjs",
93+
path = "node_modules/rxjs/src",
94+
)

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)