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

Building Envoy

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

  • RHEL (8.10, 9.4)
  • SLES 15 SP6
  • 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.

Build and Install Envoy

1. Build using script

If you want to build Envoy using manual steps, go to Step 2.

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

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Envoy/1.31.2/build_envoy.sh

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

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

2. Install Dependencies

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

2.1. Install Basic Dependencies

  • RHEL (8.10, 9.4)

    sudo yum install -y wget curl zip unzip patch clang-14.0.6 llvm-devel-14.0.6 gcc-toolset-12-gcc gcc-toolset-12-gcc-c++ gcc-toolset-12-libstdc++-devel gcc-toolset-12-binutils-devel gcc-toolset-12-binutils-gold gcc-toolset-12-annobin-plugin-gcc gcc-toolset-12-libatomic-devel pkgconf-pkg-config openssl-devel java-11-openjdk-devel python3.11
    
    # set gcc 12 as default
    source /opt/rh/gcc-toolset-12/enable
    
    # set JAVA_HOME location
    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk
    export PATH=$JAVA_HOME/bin:$PATH
    

    Note: Add the '--allowerasing' option to the yum command above if any dependency conflicts are encountered for RHEL 9.*.

  • SLES 15 SP6

    sudo zypper addrepo --priority 199 http://download.opensuse.org/distribution/leap/15.6/repo/oss/ oss
    sudo zypper --gpg-auto-import-keys refresh -r oss
    
    sudo zypper install -y awk autoconf curl libtool patch pkg-config wget git gcc-c++ gcc12-c++ clang14 llvm14-devel binutils-gold gzip make cmake python311 java-11-openjdk-devel unzip zip tar xz libopenssl-devel
    
    # set JAVA_HOME location
    export JAVA_HOME=/usr/lib64/jvm/java-11-openjdk
    export PATH=$JAVA_HOME/bin:$PATH
    
  • Ubuntu 22.04

    sudo apt-get update
    sudo apt-get install -y autoconf curl git libtool patch python3-pip unzip virtualenv pkg-config locales libssl-dev build-essential openjdk-11-jdk-headless python2 python2-dev python3 python3-dev zip
    
    # Install GCC 12 from repo
    sudo apt-get install -y gcc-12 g++-12
    
    sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-12 12
    sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 12
    sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-12 12
    sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-12 12
    
    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-s390x
    export PATH=$JAVA_HOME/bin:$PATH
    
  • Ubuntu (24.04, 24.10)

    sudo apt-get update
    sudo apt-get install -y autoconf curl git libtool patch python3-pip unzip virtualenv pkg-config locales clang-14 gcc g++ libstdc++-12-dev openssl libssl-dev build-essential openjdk-11-jdk-headless python3 zip unzip
    
    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-s390x
    export PATH=$JAVA_HOME/bin:$PATH
    

2.2. Install Bazel 6.5.0

cd $SOURCE_ROOT
mkdir bazel && cd bazel
wget https://github.com/bazelbuild/bazel/releases/download/6.3.2/bazel-6.3.2-dist.zip
unzip -q bazel-6.3.2-dist.zip
chmod -R +w .
curl -sSL https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/Bazel/6.3.2/patch/bazel.patch | patch -p1
bash ./compile.sh

export PATH=$PATH:${SOURCE_ROOT}/bazel/output/

2.3. Install Clang (Only for Ubuntu 22.04)

cd "$SOURCE_ROOT"
sudo apt-get update
sudo apt-get install -y lsb-release wget software-properties-common gnupg
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 14

2.4. Install Rust

cd $SOURCE_ROOT
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh /dev/stdin -y
export PATH="$HOME/.cargo/bin:$PATH"

2.5. Set locale (Ubuntu Only)

sudo locale-gen en_US.UTF-8
export LC_ALL=C
unset LANGUAGE

2.6. Install Go 1.23.1

cd "$SOURCE_ROOT"
wget -q https://golang.org/dl/go1.23.1.linux-s390x.tar.gz
chmod ugo+r go1.23.1.linux-s390x.tar.gz
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf go1.23.1.linux-s390x.tar.gz
export PATH=/usr/local/go/bin:$PATH
go version

2.7. Setup GCC libstdc++ 12 for use with Clang (Only for Ubuntu 24.04 and 24.10)

  • Ubuntu (24.04, 24.10)
    sudo ln -s "/usr/include/s390x-linux-gnu/c++/12" "/usr/include/s390x-linux-gnu/c++/99"
    sudo ln -s "/usr/include/c++/12" "/usr/include/c++/99"
    sudo ln -s "/usr/lib/gcc/s390x-linux-gnu/12" "/usr/lib/gcc/s390x-linux-gnu/99"
    

