Skip to content

Building Bazel

linuxonz edited this page Apr 30, 2025 · 31 revisions

Building Bazel

Following instructions specify the steps to build Bazel version 8.2.1 on Linux on IBM Z:

  • Ubuntu (22.04, 24.04, 24.10)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

1. Building Bazel

1.1. Build using script

If you'd like to build Bazel using the manual steps, please go to STEP 1.2.

Use the following commands to build Bazel using the build script. Please make sure you have wget installed.

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Bazel/8.2.1/build_bazel.sh

# Build Bazel
bash build_bazel.sh   [Provide -t option for executing build with tests]

In case of any errors, check logs for more details or go to STEP 1.2 to follow the manual build steps.

1.2. Install dependencies  

  • Set environment variable SOURCE_ROOT:
export SOURCE_ROOT=/<source_root>/
export PATCH_URL="https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Bazel/8.2.1/patch"
sudo apt-get update
source "/etc/os-release"
DISTRO="$ID-$VERSION_ID"
  • Ubuntu (22.04, 24.04, 24.10)
sudo apt-get install -y --no-install-recommends bind9-host build-essential coreutils curl dnsutils ed expect file git gnupg2 iproute2 iputils-ping mkisofs lcov less libssl-dev lsb-release netcat-openbsd openjdk-21-jdk-headless zip zlib1g-dev unzip wget python3 gcc-11 g++-11
sudo ln -sf /usr/bin/python3 /usr/bin/python
sudo ln -sf /usr/bin/python3 /usr/bin/python
sudo ln -sf /usr/bin/gcc-11 /usr/bin/gcc  
sudo ln -sf /usr/bin/g++-11 /usr/bin/g++
sudo ln -sf /usr/bin/gcov-11 /usr/bin/gcov

1.3. Build Bazel

Note: Netty and netty-tcnative jar are needed to fix test case failures related to remote execution. If remote execution functionality is not required then go to "Set JAVA_HOME to JDK21 required for building Bazel" step.

  • Install and build netty-tcnative 2.0.61:
cd $SOURCE_ROOT
wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/netty-tcnative/2.0.61/build_netty.sh
if [[ $DISTRO =~ ^ubuntu-24\.(04|10)$ ]]; then
          sed -i "s/ubuntu-22.04/$DISTRO/g" build_netty.sh
fi
bash build_netty.sh -y
export LD_LIBRARY_PATH=$SOURCE_ROOT/netty-tcnative/openssl-dynamic/target/native-build/.libs/:$LD_LIBRARY_PATH
  • Set JAVA_HOME to JDK21 required for building netty:
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-s390x
export PATH=$JAVA_HOME/bin:$PATH
java -version
  • Build netty 4.1.100:
cd $SOURCE_ROOT
git clone -b netty-4.1.100.Final https://github.com/netty/netty.git
cd netty
mvn clean install -DskipTests
  • Download Bazel 8.2.1 distribution archive:
cd $SOURCE_ROOT
wget https://github.com/bazelbuild/bazel/releases/download/8.2.1/bazel-8.2.1-dist.zip
mkdir -p dist/bazel && cd dist/bazel
unzip -q ../../bazel-8.2.1-dist.zip
chmod -R +w .
  • Build the bootstrap bazel:
cd ${SOURCE_ROOT}/dist/bazel
env EXTRA_BAZEL_ARGS="--java_runtime_version=21 \
    --java_language_version=21 \
    --tool_java_runtime_version=21 \
    --tool_java_language_version=21" \
    bash ./compile.sh
  • Checkout the Bazel 8.2.1 source code and apply the patch:
cd $SOURCE_ROOT
git clone --depth 1 -b 8.2.1 https://github.com/bazelbuild/bazel.git
cd bazel
curl -sSLO $PATCH_URL/bazel.patch
patch -p1 < bazel.patch
rm -f bazel.patch
  • Copy the netty and netty-tcnative jar into the respective bazel directory:
