Building CockroachDB - linux-on-ibm-z/docs GitHub Wiki

Building CockroachDB

The instructions provided below specify the steps to build CockroachDB version 25.4.2 on Linux on IBM Z for the following distributions:

  • RHEL (8.10, 9.4, 9.6, 9.7, 10.0, 10.1)
  • Ubuntu (22.04, 24.04, 25.10)

Important Notes:

  • You need to enable the EPEL repositories on RHEL distros. This can be done by installing the epel-release package:

    • RHEL 8.10

      sudo subscription-manager repos --enable codeready-builder-for-rhel-8-$(arch)-rpms
      sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
    • RHEL (9.4, 9.6, 9.7)

      sudo subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rpms
      sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
    • RHEL (10.0, 10.1)

      sudo subscription-manager repos --enable codeready-builder-for-rhel-10-$(arch)-rpms
      sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-10.noarch.rpm

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. Build using script

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

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

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/CockroachDB/25.4.2/build_crdb.sh

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

If the build completes successfully, go to STEP 5. In case of error, check logs for more details or go to STEP 2 to follow manual build steps

2. Install the Dependencies

export SOURCE_ROOT=/<source_root>/
export PATCH_URL=https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/CockroachDB/25.4.2/patch

2.1. Install Basic Dependencies

  • RHEL 8.10

    sudo yum install -y gcc-c++ git ncurses-devel make cmake automake bison patch wget tar xz zip unzip java-21-openjdk-devel python3 zlib-devel diffutils libtool libarchive openssl-devel keyutils-libs-devel bsdtar
  • RHEL (9.4, 9.6, 9.7, 10.0, 10.1)

    sudo yum install -y gcc-c++ git ncurses-devel make cmake automake bison patch wget tar xz zip unzip java-21-openjdk-devel python3 zlib-devel diffutils libtool libarchive keyutils-libs-devel bsdtar
  • Ubuntu 22.04

    sudo apt-get update && sudo apt-get -y install zip unzip autoconf automake wget make libssl-dev libncurses5-dev bison xz-utils patch g++ curl git python3 cmake netbase libresolv-wrapper libkeyutils-dev openjdk-21-jdk libarchive-tools
  • Ubuntu (24.04)

    sudo apt-get update && sudo apt-get -y install zip unzip autoconf automake wget make libssl-dev libncurses5-dev bison xz-utils patch g++ curl git python3 cmake netbase libresolv-wrapper libkeyutils-dev openjdk-21-jdk bzip2 libarchive-tools
  • Ubuntu 25.10

    sudo apt-get update && sudo apt-get -y install zip unzip autoconf automake wget make libssl-dev libncurses5-dev bison xz-utils patch g++-14 gcc-14 curl git python3 cmake netbase libresolv-wrapper libkeyutils-dev openjdk-21-jdk bzip2 libarchive-tools
    export CC=gcc-14
    export CXX=g++-14

2.2. Change TzData EST timezone on RHEL and ubuntu 25.10

cd $SOURCE_ROOT   
cat > pure_est.txt <<EOF
# Zone  NAME            STDOFF  RULES   FORMAT
Zone    PureEST         -5:00   -       EST
EOF
zic -b fat -d . pure_est.txt
sudo cp ./PureEST /usr/share/zoneinfo/EST

2.3. Build and Install Bazel

cd $SOURCE_ROOT
git clone -b 7.6.1 https://github.com/bazelbuild/rules_java.git
cd rules_java
curl -sSL https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Bazel/7.2.1/patch/rules_java_7.6.1.patch | git apply || error "Patch rules_java v7.6.1"
cd $SOURCE_ROOT
git clone -b v0.11.1 https://github.com/sgammon/rules_graalvm
cd rules_graalvm
curl -sSL https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Bazel/7.2.1/patch/rules_graalvm_0.11.1.patch | git apply || error "Patch graalvm v0.11.1"
mkdir -p $SOURCE_ROOT/bazel
cd $SOURCE_ROOT/bazel
wget https://github.com/bazelbuild/bazel/releases/download/7.2.1/bazel-7.2.1-dist.zip
unzip -q bazel-7.2.1-dist.zip
chmod -R +w .
curl -sSLO https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Bazel/7.2.1/patch/bazel.patch
sed -i '368,$d' bazel.patch
sed -i "s#RULES_JAVA_ROOT_PATH#$SOURCE_ROOT#g" bazel.patch
patch -p1 < bazel.patch || error "Patch bazel"
# only on RHEL 10.0 and RHEL 9.6
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk && export PATH=$JAVA_HOME/bin:$PATH
# only on Ubuntu 25.10
export JAVA_HOME=/usr/lib/jvm/java-21-openjdk-s390x && export PATH=$JAVA_HOME/bin:$PATH
env EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk" bash ./compile.sh

