skia2/toolchain/clang_trampoline.sh
Kevin Lubick fed97e8f40 [bazel] Add RBE support using hermetic Linux Clang toolchain
A new RBE worker-pool called gce_linux was created in
conjunction with this CL. See
https://docs.google.com/document/d/14xMZCKews69SSTfULhE8HDUzT5XvPwZ4CvRufEvcZ74/edit#
for some details on that.

Note: everything under bazel/rbe/gce_linux was autogenerated
and can be ignored from manual review. It basically specifies
what files are on the RBE image that are necessary for running
Bazel.

Testing it out can be done by authenticating for RBE
gcloud auth application-default login --no-browser

Then, run make -C bazel rbe_known_good_builds
to test it out.

On my 4 core laptop with an empty local cache, but a
warm remote cache, the build took <2 min instead of the
10+ minutes it would have [1].

The folder structure in //bazel/rbe is meant to let us
have multiple remote configurations there, e.g.
//bazel/rbe/gce_windows.

Suggested Review Order:
 - bazel/rbe/README.md
 - bazel/rbe/gce_linux_container/Dockerfile to see the
   bare-bones RBE image.
 - bazel/rbe/BUILD.bazel to see a custom platform defined.
   It is nearly identical to the autogenerated one
   in bazel/rbe/gce_linux/config/BUILD, with one extra
   field to force the gce_linux pool to be used.
 - .bazelrc to see the settings needed to make
   --config=linux-rbe work. The naming convention was
   inspired by SkCMS's setup [2], and allows us to have
   some common RBE settings (i.e. config:remote) and
   some specialized ones for the given host machine
   (e.g. config:linux-rbe) A very important, but subtle
   configuration, is on line 86 of .bazelrc where we say
   to use our hermetic toolchain and not whatever C++
   compiler and headers are on the host machine (aka
   the RBE container).
 - toolchain/build_toolchain.bzl to see some additional
   dependencies needed in the toolchain (to run IWYU) which
   I had installed locally but didn't realize were important.
 - third_party/BUILD.bazel to see an example of how failing
   to specify all files can result in something that works
   locally, but fails remotely.
   --execution_log_json_file=/tmp/execlog.json helped debug
   these issues.
 - All other files.

[1] http://go/scrcast/NjM1ODE4MDI0NzM3MTc3Nnw3ODViZmFkMi1iOA
[2] https://skia.googlesource.com/skcms/+/30c8e303800c256febb03a09fdcda7f75d119b1b/.bazelrc#20


Change-Id: Ia0a9e6a06c1a13071949ab402dc5d897df6b12e1
Bug: skia:12541
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/524359
Reviewed-by: Leandro Lovisolo <lovisolo@google.com>
2022-03-28 13:56:16 +00:00

44 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
# Copyright 2021 Google LLC
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
export LD_LIBRARY_PATH="external/clang_linux_amd64/usr/lib/x86_64-linux-gnu:external/clang_linux_amd64/usr/lib/llvm-13/lib"
# If compilation fails, we want to exit right away
set -e
# We only want to run include-what-you-use if SKIA_ENFORCE_IWYU_FOR_THIS_FILE is in the arguments
# passed in (i.e. the "skia_opt_file_into_iwyu" feature is enabled) and we are not linking
# (as detected by the presence of -fuse-ld).
if [[ "$@" != *SKIA_ENFORCE_IWYU_FOR_THIS_FILE* || "$@" == *use-ld* ]]; then
external/clang_linux_amd64/bin/clang $@
exit 0
else
# Now try to compile with Clang, and then verify with IWYU
external/clang_linux_amd64/bin/clang $@
# IWYU always returns a non-zero code because it doesn't produce the .o file (that's why
# we ran Clang first). As such, we do not want bash to fail after running IWYU.
set +e
# Get absolute path to the mapping file because resolving the relative path is tricky, given
# how Bazel locates the toolchain files.
MAPPING_FILE=$(realpath $(dirname ${BASH_SOURCE[0]}))"/IWYU_mapping.imp"
# IWYU always outputs something to stderr, which can be noisy if everything is fixed.
# Otherwise, we send the exact same arguments to include-what-you-use that we would for
# regular compilation with clang.
external/clang_linux_amd64/usr/bin/include-what-you-use \
-Xiwyu --mapping_file=$MAPPING_FILE $@ 2>/dev/null
# IWYU returns 2 if everything looks good. It returns some other non-zero exit code otherwise.
if [ $? -eq 2 ]; then
exit 0 # keep the build going
else
# Run IWYU again, but this time display the output. Then return non-zero to fail the build.
# These flags are a little different, but only in ways that affect what was displayed, not the
# analysis. If we aren't sure why IWYU wants to include something, try changing verbose to 3.
external/clang_linux_amd64/usr/bin/include-what-you-use \
-Xiwyu --mapping_file=$MAPPING_FILE -Xiwyu --no_comments \
-Xiwyu --quoted_includes_first -Xiwyu --verbose=3 $@
exit 1 # fail the build
fi
fi