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

build: add Bazel rules #964

Closed
wants to merge 14 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
src/apps/demo-app/node_modules
src/apps/demo-app/package.json
src/apps/universal-app/package.json
src/apps/universal-app/node_modules
src/apps/hello-world/node_modules
.git
60 changes: 60 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
###############################
# Filesystem interactions #
###############################

# Don't create bazel-* symlinks in the WORKSPACE directory.
# These require .gitignore and may scare users. Also, it's a workaround for
# https://github.com/bazelbuild/rules_typescript/issues/12 which affects the common case of
# having `tsconfig.json` in the WORKSPACE directory. Instead, you should run
# `bazel info output_base` to find out where the outputs went.
build --symlink_prefix=/

# Performance: avoid stat'ing input files
build --watchfs

# Turn off legacy external runfiles
run --nolegacy_external_runfiles
test --nolegacy_external_runfiles

###############################
# Output control #
###############################

# A more useful default output mode for bazel query
# Prints eg. "ng_module rule //foo:bar" rather than just "//foo:bar"
query --output=label_kind

# By default, failing tests don't print any output, it goes to the log file
test --test_output=errors

# Show which actions are run under workers,
# and print all the actions running in parallel.
# Helps to demonstrate that bazel uses all the cores on the machine.
build --experimental_ui
test --experimental_ui

#################################
# Release configuration. #
# Run with "--config=release" #
#################################

# Configures script to do version stamping.
# See https://docs.bazel.build/versions/master/user-manual.html#flag--workspace_status_command
build:release --workspace_status_command=./tools/bazel-stamp-vars.sh

###############################
# Typescript / Angular / Sass #
###############################

# Make compilation fast, by keeping a few copies of the compilers
# running as daemons, and cache SourceFile AST's to reduce parse time.
build --strategy=TypeScriptCompile=worker
build --strategy=AngularTemplateCompile=worker

################################
# Temporary Settings for Ivy #
################################

# Use the legacy AOT compiler strategy. We don't want to compile with Ivy nor with "ngtsc" which
# does not generate factory files which are needed for AOT.
build --define=compile=legacy
7 changes: 7 additions & 0 deletions .circleci/bazel.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Bazel configuration that will be copied to /etc/bazel.bazelrc in CircleCI containers.
# This allows us adding specific configuration flags for builds within CircleCI.
# See more: https://docs.bazel.build/versions/master/user-manual.html#where-are-the-bazelrc-files

# Save downloaded repositories in a location that can be cached by CircleCI. This helps us
# speeding up the analysis time significantly with Bazel managed node dependencies on the CI.
build --experimental_repository_cache=/home/circleci/bazel_repository_cache
96 changes: 78 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# To validate changes, use an online parser, eg.
# http://yaml-online-parser.appspot.com/

var_1: &docker_image angular/ngcontainer:0.7.0
var_2: &cache_key v2-ng-layout-{{ .Branch }}-{{ checksum "yarn.lock" }}-0.7.0
var_1: &docker_image circleci/node:10.12
var_2: &cache_key v2-ng-layout-{{ checksum "WORKSPACE" }}-{{ checksum "yarn.lock" }}-0.7.0

# Settings common to each job
var_3: &job_defaults
Expand Down Expand Up @@ -47,20 +47,39 @@ var_6: &save_cache
var_7: &yarn_install
run: yarn install --frozen-lockfile --non-interactive

# Copies the Bazel config which is specifically for CircleCI to a location where Bazel picks it
# up and merges it with the project-wide bazel configuration (tools/bazel.rc)
var_8: &copy_bazel_config
# Set up the CircleCI specific bazel configuration.
run: sudo cp ./.circleci/bazel.rc /etc/bazel.bazelrc

# Sets up a different Docker image that includes a moe recent Firefox version which
# is needed for headless testing.
var_8: &docker-firefox-image
var_9: &docker-firefox-image
# TODO(devversion): Temporarily use a image that includes Firefox 62 because the
# ngcontainer image does include an old Firefox version that does not support headless.
# See the PR that fixes this: https://github.com/angular/angular/pull/26435
- image: circleci/node:10.12-browsers

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

# Branch filter that we can specify for jobs that should only run on publish branches. This filter
# is used to ensure that not all upstream branches will be published as Github builds
# (e.g. revert branches, feature branches)
var_11: &publish_branches_filter
branches:
only:
- master
# 6.0.x, 7.1.x, etc.
- /\d+\.\d+\.x/
# 6.x, 7.x, 8.x etc
- /\d+\.x/


# -----------------------------
# Container version of CircleCI
# -----------------------------
Expand All @@ -73,21 +92,39 @@ version: 2
jobs:

# -----------------------------------
# Build job
# Build and test job that uses Bazel.
# -----------------------------------
build:
<<: *job_defaults
docker: *docker-firefox-image
resource_class: xlarge
steps:
- *checkout_code
- *restore_cache
- *copy_bazel_config
- *yarn_install

- run: yarn gulp :publish:build-releases
- run: yarn bazel build src/lib/...
- run: yarn bazel test src/lib/...

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

# --------------------------------------------------------------------------------------------
# Job that runs ts-api-guardian against our API goldens in "tools/public_api_guard".
# This job fails whenever an API has been updated but not explicitly approved through goldens.
# --------------------------------------------------------------------------------------------
api_golden_checks:
resource_class: xlarge
<<: *job_defaults
steps:
- *checkout_code
- *restore_cache
- *yarn_install

- run: yarn bazel test tools/public_api_guard/...

# ------------------------------------------------------------------------------------------
# Job that runs the unit tests on locally installed browsers (Chrome and Firefox headless).
# The available browsers are installed through the angular/ngcontainer Docker image.
Expand Down Expand Up @@ -261,6 +298,20 @@ jobs:

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

# ----------------------------------------------------------------------------
# Job that runs the local browser tests against the Angular Github snapshots
# ----------------------------------------------------------------------------
snapshot_tests_local_browsers:
docker: *docker-firefox-image
resource_class: xlarge
steps:
- *checkout_code
- *restore_cache
- *yarn_install

- run: node ./scripts/circleci/setup-angular-snapshots.js
- run: ./scripts/circleci/run-local-browser-tests.sh

# ----------------------------------------------------------------------------------------
# Workflow definitions. A workflow usually groups multiple jobs together. This is useful if
# one job depends on another.
Expand All @@ -276,6 +327,7 @@ workflows:
build:
jobs:
- build
- api_golden_checks

unit_tests:
jobs:
Expand All @@ -294,6 +346,7 @@ workflows:
jobs:
- build_release_packages
- publish_snapshots:
filters: *publish_branches_filter
requires:
- build_release_packages

Expand All @@ -302,14 +355,21 @@ workflows:
jobs:
- lint

# ---------------------------
# General setup for CircleCI
# ---------------------------
general:
branches:
only:
- master
# 5.2.x, 6.0.x, etc
- /\d+\.\d+\.x/
# 5.x, 6.x, etc
- /\d+\.x/
# Snapshot tests workflow that is scheduled to run all specified jobs at midnight everyday.
# This workflow runs various jobs against the Angular snapshot builds from Github.
snapshot_tests:
jobs:
# Note that we need additional jobs for the nightly snapshot tests because there is no
# easy way to detect whether a job runs inside of a cronjob or specific workflow.
# See: https://circleci.com/ideas/?idea=CCI-I-295
- snapshot_tests_local_browsers
triggers:
- schedule:
cron: "0 0 * * *"
filters:
branches:
only:
# We only want to run the "master" branch against the snapshot builds because
# it's not guaranteed that older versions of Angular Layout always work
# with the latest Angular version.
- master
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ testem.log

src/apps/universal-app/package-lock.json
src/apps/universal-app/yarn.lock
src/apps/demo-app/yarn.lock
src/apps/demo-app/package-lock.json
src/apps/demo-app/yarn.lock
src/apps/hello-world/package-lock.json
src/apps/hello-world/yarn.lock
yarn-error.log
3 changes: 3 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package(default_visibility = ["//visibility:public"])

exports_files(["tsconfig.json"])
127 changes: 127 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
workspace(name = "angular_layout")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

# Add NodeJS rules (explicitly used for sass bundle rules)
http_archive(
name = "build_bazel_rules_nodejs",
url = "https://github.com/gregmagolan/rules_nodejs/archive/c8b92cee7e7ed404d7daf49d2379cd6feda799b8.zip",
strip_prefix = "rules_nodejs-c8b92cee7e7ed404d7daf49d2379cd6feda799b8",
)

# Add TypeScript rules
http_archive(
name = "build_bazel_rules_typescript",
strip_prefix = "rules_typescript-0.22.1",
url = "https://github.com/bazelbuild/rules_typescript/archive/0.22.1.zip",
)

# Add Angular source and Bazel rules.
http_archive(
name = "angular",
url = "https://github.com/angular/angular/archive/7.2.4.zip",
strip_prefix = "angular-7.2.4",
)

# Add RxJS as repository because those are needed in order to build Angular from source.
# Also we cannot refer to the RxJS version from the node modules because self-managed
# node modules are not guaranteed to be installed.
# TODO(gmagolan): remove this once rxjs ships with an named UMD bundle and we
# are no longer building it from source.
http_archive(
name = "rxjs",
url = "https://registry.yarnpkg.com/rxjs/-/rxjs-6.3.3.tgz",
strip_prefix = "package/src",
sha256 = "72b0b4e517f43358f554c125e40e39f67688cd2738a8998b4a266981ed32f403",
)

# Angular material
http_archive(
name = "angular_material",
strip_prefix = "material2-7.3.1",
url = "https://github.com/angular/material2/archive/7.3.1.zip",
)

# We need to create a local repository called "npm" because currently Angular Layout
# stores all of it's NPM dependencies in the "@layoutdeps" repository. This is necessary because
# we don't want to reserve the "npm" repository that is commonly used by downstream projects.
# Since we still need the "npm" repository in order to use the Angular or TypeScript Bazel
# rules, we create a local repository that is just defined in **this** workspace and is not
# being shipped to downstream projects. This can be removed once downstream projects can
# consume Angular Layout completely from NPM.
# TODO(CaerusKaru): remove once Angular Layout can be consumed from NPM with Bazel.
local_repository(
name = "npm",
path = "tools/npm-workspace"
)

# Add sass rules
http_archive(
name = "io_bazel_rules_sass",
url = "https://github.com/bazelbuild/rules_sass/archive/1.15.2.zip",
strip_prefix = "rules_sass-1.15.2",
)

# Since we are explitly fetching @build_bazel_rules_typescript, we should explicitly ask for
# its transitive dependencies in case those haven't been fetched yet.
load("@build_bazel_rules_typescript//:package.bzl", "rules_typescript_dependencies")
rules_typescript_dependencies()

# Since we are explitly fetching @build_bazel_rules_nodejs, we should explicitly ask for
# its transitive dependencies in case those haven't been fetched yet.
load("@build_bazel_rules_nodejs//:package.bzl", "rules_nodejs_dependencies")
rules_nodejs_dependencies()

# Fetch transitive dependencies which are needed by the Angular build targets.
load("@angular//packages/bazel:package.bzl", "rules_angular_dependencies")
rules_angular_dependencies()

# Fetch transitive dependencies which are needed to use the Sass rules.
load("@io_bazel_rules_sass//:package.bzl", "rules_sass_dependencies")
rules_sass_dependencies()

load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories")

# The minimum bazel version to use with this repo is 0.18.0
check_bazel_version("0.18.0")

node_repositories(
# For deterministic builds, specify explicit NodeJS and Yarn versions.
node_version = "10.10.0",
# Use latest yarn version to support integrity field (added in yarn 1.10)
yarn_version = "1.12.1",
)

# Setup TypeScript Bazel workspace
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
ts_setup_workspace()

# Setup the Sass rule repositories.
load("@io_bazel_rules_sass//:defs.bzl", "sass_repositories")
sass_repositories()

# Setup Angular workspace for building (Bazel managed node modules)
load("@angular//:index.bzl", "ng_setup_workspace")
ng_setup_workspace()

# Setup Material workspace for building (Bazel managed node modules)
load("@angular_material//:index.bzl", "angular_material_setup_workspace")
angular_material_setup_workspace()

load("@angular_layout//:index.bzl", "angular_layout_setup_workspace")
angular_layout_setup_workspace()

# Setup Go toolchain (required for Bazel web testing rules)
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()

# Setup web testing. We need to setup a browser because the web testing rules for TypeScript need
# a reference to a registered browser (ideally that's a hermetic version of a browser)
load("@io_bazel_rules_webtesting//web:repositories.bzl", "browser_repositories",
"web_test_repositories")

web_test_repositories()
browser_repositories(
chromium = True,
)
13 changes: 13 additions & 0 deletions index.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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
"""Public API surface is re-exported here.
This API is exported for users building Angular Layout from source in
downstream projects.
"""

load("//tools:angular_layout_setup_workspace.bzl",
_angular_layout_setup_workspace = "angular_layout_setup_workspace")

angular_layout_setup_workspace = _angular_layout_setup_workspace
Loading