diff --git a/src/s-core-devcontainer/.devcontainer/devcontainer.json b/src/s-core-devcontainer/.devcontainer/devcontainer.json index 17fb611..21899af 100644 --- a/src/s-core-devcontainer/.devcontainer/devcontainer.json +++ b/src/s-core-devcontainer/.devcontainer/devcontainer.json @@ -11,6 +11,7 @@ }, "ghcr.io/devcontainers/features/git-lfs": { // Installs the latest version from the Distribution + "autoPull": "false" // do not automatically pull LFS files when creating the container }, "ghcr.io/devcontainers/features/common-utils": { // Installs latest version from the Distribution diff --git a/src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json b/src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json index 3930707..258723d 100644 --- a/src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json +++ b/src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json @@ -30,7 +30,7 @@ "description": "sha256sums of Bazel Compile Commands to verify the download; format: :;:;..." } }, - "postCreateCommand": "/devcontainer/features/s-core-local/post_create_command.sh", + "onCreateCommand": "/devcontainer/features/s-core-local/on_create_command.sh", "mounts": [ { "source": "${localEnv:HOME}/.cache/bazel", // default Bazel cache directory "target": "/var/cache/bazel", diff --git a/src/s-core-devcontainer/.devcontainer/s-core-local/on_create_command.sh b/src/s-core-devcontainer/.devcontainer/s-core-local/on_create_command.sh new file mode 100755 index 0000000..5f1092d --- /dev/null +++ b/src/s-core-devcontainer/.devcontainer/s-core-local/on_create_command.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +set -euo pipefail + +# ensure that the Bazel cache directory exists +if [ ! -d /var/cache/bazel ]; then + echo "Creating /var/cache/bazel directory..." + # yes, mkdir -p is idempotent, but we want to see the log message + mkdir -p /var/cache/bazel +fi + +# If /var/cache/bazel is not a mountpoint, we assume it is a container-local cache. +# This is the case in codespaces, for example. +# Here, we must ensure that the directory has the correct permissions +# so that Bazel can write to it. +if ! mountpoint -q /var/cache/bazel; then + echo "/var/cache/bazel is not mounted. Using container-local cache and setting permissions." + chown -R "$(id -un):$(id -gn)" /var/cache/bazel +fi + +# Configure Bazel to use the cache directory +# This way, Bazel can re-use an existing cache on the host machine, if mounted. +# Note that in some scenarios (like codespaces), it is not and hence resides in the container. +echo "startup --output_user_root=/var/cache/bazel" >> ~/.bazelrc + +# Configure clangd to remove the -fno-canonical-system-headers flag, which is +# GCC-specific. If not done, there is an annoying error message on the first +# line of every C++ file when being displayed in Visual Studio Code. +mkdir -p ~/.config/clangd +cat > ~/.config/clangd/config.yaml <> ~/.bazelrc - -# ensure that the Bazel cache directory has the correct permissions -sudo chown -R "$(id -un):$(id -gn)" /var/cache/bazel - -# Configure clangd to remove the -fno-canonical-system-headers flag, which is -# GCC-specific. If not done, there is an annoying error message on the first -# line of every C++ file when being displayed in Visual Studio Code. -mkdir -p ~/.config/clangd -cat > ~/.config/clangd/config.yaml <