export PATH=$PATH:$SOURCE_ROOT/bazel/output/
bazel --version

2.4. Build and Install resolv_wrapper (RHEL only)

cd $SOURCE_ROOT
wget https://ftp.samba.org/pub/cwrap/resolv_wrapper-1.1.8.tar.gz
tar zxf resolv_wrapper-1.1.8.tar.gz
cd resolv_wrapper-1.1.8
mkdir obj && cd obj
cmake -DCMAKE_INSTALL_PREFIX=/usr ..
make
sudo make install

2.5. Build and Install Bazel-lib

cd $SOURCE_ROOT
git clone -b v1.42.3 https://github.com/aspect-build/bazel-lib.git
cd bazel-lib/
value=($(sha256sum /usr/bin/bsdtar))
wget -O $SOURCE_ROOT/bazel-lib.patch $PATCH_URL/bazel-lib.patch
sed -i "s#BSDTAR_SHA256SUM#$value#g" $SOURCE_ROOT/bazel-lib.patch
git apply --reject --whitespace=fix $SOURCE_ROOT/bazel-lib.patch
bazel build @aspect_bazel_lib//tools/copy_directory
bazel build @aspect_bazel_lib//tools/copy_to_directory

3. Build and Install CockroachDB

  • Download source code

    cd $SOURCE_ROOT
    git clone -b v25.4.2 --depth 1 https://github.com/cockroachdb/cockroach.git
    cd cockroach
  • Apply patches to code using below commands:

    cd $SOURCE_ROOT/cockroach
    mkdir patch && cd patch
    cp $SOURCE_ROOT/bazel-lib.patch .
    cat <<EOF >BUILD
    filegroup(
        name = "bazel-lib.patch",
        srcs = ["bazel-lib.patch"],
    )
    EOF
    cd $SOURCE_ROOT/cockroach
    wget -O $SOURCE_ROOT/crdb.patch $PATCH_URL/crdb.patch
    git apply --reject --whitespace=fix $SOURCE_ROOT/crdb.patch
  • Build and install

    cd $SOURCE_ROOT/cockroach
    echo 'build --remote_cache=http://127.0.0.1:9867' > .bazelrc.user
    echo 'build --config=dev
    build --config nolintonbuild' >> .bazelrc.user
    echo "test --test_tmpdir=$SOURCE_ROOT/cockroach/tmp" >> .bazelrc.user
    ./dev doctor
    ./dev build
    # only on RHEL 10.0, Ubuntu 24.04 and Ubuntu 25.10
    sed -i '/#include/ a #include <cstdint>' $SOURCE_ROOT/cockroach/c-deps/geos/include/geos/shape/fractal/HilbertEncoder.h
    bazel build c-deps:libgeos --config force_build_cdeps
    sudo cp cockroach /usr/local/bin
    sudo mkdir -p /usr/local/lib/cockroach
    sudo cp _bazel/bin/c-deps/libgeos_foreign/lib/libgeos.so /usr/local/lib/cockroach/
    sudo cp _bazel/bin/c-deps/libgeos_foreign/lib/libgeos_c.so /usr/local/lib/cockroach/
    export PATH=$SOURCE_ROOT/cockroach:$PATH

4. Testing (Optional)

cd $SOURCE_ROOT/cockroach
./dev test -v -- --test_timeout=3600

Note:

  • Some test cases might experience time out problem. They should pass after increasing the timeout and running the test again. And remaining test cases will pass on re-run.

5. Verify

cockroach version

Output should look like:

Build Tag:        v25.4.2-dev
Build Time:
Distribution:     CCL
Platform:         linux s390x
Go Version:       go1.25.4 X:nocoverageredesign
C Compiler:       gcc 13.3.0
Build Commit ID:
Build Type:
Enabled Assertions: false

Please visit this link to start a local cluster and CockroachDB SQL.

References:

⚠️ **GitHub.com Fallback** ⚠️