Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions bazel/external/Dockerfile.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ ARG DEPS_BUILDER="\
ca-certificates \
clang \
curl \
git \
openjdk-21-jdk \
python3 \
unzip \
Expand All @@ -109,15 +108,24 @@ RUN apt-get update && \
mkdir -p /tmp/src/bazel && \
wget --progress=dot:giga -O /tmp/bazel-dist.zip https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-dist.zip && \
unzip /tmp/bazel-dist.zip -d /tmp/src/bazel && \
rm -f /tmp/bazel-dist.zip /tmp/src/bazel/MODULE.bazel.lock
rm -f /tmp/bazel-dist.zip
ENV JAVA_HOME=/usr/lib/jvm/java-21-openjdk-${TARGETARCH}
WORKDIR /tmp/src/bazel
# Patch MODULE.bazel and tools/cpp/unix_cc_configure.bzl to:
# For Bazel v7.7.1 - patch MODULE.bazel and tools/cpp/unix_cc_configure.bzl to:
# - Force bazel_features v1.11.0 (avoids bzlmod macro requirement during bootstrap)
# - Configure C++ toolchain compilation flags to avoid GCC segmentation faults on s390x under QEMU emulation
COPY bazel/external/bazel-v7.7.1.patch /tmp/bazel-v7.7.1.patch
Copy link
Contributor

@mmorel-35 mmorel-35 Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use ARG BAZEL_VERSION to do COPY "bazel/external/bazel-v${BAZEL_VERSION}.patch" /tmp/bazel.patch this will make Dockerfile version agnostic

And use only the patch you need

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does COPY work with non-existing files (we only have patches for v7.7.1 and v9.0.1, but not for 8.x)?

Alternatively, we could just COPY bazel/external/bazel-*.patch /tmp/ and be done with it...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might work.

I'm also wondering if it would be better to have a dedicated project to build this image. Then have branches per bazel major version

RUN git apply /tmp/bazel-v7.7.1.patch && \
rm -rf derived/repository_cache
RUN if [ "${BAZEL_VERSION}" = "7.7.1" ]; then \
patch -p1 </tmp/bazel-v7.7.1.patch; \
rm -rf MODULE.bazel.lock derived/repository_cache; \
fi
# For Bazel v9.0.1 - patch protobuf/upb to fix SIGSEGV on s390x:
# - https://github.com/protocolbuffers/protobuf/pull/25363
# - https://github.com/protocolbuffers/protobuf/pull/25683
COPY bazel/external/bazel-v9.0.1.patch /tmp/bazel-v9.0.1.patch
RUN if [ "${BAZEL_VERSION}" = "9.0.1" ]; then \
patch -p1 </tmp/bazel-v9.0.1.patch; \
fi
# Additional compilation flags for bootstrap build to avoid GCC crashes under QEMU emulation
# Note: .bazelrc is ignored during bootstrap (BAZELRC=/dev/null), so flags must be in EXTRA_BAZEL_ARGS
# Use -c dbg and --host_compilation_mode=dbg to avoid default -O2 from opt mode
Expand All @@ -126,16 +134,16 @@ RUN git apply /tmp/bazel-v7.7.1.patch && \
ENV CC=clang
ENV CXX=clang++
ENV EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk \
--jobs=1 \
--local_ram_resources=2048 \
--jobs=HOST_CPUS*.5 \
--local_resources=memory=8192 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOST_RAM*.5?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't think there is a good reason to keep memory usage limited at all, since the crashes / hangs were all happening because of bugs in QEMU CPU emulation and some race conditions there... On the other hand, it doesn't feel like Bazel should require more than 8 GiB RAM to build itself.

-c dbg \
--host_compilation_mode=dbg \
--copt=-O0 --host_copt=-O0 \
--copt=-g0 --host_copt=-g0"
RUN bash ./compile.sh && \
cp /tmp/src/bazel/output/bazel /tmp/bazel && \
chmod +x /tmp/bazel && \
rm -rf /tmp/src/bazel /tmp/bazel-v7.7.1.patch
rm -rf /tmp/src/bazel /tmp/bazel-*.patch

# Stage 2: minimal runtime for executing tests
FROM ubuntu:${UBUNTU_VERSION} AS test-runtime
Expand Down
28 changes: 28 additions & 0 deletions bazel/external/bazel-v9.0.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/third_party/protobuf.patch b/third_party/protobuf.patch
index 6681897694..90a79a3a99 100644
--- a/third_party/protobuf.patch
+++ b/third_party/protobuf.patch
@@ -45,3 +45,23 @@ index 426bf9124..fd17ac96c 100644
# Amalgamation #################################################################

upb_amalgamation(
+diff --git a/upb/wire/decode.c b/upb/wire/decode.c
+index 6da57877b..3f53a61d4 100644
+--- a/upb/wire/decode.c
++++ b/upb/wire/decode.c
+@@ -488,6 +488,7 @@ static const char* _upb_Decoder_DecodeEnumPacked(
+ _upb_Decoder_AddEnumValueToUnknown(d, msg, field, &elem);
+ continue;
+ }
++ _upb_Decoder_MungeInt32(&elem);
+ if (_upb_Decoder_Reserve(d, arr, 1)) {
+ out = UPB_PTR_AT(upb_Array_MutableDataPtr(arr),
+ arr->UPB_PRIVATE(size) * 4, void);
+@@ -1079,6 +1080,7 @@ const char* _upb_Decoder_DecodeWireValue(upb_Decoder* d, const char* ptr,
+ *op = kUpb_DecodeOp_UnknownField;
+ return ptr;
+ }
++ _upb_Decoder_MungeInt32(val);
+ } else {
+ _upb_Decoder_Munge(field, val);
+ }
Loading