|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# ensure that the Bazel cache directory exists |
| 5 | +if [ ! -d /var/cache/bazel ]; then |
| 6 | + echo "Creating /var/cache/bazel directory..." |
| 7 | + # yes, mkdir -p is idempotent, but we want to see the log message |
| 8 | + mkdir -p /var/cache/bazel |
| 9 | +fi |
| 10 | + |
| 11 | +# If /var/cache/bazel is not a mountpoint, we assume it is a container-local cache. |
| 12 | +# This is the case in codespaces, for example. |
| 13 | +# Here, we must ensure that the directory has the correct permissions |
| 14 | +# so that Bazel can write to it. |
| 15 | +if ! mountpoint -q /var/cache/bazel; then |
| 16 | + echo "/var/cache/bazel is not mounted. Using container-local cache and setting permissions." |
| 17 | + chown -R "$(id -un):$(id -gn)" /var/cache/bazel |
| 18 | +fi |
| 19 | + |
| 20 | +# Configure Bazel to use the cache directory |
| 21 | +# This way, Bazel can re-use an existing cache on the host machine, if mounted. |
| 22 | +# Note that in some scenarios (like codespaces), it is not and hence resides in the container. |
| 23 | +echo "startup --output_user_root=/var/cache/bazel" >> ~/.bazelrc |
| 24 | + |
| 25 | +# Configure clangd to remove the -fno-canonical-system-headers flag, which is |
| 26 | +# GCC-specific. If not done, there is an annoying error message on the first |
| 27 | +# line of every C++ file when being displayed in Visual Studio Code. |
| 28 | +mkdir -p ~/.config/clangd |
| 29 | +cat > ~/.config/clangd/config.yaml <<EOF |
| 30 | +CompileFlags: |
| 31 | + Remove: |
| 32 | + - -fno-canonical-system-headers |
| 33 | +EOF |
0 commit comments