3. Build and Install Envoy

  • Download Envoy and Apply Patches

    cd "$SOURCE_ROOT"/
    git clone --depth 1 -b 1.31.2 https://github.com/envoyproxy/envoy.git
    cd envoy
    
    ./bazel/setup_clang.sh "/usr" ### For RHEL and SLES only
    ./bazel/setup_clang.sh "/usr/lib/llvm-14" ### For Ubuntu only
    
    # Apply patches to allow envoy to build
    curl -sSL https://github.com/envoyproxy/envoy/commit/55b0fc45cfdc2c0df002690606853540cf794fab.patch | git apply -
    curl -sSL $PATCH_URL/envoy-build.patch | git apply -
    
    # Apply patches for failing tests
    curl -sSL $PATCH_URL/envoy-test.patch | git apply -
    curl -sSL https://github.com/envoyproxy/envoy/commit/f6a84d8c66c1346063c32d046b56e52b28b4da9a.patch | git apply -
    
    # Move patch files to envoy/bazel which will be applied to external packages while building envoy
    curl -sSL $PATCH_URL/boringssl-s390x.patch > $SOURCE_ROOT/envoy/bazel/boringssl-s390x.patch
    curl -sSL $PATCH_URL/cel-cpp-memory.patch > $SOURCE_ROOT/envoy/bazel/cel-cpp-memory.patch
    curl -sSL $PATCH_URL/cel-cpp-json.patch > $SOURCE_ROOT/envoy/bazel/cel-cpp-json.patch
    curl -sSL $PATCH_URL/grpc-s390x.patch > $SOURCE_ROOT/envoy/bazel/grpc-s390x.patch
    curl -sSL $PATCH_URL/rules_foreign_cc-s390x.patch > $SOURCE_ROOT/envoy/bazel/rules_foreign_cc-s390x.patch
    curl -sSL https://github.com/iii-i/moonjit/commit/db9c993d2ffcf09b3995b8949bb8f5026e610857.patch > $SOURCE_ROOT/envoy/bazel/foreign_cc/luajit-s390x.patch
    curl -sSL https://github.com/iii-i/moonjit/commit/e0728b5f0616088db6f7856b5eaba91625e23577.patch >> $SOURCE_ROOT/envoy/bazel/foreign_cc/luajit-s390x.patch
    curl -sSL $PATCH_URL/luajit-as.patch > $SOURCE_ROOT/envoy/bazel/foreign_cc/luajit-as.patch
    curl -sSL $PATCH_URL/quiche-s390x.patch > $SOURCE_ROOT/envoy/bazel/quiche-s390x.patch
    
  • Build Envoy

    bazel build envoy -c opt --config=clang --test_env=HEAPCHECK= 
    

The binary will be generated in $SOURCE_ROOT/envoy/bazel-bin/source/exe/envoy-static.

  • Verify the version of Envoy
    $SOURCE_ROOT/envoy/bazel-bin/source/exe/envoy-static --version
    
    Output should be similar to:
    bazel-bin/source/exe/envoy-static  version: cc4a75482810de4b84c301d13deb551bd3147339/1.31.2/Modified/RELEASE/BoringSSL
    

4. Test (optional)

cd $SOURCE_ROOT/envoy
  • Run Tests
    bazel test //test/... -c opt --config=clang --keep_going
    

Notes:

  • Below mentioned test failures are observed on all distros on Intel and s390x:

    • //test/extensions/filters/listener/original_dst:original_dst_integration_test: To fix the test, follow official doc to set up the original_dst filter for a quick manual test. To run this test after applying this fix, the following command can be used.

      bazel test //test/extensions/filters/listener/original_dst:original_dst_integration_test -c opt --config=clang --test_env=HEAPCHECK= 
      
    • //test/extensions/tracers/dynamic_ot:dynamic_opentracing_driver_impl_test: The test can pass by adding --linkopt=-lstdc++ to bazel as discussed here .

  • Below mentioned test failure is observed on all RHEL and SLES distros on Intel and s390x:

    //test/config_test:example_configs_test: This test fails because the file "/etc/ssl/certs/ca-certificates.crt" only exists on debian like systems.

  • Some tests might timeout as they are being run with heap checker enabled in "normal" mode. Heap checker can be disabled using below test command:

    bazel test //test/... -c opt --config=clang --keep_going --test_env=HEAPCHECK= 
    

References: