Skip to content
Guirish Salgaonkar edited this page May 22, 2019 · 1 revision

Building Istio Proxy

The DRAFT instructions provided below specify the steps to build Istio Proxy version 1.1.0 on Linux on IBM Z for following distributions:

  • RHEL (7.5, 7.6)
  • SLES 15
  • Ubuntu (16.04, 18.04)

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.

Step 1: Install dependencies

 export SOURCE_ROOT=/<source_root>/
  • RHEL (7.5, 7.6)

    sudo yum install -y git tar zip gcc-c++ unzip python libtool automake cmake golang curl wget gcc vim patch binutils-devel bzip2 make
    
    • Build GCC 7.3.0:

      cd $SOURCE_ROOT
      mkdir gcc
      cd gcc
      wget https://ftpmirror.gnu.org/gcc/gcc-7.3.0/gcc-7.3.0.tar.xz
      tar -xf gcc-7.3.0.tar.xz
      cd gcc-7.3.0
      ./contrib/download_prerequisites
      mkdir objdir
      cd objdir
      ../configure --prefix=/opt/gcc --enable-languages=c,c++ --with-arch=zEC12 --with-long-double-128 \
             --build=s390x-linux-gnu --host=s390x-linux-gnu --target=s390x-linux-gnu                  \
             --enable-threads=posix --with-system-zlib --disable-multilib
      make -j 8
      sudo make install
      sudo ln -sf /opt/gcc/bin/gcc /usr/bin/gcc
      sudo ln -sf /opt/gcc/bin/g++ /usr/bin/g++
      sudo ln -sf /opt/gcc/bin/g++ /usr/bin/c++
      export PATH=/opt/gcc/bin:"$PATH"
      export LD_LIBRARY_PATH=/opt/gcc/lib64:"$LD_LIBRARY_PATH"
      export C_INCLUDE_PATH=/opt/gcc/lib/gcc/s390x-linux-gnu/7.3.0/include
      export CPLUS_INCLUDE_PATH=/opt/gcc/lib/gcc/s390x-linux-gnu/7.3.0/include
      sudo ln -sf /opt/gcc/lib64/libstdc++.so.6.0.24 /lib64/libstdc++.so.6
    • Build Cmake 3.7.2:

      cd $SOURCE_ROOT
      wget https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz
      tar xzf cmake-3.7.2.tar.gz
      cd cmake-3.7.2
      ./configure --prefix=/usr/local
      make && sudo make install
  • SLES 15

    sudo zypper install -y  wget git tar pkg-config zip unzip python libtool automake cmake zlib-devel gcc gcc-c++ binutils-devel patch which curl python-xml libxml2-devel ninja
    
  • Ubuntu 16.04

     sudo apt-get update
     sudo apt-get install -y git tar  pkg-config zip g++ zlib1g-dev unzip python libtool automake cmake curl wget build-essential realpath ninja-build clang-format-5.0 golang-1.10
     export PATH=/usr/lib/go-1.10/bin:$PATH
    
    • Build GCC 7.3.0:
      cd $SOURCE_ROOT
      mkdir gcc
      cd gcc
      wget https://ftpmirror.gnu.org/gcc/gcc-7.3.0/gcc-7.3.0.tar.xz
      tar -xf gcc-7.3.0.tar.xz
      cd gcc-7.3.0
      ./contrib/download_prerequisites
      mkdir objdir
      cd objdir
      ../configure --prefix=/opt/gcc --enable-languages=c,c++ --with-arch=zEC12 --with-long-double-128 \
             --build=s390x-linux-gnu --host=s390x-linux-gnu --target=s390x-linux-gnu                  \
             --enable-threads=posix --with-system-zlib --disable-multilib
      make -j 8
      sudo make install
      sudo ln -sf /opt/gcc/bin/gcc /usr/bin/gcc
      sudo ln -sf /opt/gcc/bin/g++ /usr/bin/g++
      sudo ln -sf /opt/gcc/bin/g++ /usr/bin/c++
      export PATH=/opt/gcc/bin:"$PATH"
      export LD_LIBRARY_PATH=/opt/gcc/lib64:"$LD_LIBRARY_PATH"
      export C_INCLUDE_PATH=/opt/gcc/lib/gcc/s390x-linux-gnu/7.3.0/include
      export CPLUS_INCLUDE_PATH=/opt/gcc/lib/gcc/s390x-linux-gnu/7.3.0/include
      sudo ln -sf /opt/gcc/lib64/libstdc++.so.6.0.24 /lib64/libstdc++.so.6
  • Ubuntu 18.04

     sudo apt-get update
     sudo apt-get install -y git pkg-config zip zlib1g-dev unzip python libtool automake cmake curl wget build-essential rsync clang gcc-7 g++-7 libgtk2.0-0 ninja-build clang-format-5.0 golang-1.10
     sudo rm -rf /usr/bin/gcc /usr/bin/g++ /usr/bin/cc
     sudo ln -sf /usr/bin/gcc-7 /usr/bin/gcc
     sudo ln -sf /usr/bin/g++-7 /usr/bin/g++
     sudo ln -sf /usr/bin/gcc /usr/bin/cc
     export PATH=/usr/lib/go-1.10/bin:$PATH	
    
  • Install Go - v1.10.5 (RHEL and SLES only)

    cd $SOURCE_ROOT
    wget https://storage.googleapis.com/golang/go1.10.5.linux-s390x.tar.gz
    tar -xzf go1.10.5.linux-s390x.tar.gz
    export PATH=$SOURCE_ROOT/go/bin:$PATH
    export GOROOT=$SOURCE_ROOT/go
    go version
    
  • Install AdoptOpenJDK

    cd $SOURCE_ROOT
    wget https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.2%2B9/OpenJDK11U-jdk_s390x_linux_hotspot_11.0.2_9.tar.gz
    tar -xvf OpenJDK11U-jdk_s390x_linux_hotspot_11.0.2_9.tar.gz
    export JAVA_HOME=$SOURCE_ROOT/jdk-11.0.2+9
    export PATH=$JAVA_HOME/bin:$PATH
    java -version
    

