Files
carbon-lang/.github/workflows/tests.yaml
T
Chandler CarruthandJon Meow 05261b7fe7 Remove the LLVM bootstrap and use Hombrew installed LLVM-12. (#551)
Now that LLVM 12 has been released we no longer have any need to
bootstrap LLVM to get the desired featureset. LLVM 12 is available
widely, including in Homebrew across multiple platforms and in the
GitHub action runners.

Sadly, the Linux distribution builds of LLVM-12 are largely broken and
not as useful for us. The Homebrew Linux install was also broken
originally, but I've worked extensively with the Homebrew folks to get
the Linux install into a really good shape. It should now work reliably.

There are two primary bugs in Linux LLVM packages that need to be fixed
before we can just use them:

- https://bugs.llvm.org/show_bug.cgi?id=43604
- https://bugs.llvm.org/show_bug.cgi?id=46321

Once those are addressed and point releases with the fixes widely
available we can further simplify things.

Even with the need to use Homebrew installs, using the released LLVM has
the extra advantage of making it easy to properly support Darwin ARM and
I've added that configuration so that I can test things there.

Last but not least, this will significantly shrink our build outputs
which should allow building much more in continuous integration on
GitHub actions without exceeding the action cache size limits. I've even
added several tweaks and adjustments to the compile and build flags to
improve the build performance and reduce the build output size.

Once this is landed and stable, we can consider adding the refactoring
tooling back to our CI.

One of the biggest downsides of this path is that our CI has to download
and install the LLVM toolchain from Homebrew on each run. This is pretty
slow (takes a couple of minutes). But it is a fixed overhead -- it won't
get worse over time. Eventually, we can either look at a much fancier
action configuration to avoid this or hopefully the Debian packages will
get updated and we can move back to those.

The bootstrapping has served us long enough at this point. We can
resurrect it if we ever find a compelling reason for breaking off of the
latest LLVM release as our host toolchain.

Co-authored-by: Jon Meow <46229924+jonmeow@users.noreply.github.com>
2021-06-09 10:00:46 -07:00

171 lines
6.4 KiB
YAML

# Part of the Carbon Language project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
name: test
on:
push:
branches: [trunk]
paths:
# Conservatively run the tests. However, skip them if the only paths in
# the pull request match files that we know don't impact the build.
- '**'
- '!**/*.md'
- '!LICENSE'
- '!CODEOWNERS'
- '!.git*'
pull_request:
paths:
# Conservatively run the tests. However, skip them if the only paths in
# the pull request match files that we know don't impact the build.
- '**'
- '!**/*.md'
- '!LICENSE'
- '!CODEOWNERS'
- '!.git*'
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
build_mode: [fastbuild, opt]
runs-on: ${{ matrix.os }}
steps:
- name: Create environment variables
run: |
echo "BAZEL_OUTPUT_BASE_PATH=$HOME/.cache/bazel-output-base" >> $GITHUB_ENV
echo "BAZEL=bazelisk --output_base=$HOME/.cache/bazel-output-base" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
# Setup Python and related tools.
- uses: actions/setup-python@v2
with:
# Match the min version listed in docs/project/contribution_tools.md
python-version: '3.6'
# On macOS we need Go and to use it to install Bazelisk.
- uses: actions/setup-go@v2
if: matrix.os == 'macos-latest'
- name: Install bazelisk
if: matrix.os == 'macos-latest'
run: |
go get github.com/bazelbuild/bazelisk
echo "$(go env GOPATH)/bin" >> $GITHUB_PATH
# Setup to the latest LLVM and Clang release on Linux runners.
#
# Ideally we would use the pre-installed versions in the image, but the
# debian packages for LLVM-12 are broken due to several bugs:
# https://bugs.llvm.org/show_bug.cgi?id=43604
# https://bugs.llvm.org/show_bug.cgi?id=46321
#
# For now, we rely on Homebrew to manage installing a correctly built
# toolchain. We also take some care to be as resilient as possible to
# issues fetching and installing the toolchain.
- name: Setup LLVM and Clang on Ubuntu
if: matrix.os == 'ubuntu-latest'
run: |
brew update
brew install --force-bottle --only-dependencies llvm
brew install --force-bottle --force --verbose llvm
brew info llvm
brew config
echo "$(brew --prefix llvm)/bin" >> $GITHUB_PATH
# Just add the Homebrew installed LLVM to the path on macOS, the image has
# LLVM-12 pre-installed.
- name: Setup LLVM and Clang on macOS
if: matrix.os == 'macos-latest'
run: |
echo "$(brew --prefix llvm)/bin" >> $GITHUB_PATH
# Print the various tool paths and versions to help in debugging.
- name: Print tool debugging info
run: |
echo $PATH
which bazelisk
bazelisk --version
which python
python --version
which clang
clang --version
which clang++
clang++ --version
which clang-format
clang-format --version
# Make the date available to subsequent steps.
- name: Get date
id: date
shell: bash
run: |
echo "::set-output name=date::$(/bin/date -u "+%Y%m%d")"
# Preserve and restore the Bazel cache across builds.
#
# These cached entries are keyed on this file (which configures the
# command and other inputs) as well as the date. Because Bazel is
# hermetic, it doesn't matter if we get a "stale" entry here, but it makes
# the cache less efficient. So we use the date to get a fresh baseline
# cache once per day. We include this file so that changing the build
# structure itself returns us to a clean state. We can also increment the
# counter in this comment to forcibly rotate this hash in the event we get
# a corrupted cache that breaks Bazel. This is a risk because we very
# selectively prune directories out of the internals of the Bazel output
# base to reduce the storage of the cache. At any point, this might break
# invariants and require us to clear our caches. There is no way to
# actually delete them and so instead we can simply bump the counter here.
#
# Current cache version: 2
- name: Cache Bazel build data
uses: actions/cache@v2
with:
# We exclude the install symlink so that Bazel reconnects to the
# current installation. This helps repair any damage done by other
# exclusions as well. Then we exclude the `external` tree because
# those are all downloaded and rapidly rebuilt, so no benefit from
# downloading them with the cached state.
path: |
${{ env.BAZEL_OUTPUT_BASE_PATH }}
!${{ env.BAZEL_OUTPUT_BASE_PATH }}/install
!${{ env.BAZEL_OUTPUT_BASE_PATH }}/external
key: |
bazel-${{ matrix.os }}-${{ matrix.build_mode }}-${{ hashFiles('.github/workflows/tests.yaml')
}}-${{ steps.date.outputs.date }}
# When we get a cache miss, try finding the most recent previous day's
# cache to start.
restore-keys: |
bazel-${{ matrix.os }}-${{ matrix.build_mode }}-${{ hashFiles('.github/workflows/tests.yaml')
}}-
# Print Bazel diagnostics to make debugging easier.
- name: Print Bazel info
run: |
${{ env.BAZEL }} info
# Build all targets first to isolate build failures.
- name: Build (${{ matrix.build_mode }})
run: |
${{ env.BAZEL }} build -c ${{ matrix.build_mode }} --verbose_failures \
--deleted_packages=migrate_cpp,migrate_cpp/cpp_refactoring \
//...:all
# Run all test targets.
- name: Test (${{ matrix.build_mode }})
run: |
${{ env.BAZEL }} test -c ${{ matrix.build_mode }} --test_output errors \
--deleted_packages=migrate_cpp,migrate_cpp/cpp_refactoring \
--verbose_failures //...:all
# We manually shut down the Bazel server to make sure the cached files
# don't interact with it.
- name: Shutdown Bazel
run: |
${{ env.BAZEL }} shutdown