Skip to content

Commit c2bfb67

Browse files
committed
Extract bazel feature from devcontainer feature
bazel related code is a lot and sould be isolated in a dedicated feature.
1 parent dd1d0c5 commit c2bfb67

15 files changed

Lines changed: 227 additions & 172 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Ordered by importance:
9393

9494
* `src/s-core-devcontainer/` contains the sources for the Eclipse S-CORE DevContainer.
9595
It uses pre-existing [DevContainer features](https://containers.dev/implementors/features/) to provide some standard tools like Git, LLVM, and others.
96-
In addition, it uses a so-called "local" feature (cf. `src/s-core-devcontainer/.devcontainer/s-core-local`) for the remaining tools and configuration.
96+
In addition, it uses so-called "local" features (cf. `src/s-core-devcontainer/.devcontainer/s-core-local`) for the remaining tools and configuration.
9797
* `scripts/` contains scripts to build and test the container.
9898
* `.devcontainer/` contains the definition of the DevContainer for **this** repository, i.e. the "devcontainer devcontainer".
9999
There should rarely be a need to modify this.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "Bazel Tools",
3+
"id": "bazel",
4+
"version": "1.0.0",
5+
"description": "Bazel and supplimentary tools for working with Bazel-based projects.",
6+
"onCreateCommand": "/devcontainer/features/bazel/on_create_command.sh",
7+
"postCreateCommand": {
8+
// The repos in S-CORE may use different Bazel versions. This ensures that the required version is installed.
9+
// Should be removed once we provide versions of the devcontainer.
10+
"Install matching Bazel version": "bash /devcontainer/features/bazel/install_matching_bazel_version.sh"
11+
},
12+
"mounts": [
13+
{
14+
"source": "eclipse-s-core-bazel-cache",
15+
"target": "/var/cache/bazel",
16+
"type": "volume"
17+
}
18+
]
19+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Copy feature sources and tests to expected location
5+
FEATURES_DIR="/devcontainer/features"
6+
SCRIPT_PATH=$(readlink -f "$0")
7+
SCRIPT_DIR=$(dirname -- "${SCRIPT_PATH}")
8+
mkdir -p "${FEATURES_DIR}"
9+
COPY_TARGET="${FEATURES_DIR}/$(basename "${SCRIPT_DIR%%_*}")"
10+
cp -R "${SCRIPT_DIR}" "${COPY_TARGET}"
11+
rm -f "${COPY_TARGET}/devcontainer-features.env" "${COPY_TARGET}/devcontainer-features-install.sh"
12+
13+
DEBIAN_FRONTEND=noninteractive
14+
15+
# Read tool versions + metadata into environment variables
16+
. /devcontainer/features/s-core-local/versions.sh /devcontainer/features/bazel/versions.yaml
17+
18+
ARCHITECTURE=$(dpkg --print-architecture)
19+
20+
apt-get update
21+
22+
# INSTALL CONTAINER BUILD DEPENDENCIES
23+
# Container build dependencies are not pinned, since they are removed anyway after container creation.
24+
apt-get install apt-transport-https -y
25+
26+
# Bazelisk, directly from GitHub
27+
# Using the existing devcontainer feature is not optimal:
28+
# - it does not check the SHA256 checksum of the downloaded file
29+
# - it cannot pre-install a specific version of Bazel, or prepare bash completion
30+
BAZELISK_VARIANT="amd64"
31+
SHA256SUM="${bazelisk_amd64_sha256}"
32+
if [ "${ARCHITECTURE}" = "arm64" ]; then
33+
BAZELISK_VARIANT="arm64"
34+
SHA256SUM="${bazelisk_arm64_sha256}"
35+
fi
36+
curl -L "https://github.com/bazelbuild/bazelisk/releases/download/v${bazelisk_version}/bazelisk-${BAZELISK_VARIANT}.deb" -o /tmp/bazelisk.deb
37+
echo "${SHA256SUM} /tmp/bazelisk.deb" | sha256sum -c - || exit -1
38+
apt-get install -y --no-install-recommends --fix-broken /tmp/bazelisk.deb
39+
rm /tmp/bazelisk.deb
40+
41+
# Pre-install a fixed Bazel version, setup the bash command completion
42+
export USE_BAZEL_VERSION=${bazel_version}
43+
# bazelisk downloads Bazel into the home directory of the user running the command
44+
# lets assume there is only one user in the devcontainer
45+
su $(ls /home) -c "bazel help completion bash > /tmp/bazel-complete.bash"
46+
mkdir -p /etc/bash_completion.d
47+
mv /tmp/bazel-complete.bash /etc/bash_completion.d/bazel-complete.bash
48+
sh -c "echo 'INSTALLED_BAZEL_VERSION=${bazel_version}' >> /devcontainer/features/bazel/bazel_setup.sh"
49+
50+
# Configure Bazel to use system trust store for SSL/TLS connections
51+
# This is required for corporate environments with custom CA certificates
52+
echo 'startup --host_jvm_args=-Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts --host_jvm_args=-Djavax.net.ssl.trustStorePassword=changeit' >> /etc/bazel.bazelrc
53+
54+
# Buildifier, directly from GitHub (apparently no APT repository available)
55+
# The version is pinned to a specific release, and the SHA256 checksum is provided by the devcontainer-features.json file.
56+
BUILDIFIER_VARIANT="amd64"
57+
SHA256SUM="${buildifier_amd64_sha256}"
58+
if [ "${ARCHITECTURE}" = "arm64" ]; then
59+
BUILDIFIER_VARIANT="arm64"
60+
SHA256SUM="${buildifier_arm64_sha256}"
61+
fi
62+
curl -L "https://github.com/bazelbuild/buildtools/releases/download/v${buildifier_version}/buildifier-linux-${BUILDIFIER_VARIANT}" -o /usr/local/bin/buildifier
63+
echo "${SHA256SUM} /usr/local/bin/buildifier" | sha256sum -c - || exit -1
64+
chmod +x /usr/local/bin/buildifier
65+
66+
# Starlark Language Server, directly from GitHub (apparently no APT repository available)
67+
STARPLS_VARIANT="amd64"
68+
SHA256SUM="${starpls_amd64_sha256}"
69+
if [ "${ARCHITECTURE}" = "arm64" ]; then
70+
STARPLS_VARIANT="aarch64"
71+
SHA256SUM="${starpls_arm64_sha256}"
72+
fi
73+
curl -L "https://github.com/withered-magic/starpls/releases/download/v${starpls_version}/starpls-linux-${STARPLS_VARIANT}" -o /usr/local/bin/starpls
74+
echo "${SHA256SUM} /usr/local/bin/starpls" | sha256sum -c - || exit -1
75+
chmod +x /usr/local/bin/starpls
76+
77+
# Code completion for C++ code of Bazel projects
78+
# (see https://github.com/kiron1/bazel-compile-commands)
79+
source /etc/lsb-release
80+
curl -L "https://github.com/kiron1/bazel-compile-commands/releases/download/v${bazel_compile_commands_version}/bazel-compile-commands_${bazel_compile_commands_version}-${DISTRIB_CODENAME}_${ARCHITECTURE}.deb" -o /tmp/bazel-compile-commands.deb
81+
# Extract correct sha256 for current DISTRIB_CODENAME and check
82+
SHA256SUM="${bazel_compile_commands_amd64_sha256}"
83+
if [ "${ARCHITECTURE}" = "arm64" ]; then
84+
SHA256SUM="${bazel_compile_commands_arm64_sha256}"
85+
fi
86+
echo "${SHA256SUM} /tmp/bazel-compile-commands.deb" | sha256sum -c - || exit -1
87+
apt-get install -y --no-install-recommends --fix-broken /tmp/bazel-compile-commands.deb
88+
rm /tmp/bazel-compile-commands.deb
89+
90+
# Cleanup
91+
# REMOVE CONTAINER BUILD DEPENDENCIES
92+
apt-get remove --purge -y apt-transport-https
93+
apt-get autoremove -y
94+
apt-get clean
95+
rm -rf /var/lib/apt/lists/*

src/s-core-devcontainer/.devcontainer/s-core-local/install_matching_bazel_version.sh renamed to src/s-core-devcontainer/.devcontainer/bazel-feature/install_matching_bazel_version.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22
set -eo pipefail
33

4-
. /devcontainer/features/s-core-local/bazel_setup.sh || true
4+
. /devcontainer/features/bazel/bazel_setup.sh || true
55

66
if [ -f .bazelversion ] && [ "$(cat .bazelversion)" != "$INSTALLED_BAZEL_VERSION" ]; then
77
# Pre-install the matching Bazel version, setup the bash command completion
@@ -15,5 +15,5 @@ if [ -f .bazelversion ] && [ "$(cat .bazelversion)" != "$INSTALLED_BAZEL_VERSION
1515

1616
bazel help completion ${bash} > /tmp/bazel-complete.bash
1717
sudo mv /tmp/bazel-complete.bash /etc/bash_completion.d/bazel-complete.bash
18-
echo "INSTALLED_BAZEL_VERSION=$USE_BAZEL_VERSION" | sudo tee /devcontainer/features/s-core-local/bazel_setup.sh
18+
echo "INSTALLED_BAZEL_VERSION=$USE_BAZEL_VERSION" | sudo tee /devcontainer/features/bazel/bazel_setup.sh
1919
fi
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Enable persistent Bazel cache
5+
#
6+
# Usually, a volume is mounted to /var/cache/bazel (see
7+
# devcontainer-feature.json). This shall be used as Bazel cache, which is then
8+
# preserved across container re-starts. Since the volume has a fixed
9+
# name ("eclipse-s-core-bazel-cache"), it is even used across all Eclipse
10+
# S-CORE DevContainer instances.
11+
if [ -d /var/cache/bazel ]; then
12+
echo "Bazel Cache: /var/cache/bazel exists. Checking ownership and configuring Bazel to use it as cache..."
13+
current_owner_group=$(stat -c "%U:%G" /var/cache/bazel)
14+
current_user_group="$(id -un):$(id -gn)"
15+
if [ "${current_owner_group}" = "${current_user_group}" ]; then
16+
echo "Bazel Cache: /var/cache/bazel is already owned by ${current_user_group}. "
17+
else
18+
echo "Bazel Cache: /var/cache/bazel is not owned by ${current_owner_group}. Setting ownership (this may take a few seconds) ..."
19+
sudo chown -R "${current_user_group}" /var/cache/bazel
20+
fi
21+
echo "Bazel Cache: Configuring Bazel to use /var/cache/bazel as cache..."
22+
echo "startup --output_user_root=/var/cache/bazel" >> ~/.bazelrc
23+
fi
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Read tool versions + metadata into environment variables
5+
. /devcontainer/features/s-core-local/versions.sh /devcontainer/features/bazel/versions.yaml
6+
7+
# Bazel-related tools
8+
## This is the bazel version preinstalled in the devcontainer.
9+
## A solid test would disable the network interface first to prevent a different version from being downloaded,
10+
## but that requires CAP_NET_ADMIN, which is not yet added.
11+
export USE_BAZEL_VERSION=${bazel_version}
12+
check "validate bazelisk is working and has the correct version" bash -c "bazelisk version | grep '${bazelisk_version}'"
13+
check "validate bazel is working and has the correct version" bash -c "bazel version | grep '${bazel_version}'"
14+
unset USE_BAZEL_VERSION
15+
16+
check "validate buildifier is working and has the correct version" bash -c "buildifier --version | grep '${buildifier_version}'"
17+
check "validate starpls is working and has the correct version" bash -c "starpls version | grep '${starpls_version}'"
18+
check "validate bazel-compile-commands is working and has the correct version" bash -c "bazel-compile-commands --version 2>&1 | grep '${bazel_compile_commands_version}'"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
bazel:
2+
# https://github.com/bazelbuild/bazel/releases -- latest version as of 2025-09-24
3+
version: 8.4.1
4+
# no need to define sha256 here, as bazel is installed via bazelisk
5+
6+
buildifier:
7+
version: 8.2.1
8+
amd64:
9+
# The following sha256sum is for the binary buildifier-linux-amd64
10+
# from the GitHub release page of buildtools
11+
# It is generated by running 'sha256sum buildifier-linux-amd64'
12+
sha256: 6ceb7b0ab7cf66fceccc56a027d21d9cc557a7f34af37d2101edb56b92fcfa1a
13+
arm64:
14+
# The following sha256sum is for the binary buildifier-linux-arm64
15+
# from the GitHub release page of buildtools
16+
# It is generated by running 'sha256sum buildifier-linux-arm64'
17+
sha256: 3baa1cf7eb41d51f462fdd1fff3a6a4d81d757275d05b2dd5f48671284e9a1a5
18+
19+
bazelisk:
20+
version: 1.27.0
21+
amd64:
22+
# The following sha256sums are for the deb package bazelisk_<version>_amd64.deb
23+
# It is generated by running 'sha256sum bazelisk_<version>_amd64.deb'
24+
sha256: d8b00ea975c823e15263c80200ac42979e17368547fbff4ab177af035badfa83
25+
arm64:
26+
# The following sha256sums are for the deb package bazelisk_<version>_arm64.deb
27+
# It is generated by running 'sha256sum bazelisk_<version>_arm64.deb'
28+
sha256: 173c5b367b485a30ce58c1d0d560b39d257a2d7a3c859c45d7d05eb61605a2a1
29+
30+
starpls:
31+
version: 0.1.22
32+
amd64:
33+
# The following sha256sum is for the binary starpls-linux-amd64
34+
# from the GitHub release page of starpls
35+
# It is generated by running 'sha256sum starpls-linux-amd64'
36+
sha256: 7c661cdde0d1c026665086d07523d825671e29056276681616bb32d0273c5eab
37+
arm64:
38+
# The following sha256sum is for the binary starpls-linux-arm64
39+
# from the GitHub release page of starpls
40+
# It is generated by running 'sha256sum starpls-linux-arm64'
41+
sha256: 55877ec4c3ff03e1d90d59c76f69a3a144b6c29688747c8ac4d77993e2eef1ad
42+
43+
bazel_compile_commands:
44+
version: 0.18.0
45+
amd64:
46+
# The following sha256sums are for the deb package bazel-compile-commands_<version>-noble_amd64.deb
47+
# It is generated by running 'sha256sum bazel-compile-commands_<version>-noble_amd64.deb'
48+
sha256: 6735ea846241497094719792ad3d4f67b1d3123048693d34fcdf7190f8c2da4e
49+
arm64:
50+
# The following sha256sums are for the deb package bazel-compile-commands_<version>-noble_arm64.deb
51+
# It is generated by running 'sha256sum bazel-compile-commands_<version>-noble_arm64.deb'
52+
sha256: d73998efa01cbd501b82ad6266642464b78ecd9fc6224a60c9cb558182d52d88

src/s-core-devcontainer/.devcontainer/devcontainer.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,19 @@
3737
"rustfmt"
3838
]
3939
},
40-
"./s-core-local": {}
40+
"./s-core-local": {},
41+
"./bazel-feature": {}
4142
},
4243
"overrideFeatureInstallOrder": [
43-
// this order makes it more convenient to develop the s-core-local feature, since it will be installed last
44+
// this order makes it more convenient to develop the local features, since they will be installed last
4445
// which means changes to it will be applied without needing to rebuild all other features
4546
"ghcr.io/devcontainers/features/common-utils",
4647
"ghcr.io/devcontainers-community/features/llvm",
4748
"ghcr.io/devcontainers/features/rust",
48-
"./s-core-local"
49+
"./s-core-local",
50+
"./bazel-feature"
4951
],
5052
"remoteUser": "vscode",
51-
5253
"customizations": {
5354
"vscode": {
5455
"extensions": [

src/s-core-devcontainer/.devcontainer/s-core-local/devcontainer-feature.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,9 @@
55
"description": "Tools which are not available as already existing development container feature",
66
"onCreateCommand": "/devcontainer/features/s-core-local/on_create_command.sh",
77
"postCreateCommand": {
8-
// The repos in S-CORE may use different Bazel versions. This ensures that the required version is installed.
9-
// Should be removed once we provide versions of the devcontainer.
10-
"Install matching Bazel version": "bash /devcontainer/features/s-core-local/install_matching_bazel_version.sh",
118
"Setup persistent bash history": "bash /devcontainer/features/s-core-local/setup_command_history.sh"
129
},
1310
"mounts": [
14-
{
15-
"source": "eclipse-s-core-bazel-cache",
16-
"target": "/var/cache/bazel",
17-
"type": "volume"
18-
},
1911
{
2012
"source": "eclipse-s-core-bash-history-${devcontainerId}",
2113
"target": "/commandhistory",

src/s-core-devcontainer/.devcontainer/s-core-local/install.sh

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ rm -f "${COPY_TARGET}/devcontainer-features.env" "${COPY_TARGET}/devcontainer-fe
1313
DEBIAN_FRONTEND=noninteractive
1414

1515
# Read tool versions + metadata into environment variables
16-
. /devcontainer/features/s-core-local/versions.sh
16+
. /devcontainer/features/s-core-local/versions.sh /devcontainer/features/s-core-local/versions.yaml
1717

1818
ARCHITECTURE=$(dpkg --print-architecture)
1919

@@ -47,70 +47,6 @@ apt-get install -y ca-certificates-java openjdk-21-jdk-headless="${openjdk_21_ve
4747
export JAVA_HOME="$(dirname $(dirname $(realpath $(which javac))))"
4848
echo "export JAVA_HOME=\"$(dirname $(dirname $(realpath $(which javac))))\"" > /etc/profile.d/java_home.sh
4949

50-
# Bazelisk, directly from GitHub
51-
# Using the existing devcontainer feature is not optimal:
52-
# - it does not check the SHA256 checksum of the downloaded file
53-
# - it cannot pre-install a specific version of Bazel, or prepare bash completion
54-
BAZELISK_VARIANT="amd64"
55-
SHA256SUM="${bazelisk_amd64_sha256}"
56-
if [ "${ARCHITECTURE}" = "arm64" ]; then
57-
BAZELISK_VARIANT="arm64"
58-
SHA256SUM="${bazelisk_arm64_sha256}"
59-
fi
60-
curl -L "https://github.com/bazelbuild/bazelisk/releases/download/v${bazelisk_version}/bazelisk-${BAZELISK_VARIANT}.deb" -o /tmp/bazelisk.deb
61-
echo "${SHA256SUM} /tmp/bazelisk.deb" | sha256sum -c - || exit -1
62-
apt-get install -y --no-install-recommends --fix-broken /tmp/bazelisk.deb
63-
rm /tmp/bazelisk.deb
64-
65-
# Pre-install a fixed Bazel version, setup the bash command completion
66-
export USE_BAZEL_VERSION=${bazel_version}
67-
# bazelisk downloads Bazel into the home directory of the user running the command
68-
# lets assume there is only one user in the devcontainer
69-
su $(ls /home) -c "bazel help completion bash > /tmp/bazel-complete.bash"
70-
mkdir -p /etc/bash_completion.d
71-
mv /tmp/bazel-complete.bash /etc/bash_completion.d/bazel-complete.bash
72-
sh -c "echo 'INSTALLED_BAZEL_VERSION=${bazel_version}' >> /devcontainer/features/s-core-local/bazel_setup.sh"
73-
74-
# Configure Bazel to use system trust store for SSL/TLS connections
75-
# This is required for corporate environments with custom CA certificates
76-
echo 'startup --host_jvm_args=-Djavax.net.ssl.trustStore=/etc/ssl/certs/java/cacerts --host_jvm_args=-Djavax.net.ssl.trustStorePassword=changeit' >> /etc/bazel.bazelrc
77-
78-
# Buildifier, directly from GitHub (apparently no APT repository available)
79-
# The version is pinned to a specific release, and the SHA256 checksum is provided by the devcontainer-features.json file.
80-
BUILDIFIER_VARIANT="amd64"
81-
SHA256SUM="${buildifier_amd64_sha256}"
82-
if [ "${ARCHITECTURE}" = "arm64" ]; then
83-
BUILDIFIER_VARIANT="arm64"
84-
SHA256SUM="${buildifier_arm64_sha256}"
85-
fi
86-
curl -L "https://github.com/bazelbuild/buildtools/releases/download/v${buildifier_version}/buildifier-linux-${BUILDIFIER_VARIANT}" -o /usr/local/bin/buildifier
87-
echo "${SHA256SUM} /usr/local/bin/buildifier" | sha256sum -c - || exit -1
88-
chmod +x /usr/local/bin/buildifier
89-
90-
# Starlark Language Server, directly from GitHub (apparently no APT repository available)
91-
STARPLS_VARIANT="amd64"
92-
SHA256SUM="${starpls_amd64_sha256}"
93-
if [ "${ARCHITECTURE}" = "arm64" ]; then
94-
STARPLS_VARIANT="aarch64"
95-
SHA256SUM="${starpls_arm64_sha256}"
96-
fi
97-
curl -L "https://github.com/withered-magic/starpls/releases/download/v${starpls_version}/starpls-linux-${STARPLS_VARIANT}" -o /usr/local/bin/starpls
98-
echo "${SHA256SUM} /usr/local/bin/starpls" | sha256sum -c - || exit -1
99-
chmod +x /usr/local/bin/starpls
100-
101-
# Code completion for C++ code of Bazel projects
102-
# (see https://github.com/kiron1/bazel-compile-commands)
103-
source /etc/lsb-release
104-
curl -L "https://github.com/kiron1/bazel-compile-commands/releases/download/v${bazel_compile_commands_version}/bazel-compile-commands_${bazel_compile_commands_version}-${DISTRIB_CODENAME}_${ARCHITECTURE}.deb" -o /tmp/bazel-compile-commands.deb
105-
# Extract correct sha256 for current DISTRIB_CODENAME and check
106-
SHA256SUM="${bazel_compile_commands_amd64_sha256}"
107-
if [ "${ARCHITECTURE}" = "arm64" ]; then
108-
SHA256SUM="${bazel_compile_commands_arm64_sha256}"
109-
fi
110-
echo "${SHA256SUM} /tmp/bazel-compile-commands.deb" | sha256sum -c - || exit -1
111-
apt-get install -y --no-install-recommends --fix-broken /tmp/bazel-compile-commands.deb
112-
rm /tmp/bazel-compile-commands.deb
113-
11450
# qemu-system-arm
11551
apt-get install -y --no-install-recommends --fix-broken qemu-system-arm="${qemu_system_arm_version}*"
11652

0 commit comments

Comments
 (0)