Skip to content

Building Envoy

linuxonz edited this page Nov 14, 2024 · 5 revisions

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.8, 8.10, 9.2, 9.4)
  • SLES (15 SP5, 15 SP6)
  • Ubuntu (20.04, 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

Step 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.

Step 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/"

Step 2.1) Install Basic Dependencies

  • RHEL (8.8, 8.10, 9.2, 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 SP5, 15 SP6)

    sudo zypper addrepo --priority 199 http://download.opensuse.org/distribution/leap/15.6/repo/oss/ oss ### For SLES 15.6 only
    sudo zypper --gpg-auto-import-keys refresh -r oss ### For SLES 15.6 only
    
    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 20.04

    sudo apt-get update
    sudo apt-get install -y autoconf curl git libtool patch python3-pip virtualenv pkg-config gcc g++ locales build-essential openjdk-11-jdk-headless python2 python2-dev python-is-python3 python3 python3-dev zip unzip libssl-dev texinfo
    
    export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-s390x
    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

Step 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/

Step 2.3) Install Binutils and GCC (Only for Ubuntu 20.04)

  • Binutils

    cd "$SOURCE_ROOT"
    
    curl -sSL https://ftp.gnu.org/gnu/binutils/binutils-2.38.tar.gz | tar xzf -
    cd binutils-2.38
    mkdir objdir
    cd objdir
    
    CC=/usr/bin/gcc ../configure --prefix=/usr --build=s390x-linux-gnu --enable-gold --program-prefix="s390x-linux-gnu-"
    make -j "$(nproc)"
    sudo make install
  • GCC

    cd "$SOURCE_ROOT"
    curl -sSL https://ftp.gnu.org/gnu/gcc/gcc-12.3.0/gcc-12.3.0.tar.gz | tar xzf -
    
    cd gcc-12.3.0
    ./contrib/download_prerequisites
    mkdir objdir && cd objdir
    
    ../configure --enable-languages=c++ --prefix=/usr/local \
      --program-suffix=-12 \
      --enable-shared --enable-threads=posix \
      --disable-multilib --disable-libmpx \
      --with-system-zlib --with-long-double-128 --with-arch=z13 \
      --disable-libphobos --disable-werror \
      --with-gcc-major-version-only \
      --build=s390x-linux-gnu --host=s390x-linux-gnu --target=s390x-linux-gnu
    
    make -j "$(nproc)" bootstrap
    sudo make install
    
    LD_LIBRARY_PATH=${GCC_INSTALL_DIR}/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
    export LD_LIBRARY_PATH
    
    LD_RUN_PATH=${GCC_INSTALL_DIR}/lib64${LD_RUN_PATH:+:${LD_RUN_PATH}}
    export LD_RUN_PATH

Step 2.4) Install Clang (Only for Ubuntu 20.04 and 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

Step 2.5) 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"

Step 2.6) Set locale (Ubuntu Only)

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

Step 2.7) 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

Step 2.8) Setup GCC libstdc++ 12 for use with Clang (Only for Ubuntu 20.04, 24.04 and 24.10)

  • Ubuntu 20.04

    sudo mkdir -p "/usr/include/c++/99/"
    sudo ln -s /usr/local/include/c++/12/* "/usr/include/c++/99/"
    sudo mkdir -p "/usr/lib/gcc/s390x-linux-gnu/99/"
    sudo ln -s /usr/local/lib/gcc/s390x-linux-gnu/12/* "/usr/lib/gcc/s390x-linux-gnu/99/"
    sudo mkdir -p "/usr/lib/gcc/s390x-linux-gnu/99/"
    sudo ln -s /usr/local/lib64/* "/usr/lib/gcc/s390x-linux-gnu/99/"
  • 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"

Step 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 (Only for Ubuntu 20.04)

    bazel build envoy -c opt --config=clang --test_env=HEAPCHECK= --action_env=LD_LIBRARY_PATH=/usr/local/lib64 --host_action_env=LD_LIBRARY_PATH=/usr/local/lib64
  • Build Envoy (For all other distros)

    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

Step 4: Test (optional)

cd $SOURCE_ROOT/envoy
  • Run Tests (Only for Ubuntu 20.04)

    bazel test //test/... -c opt --config=clang --keep_going --action_env=LD_LIBRARY_PATH=/usr/local/lib64 --host_action_env=LD_LIBRARY_PATH=/usr/local/lib64
  • Run Tests (For all other distros)

    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.

      ### Only for Ubuntu 20.04
      bazel test //test/extensions/filters/listener/original_dst:original_dst_integration_test -c opt --config=clang --action_env=LD_LIBRARY_PATH=/usr/local/lib64 --host_action_env=LD_LIBRARY_PATH=/usr/local/lib64 --test_env=HEAPCHECK= 
      ### For all other distros
      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:

    ### Only for Ubuntu 20.04
    bazel test //test/... -c opt --config=clang --keep_going --action_env=LD_LIBRARY_PATH=/usr/local/lib64 --host_action_env=LD_LIBRARY_PATH=/usr/local/lib64 --test_env=HEAPCHECK= 
    ### For all other distros
    bazel test //test/... -c opt --config=clang --keep_going --test_env=HEAPCHECK= 

References:

Clone this wiki locally