Step 2: Build dependencies

2.1) Build Bazel version 0.24.1

  • Download Bazel

     cd $SOURCE_ROOT
     mkdir bazel && cd bazel
     wget https://github.com/bazelbuild/bazel/releases/download/0.24.1/bazel-0.24.1-dist.zip
     unzip bazel-0.24.1-dist.zip
     chmod -R +w .
     export CC=/usr/bin/gcc
     export CXX=/usr/bin/g++
  • Create a patch file patch_BUILD.diff with the following contents:

--- ./tools/cpp/BUILD.oldfile   2019-05-09 05:51:05.534752435 -0400
+++ ./tools/cpp/BUILD.newfile   2019-05-09 05:50:27.729604386 -0400
@@ -93,6 +93,7 @@
         "x64_windows|compiler": ":cc-compiler-x64_windows",
         "x64_windows_msvc|compiler": ":cc-compiler-x64_windows_msvc",
         "ppc|compiler": ":cc-compiler-ppc",
+        "s390x|compiler": ":cc-compiler-s390x",
         "k8": ":cc-compiler-local",
         "piii": ":cc-compiler-local",
         "arm": ":cc-compiler-local",
@@ -168,6 +169,34 @@
     toolchain_type = ":toolchain_type",
 )

+cc_toolchain(
+    name = "cc-compiler-s390x",
+    all_files = ":empty",
+    ar_files = ":empty",
+    as_files = ":empty",
+    compiler_files = ":empty",
+    cpu = "s390x",
+    dwp_files = ":empty",
+    linker_files = ":empty",
+    objcopy_files = ":empty",
+    strip_files = ":empty",
+    supports_param_files = 1,
+    toolchain_config = ":local_linux",
+    toolchain_identifier = "local_linux",
+)
+
+toolchain(
+    name = "cc-toolchain-s390x",
+    exec_compatible_with = [
+        "@bazel_tools//platforms:s390x",
+    ],
+    target_compatible_with = [
+        "@bazel_tools//platforms:s390x",
+    ],
+    toolchain = ":cc-compiler-s390x",
+    toolchain_type = ":toolchain_type",
+)
+
 cc_toolchain(
     name = "cc-compiler-armeabi-v7a",
     all_files = ":empty",

Apply patch using command mention below:

patch tools/cpp/BUILD < patch_BUILD.diff
  • Create a patch file patch_libcc.diff with the following contents:
--- ./tools/cpp/lib_cc_configure.bzl.oldfile    2019-05-09 06:09:31.045362405 -0400
+++ ./tools/cpp/lib_cc_configure.bzl.newfile    2019-05-09 06:09:09.902469492 -0400
@@ -188,6 +188,8 @@
     result = repository_ctx.execute(["uname", "-m"])
     if result.stdout.strip() in ["power", "ppc64le", "ppc", "ppc64"]:
         return "ppc"
+    if result.stdout.strip() in ["s390x"]:
+        return "s390x"
     if result.stdout.strip() in ["arm", "armv7l"]:
         return "arm"
     if result.stdout.strip() in ["aarch64"]:

Apply patch using command mention below:

patch tools/cpp/lib_cc_configure.bzl < patch_libcc.diff
  • Build Bazel

    env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk" bash ./compile.sh
    export PATH=$PATH:$SOURCE_ROOT/bazel/output/
    bazel version

    Note: While building Bazel, if build fails with an error java.lang.OutOfMemoryError: Java heap space , create a patch file patch_compile.diff with the following contents:

    --- ./scripts/bootstrap/compile.sh.oldfile      2019-05-09 06:19:43.508791854 -0400
    +++ ./scripts/bootstrap/compile.sh.newfile      2019-05-09 06:23:32.449966357 -0400
    @@ -127,7 +127,7 @@
       # Useful if your system chooses too small of a max heap for javac.
       # We intentionally rely on shell word splitting to allow multiple
       # additional arguments to be passed to javac.
    -  run "${JAVAC}" -classpath "${classpath}" -sourcepath "${sourcepath}" \
    +  run "${JAVAC}" -J-Xms1g -J-Xmx1g -classpath "${classpath}" -sourcepath "${sourcepath}" \
           -d "${output}/classes" -source "$JAVA_VERSION" -target "$JAVA_VERSION" \
           -encoding UTF-8 ${BAZEL_JAVAC_OPTS} "@${paramfile}"  

Apply patch using command mention below:

patch scripts/bootstrap/compile.sh < patch_compile.diff

2.2) Build Ninja (Only on RHEL)

 cd $SOURCE_ROOT 
 git clone git://github.com/ninja-build/ninja.git && cd ninja
 git checkout v1.8.2
 ./configure.py --bootstrap
 export PATH=/usr/local/bin:$PATH                              
 sudo ln -sf $SOURCE_ROOT/ninja/ninja /usr/local/bin/ninja     
 ninja --version       

2.3) Download Envoy

 cd $SOURCE_ROOT
 git clone https://github.com/envoyproxy/envoy
 cd envoy/
 git checkout 925810d      
  • Create a patch file patch_luajit.diff with the following contents:
--- ci/build_container/build_recipes/luajit.sh.oldfile  2019-05-09 06:28:41.732109308 -0400
+++ ci/build_container/build_recipes/luajit.sh.newfile  2019-05-09 06:30:11.724364502 -0400
@@ -2,15 +2,15 @@

 set -e

-VERSION=2.1.0-beta3
+
 SHA256=409f7fe570d3c16558e594421c47bdd130238323c9d6fd6c83dedd2aaeb082a8
 if [[ "${OS}" == "Windows_NT" ]]; then
   exit 0
 fi

-curl https://github.com/LuaJIT/LuaJIT/archive/v"$VERSION".tar.gz -sLo LuaJIT-"$VERSION".tar.gz \
-  && echo "$SHA256" LuaJIT-"$VERSION".tar.gz | sha256sum --check
-tar xf LuaJIT-"$VERSION".tar.gz
+git clone https://github.com/linux-on-ibm-z/LuaJIT.git
+cd LuaJIT
+git checkout v2.1

 # Fixup Makefile with things that cannot be set via env var.
 cat > luajit_make.diff << 'EOF'
@@ -60,8 +60,6 @@
  ##############################################################################
 EOF

-cd LuaJIT-"$VERSION"
-patch -p1 < ../luajit_make.diff

 # Default MACOSX_DEPLOYMENT_TARGET is 10.4, which will fail the build at link time on macOS 10.14:
 # ld: library not found for -lgcc_s.10.4

Apply patch using command mention below:

patch ci/build_container/build_recipes/luajit.sh < patch_luajit.diff
  • Create a patch file patch_utility.diff with the following contents:
--- source/common/network/utility.cc.oldfile    2019-05-09 06:33:18.159772322 -0400
+++ source/common/network/utility.cc.newfile    2019-05-09 06:33:37.892458389 -0400
@@ -452,16 +452,18 @@

 absl::uint128 Utility::Ip6ntohl(const absl::uint128& address) {
   // TODO(ccaraman): Support Ip6ntohl for big-endian.
-  static_assert(ABSL_IS_LITTLE_ENDIAN,
-                "Machines using big-endian byte order is not supported for IPv6.");
-  return flipOrder(address);
+//  static_assert(ABSL_IS_LITTLE_ENDIAN,
+//                "Machines using big-endian byte order is not supported for IPv6.");
+//  return flipOrder(address);
+  return address;
 }

 absl::uint128 Utility::Ip6htonl(const absl::uint128& address) {
   // TODO(ccaraman): Support Ip6ntohl for big-endian.
-  static_assert(ABSL_IS_LITTLE_ENDIAN,
-                "Machines using big-endian byte order is not supported for IPv6.");
-  return flipOrder(address);
+//  static_assert(ABSL_IS_LITTLE_ENDIAN,
+//                "Machines using big-endian byte order is not supported for IPv6.");
+//  return flipOrder(address);
+  return address;
 }

 absl::uint128 Utility::flipOrder(const absl::uint128& input) {

Apply patch using command mention below:

patch source/common/network/utility.cc < patch_utility.diff

2.4) Download BoringSSL

 cd $SOURCE_ROOT  
 git clone https://github.com/linux-on-ibm-z/boringssl
 cd boringssl  
 git checkout boringssl-Istio102-s390x

2.5) Download rules_foreign_cc

 cd $SOURCE_ROOT  
 git clone https://github.com/bazelbuild/rules_foreign_cc.git
 cd rules_foreign_cc/
 git checkout  e3f4b5e
 bazel build

Step 3: Building Istio-proxy

3.1) Download source code of Istio Proxy version 1.1.0

 cd $SOURCE_ROOT
 git clone https://github.com/istio/proxy.git
 cd proxy && git checkout 1.1.0
  • Edit file $SOURCE_ROOT/proxy/WORKSPACE: Note: Substitute for $SOURCE_ROOT in the below diff.
@@ -32,17 +32,31 @@ bind(
     actual = "//external:ssl",
 )

+local_repository(
+    name = "boringssl",
+    path = "$SOURCE_ROOT/boringssl",
+)
+
+bind(
+    name = "ssl",
+    actual = "@boringssl//:ssl",
+)
+
 # When updating envoy sha manually please update the sha in istio.deps file also
 #
 # Determine SHA256 `wget https://github.com/envoyproxy/envoy/archive/COMMIT.tar.gz && sha256sum COMMIT.tar.gz`
-ENVOY_SHA = "925810d00b0d3095a8e67fd4e04e0f597ed188bb"
+#
+#ENVOY_SHA = "925810d00b0d3095a8e67fd4e04e0f597ed188bb"
 ENVOY_SHA256 = "26d1f14e881455546cf0e222ec92a8e1e5f65cb2c5761d63c66598b39cd9c47d"

-http_archive(
+local_repository(
     name = "envoy",
-    strip_prefix = "envoy-" + ENVOY_SHA,
-    url = "https://github.com/envoyproxy/envoy/archive/" + ENVOY_SHA + ".tar.gz",
-    sha256 = ENVOY_SHA256,
+    path = "$SOURCE_ROOT/envoy",
+)
+
+local_repository(
+    name = "rules_foreign_cc",
+    path = "$SOURCE_ROOT/rules_foreign_cc",
 )

 load("@envoy//bazel:repositories.bzl", "envoy_dependencies")
 )

 load("@envoy//bazel:repositories.bzl", "envoy_dependencies")
 envoy_dependencies()

3.2) Build Istio Proxy