cp $SOURCE_ROOT/netty-tcnative/openssl-classes/target/netty-tcnative-classes-2.0.61.Final.jar \
    $SOURCE_ROOT/netty-tcnative/boringssl-static/target/netty-tcnative-boringssl-static-2.0.61.Final-linux-s390_64.jar \
    $SOURCE_ROOT/netty/buffer/target/netty-buffer-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/codec/target/netty-codec-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/codec-http/target/netty-codec-http-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/codec-http2/target/netty-codec-http2-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/common/target/netty-common-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/handler/target/netty-handler-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/handler-proxy/target/netty-handler-proxy-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/resolver/target/netty-resolver-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/resolver-dns/target/netty-resolver-dns-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/transport/target/netty-transport-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/transport-classes-epoll/target/netty-transport-classes-epoll-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/transport-classes-kqueue/target/netty-transport-classes-kqueue-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/transport-native-unix-common/target/netty-transport-native-unix-common-4.1.100.Final-linux-s390_64.jar \
    $SOURCE_ROOT/netty/transport-native-kqueue/target/netty-transport-native-kqueue-4.1.100.Final.jar \
    $SOURCE_ROOT/netty/transport-native-epoll/target/netty-transport-native-epoll-4.1.100.Final-linux-s390_64.jar \
    $SOURCE_ROOT/bazel/third_party
  • Build Bazel:
cd $SOURCE_ROOT/bazel
${SOURCE_ROOT}/dist/bazel/output/bazel build --enable_bzlmod --lockfile_mode=update -c opt --stamp --embed_label "8.2.1" //src:bazel //src:bazel_jdk_minimal //src:test_repos //src/main/java/...
mkdir output
cp bazel-bin/src/bazel output/bazel
  • Bazel version:
cd $SOURCE_ROOT/bazel
./output/bazel --version
bazel 8.2.1

2. Execute Test Suite (Optional)

  • Run complete test suite:
export LC_ALL=C.UTF-8     #only for ubuntu-24.04
export LANG=en_US.UTF-8   #only for ubuntu-24.04

cd $SOURCE_ROOT/bazel
./output/bazel --host_jvm_args=-Xmx2g test --enable_bzlmod --lockfile_mode=update -c opt --build_tests_only --flaky_test_attempts=1 --test_timeout=3600 --show_progress_rate_limit=5 --terminal_columns=143 --show_timestamps --verbose_failures \
-- //scripts/... //src/java_tools/... //src/main/starlark/tests/builtins_bzl/... //src/test/... //src/tools/execlog/... //src/tools/one_version/... //src/tools/singlejar/... //src/tools/workspacelog/... //third_party/ijar/... //tools/aquery_differ/... //tools/python/... //tools/bash/... \
-//src/test/shell/bazel:bazel_android_tools_test
  • Run individual test:
cd $SOURCE_ROOT/bazel
./output/bazel test --enable_bzlmod --lockfile_mode=update -c opt --cache_test_results=no --build_tests_only --flaky_test_attempts=3 --test_timeout=3600 --show_progress_rate_limit=5 --show_timestamps --verbose_failures -- //<module_name>:<testcase_name>

For example:

cd $SOURCE_ROOT/bazel
./output/bazel test --enable_bzlmod --lockfile_mode=update -c opt --cache_test_results=no --build_tests_only --flaky_test_attempts=3 --test_timeout=3600 --show_progress_rate_limit=5 --show_timestamps --verbose_failures -- //src/test/cpp/util:md5_test

Notes:

1. Some tests have been excluded in the bazel test command above:

  • //src/test/py/bazel:mod_command_test fails as buildozer binary does not have support for s390x.
  • //src/test/shell/bazel:command_profiler_test fails as async-profiler does not have support for s390x.

2. The following test would be skipped, since prebuilt ijar and singlejar binaries haven't been released for s390x:

  • //src/test/shell/bazel:bazel_java_test_defaults_prebuilt

3. The following test would fail unless ipv6 is enabled on the system:

  • //src/test/java/com/google/devtools/build/lib/bazel/bzlmod:BzlmodTests

4. Below test cases fail on both s390x and x86_64 on all distros:

//src/test/java/com/google/devtools/build/lib/bazel/bzlmod:BzlmodTests
//src/test/java/com/google/devtools/build/lib/vfs:VfsTests 
//src/test/shell/bazel:bazel_determinism_test

5. More information on running Bazel in a low memory environment:

3. Use the new module-focused external dependencies management system in Bazel (Optional)

The new module-focused MODULE.bazel system can be enabled by the flag --enable_bzlmod, for example:

cd $SOURCE_ROOT/bazel
./output/bazel build --enable_bzlmod //src:bazel_nojdk

References:

Clone this wiki locally