Proxy binaries should be built in both debug and release mode. Once the build completes, the binary file named envoy will be created under $SOURCE_ROOT/proxy/bazel-bin/src/envoy/. Take backup of the debug binary before proceeding with release mode.

  • In DEBUG mode

    • Create a patch file patch_debug.diff with the following contents:

      --- ./Makefile.oldfile  2019-05-09 06:45:04.826038421 -0400
      +++ ./Makefile.newfile  2019-05-09 06:47:27.185428866 -0400
      @@ -34,7 +34,7 @@
       PATH := /usr/lib/llvm-7/bin:$(PATH)
      
       build:
      -       PATH=$(PATH) CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) build $(BAZEL_BUILD_ARGS) $(BAZEL_TARGETS)
      +       PATH=$(PATH) CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) build $(BAZEL_BUILD_ARGS) $(BAZEL_TARGETS) --host_javabase=@local_jdk//:jdk
              @bazel shutdown
      
       # Build only envoy - fast

      Apply patch using command mention below:

      patch Makefile < patch_debug.diff
      
    • Build Proxy

     cd $SOURCE_ROOT/proxy
     make build
  • In RELEASE mode

    • Create a patch file patch_release.diff with the following contents:

      • On Ubuntu 16.04 and RHEL
      --- ./Makefile.oldfile  2019-05-09 06:45:04.826038421 -0400
      +++ ./Makefile.newfile  2019-05-09 06:47:27.185428866 -0400
      @@ -34,7 +34,7 @@
       PATH := /usr/lib/llvm-7/bin:$(PATH)
      
       build:
      -       PATH=$(PATH) CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) build $(BAZEL_BUILD_ARGS) $(BAZEL_TARGETS)
      +       PATH=$(PATH) CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) build -c opt $(BAZEL_BUILD_ARGS) $(BAZEL_TARGETS) --host_javabase=@local_jdk//:jdk
              @bazel shutdown
      
       # Build only envoy - fast   

      Apply patch using command mention below:

      patch Makefile < patch_release.diff
      
      • On Ubuntu 18.04
      --- ./Makefile.oldfile  2019-05-09 06:45:04.826038421 -0400
      +++ ./Makefile.newfile  2019-05-09 06:47:27.185428866 -0400
      @@ -34,7 +34,7 @@
       PATH := /usr/lib/llvm-7/bin:$(PATH)
      
       build:
      -       PATH=$(PATH) CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) build $(BAZEL_BUILD_ARGS) $(BAZEL_TARGETS)
      +       PATH=$(PATH) CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) build -c opt --copt="-fno-strict-aliasing" --cxxopt="-fno-strict-aliasing" $(BAZEL_BUILD_ARGS) $(BAZEL_TARGETS) --host_javabase=@local_jdk//:jdk
              @bazel shutdown
      
       # Build only envoy - fast   

      Apply patch using command mention below:

      patch Makefile < patch_release.diff
      
    • Build Proxy

      cd $SOURCE_ROOT/proxy
      make build

Note: While building Istio Proxy, if build fails with an error java.lang.OutOfMemoryError: Java heap space, add below options in $SOURCE_ROOT/proxy/Makefile:

    build:
-       @bazel $(BAZEL_STARTUP_ARGS) build $(BAZEL_BUILD_ARGS) //...
+       @bazel $(BAZEL_STARTUP_ARGS) --host_jvm_args="-Xms512m" --host_jvm_args="-Xmx2g"  build $(BAZEL_BUILD_ARGS) //...

Step 4: Execute Test Suite (Optional)

  • Create a patch file patch_test.diff with the following contents to run only ipv4 test cases as ipv6 ones are not supported:
--- ./Makefile.oldfile  2019-05-09 06:45:04.826038421 -0400
+++ ./Makefile.newfile  2019-05-09 07:05:56.226507662 -0400
@@ -47,7 +47,7 @@
        @bazel shutdown

 test:
-       PATH=$(PATH) CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) test $(BAZEL_TEST_ARGS) $(BAZEL_TARGETS)
+       PATH=$(PATH) CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) test $(BAZEL_TEST_ARGS) $(BAZEL_TARGETS) --test_env=ENVOY_IP_TEST_VERSIONS=v4only --host_javabase=@local_jdk//:jdk
        @bazel shutdown

 test_asan:

Apply patch using command mention below:

cd $SOURCE_ROOT/proxy
patch Makefile < patch_test.diff
  • Run the test suite

    cd $SOURCE_ROOT/proxy
    make test

    Note: //test/integration:mixer_fault_test is failing on s390x and x86 too:

References:

https://github.com/istio/proxy