Skip to content

Building Istio Proxy 1.2.2

Guirish Salgaonkar edited this page Jul 16, 2019 · 2 revisions

Building Istio Proxy

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

  • Ubuntu 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>/
  • 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
    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
    
  • Install Go - v1.12.5

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

    cd $SOURCE_ROOT
    wget https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.3%2B7/OpenJDK11U-jdk_s390x_linux_hotspot_11.0.3_7.tar.gz
    tar -xvf OpenJDK11U-jdk_s390x_linux_hotspot_11.0.3_7.tar.gz
    export JAVA_HOME=$SOURCE_ROOT/jdk-11.0.3+7
    export PATH=$JAVA_HOME/bin:$PATH
    java -version
    

Step 2: Build dependencies

2.1) Build Bazel version 0.25.0

  • Download Bazel

    cd $SOURCE_ROOT
    mkdir bazel && cd bazel
    wget https://github.com/bazelbuild/bazel/releases/download/0.25.0/bazel-0.25.0-dist.zip
    unzip bazel-0.25.0-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-06-24 09:20:26.858964614 +0000
    +++ ./tools/cpp/BUILD   2019-06-24 09:20:46.368964614 +0000
    @@ -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-06-24 09:21:04.158964614 +0000
    +++ ./tools/cpp/lib_cc_configure.bzl    2019-06-24 09:22:21.458964614 +0000
    @@ -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, apply below patch and rebuild Bazel.

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

      --- scripts/bootstrap/compile.sh.oldfile        2019-06-26 13:07:57.628501655 +0000
      +++ scripts/bootstrap/compile.sh        2019-06-26 13:08:41.778491674 +0000
      @@ -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:

      cd $SOURCE_ROOT/bazel
      patch scripts/bootstrap/compile.sh < patch_compile.diff
      
    • Rebuild:

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

2.2) Download Envoy

 cd $SOURCE_ROOT
 git clone https://github.com/istio/envoy/
 cd envoy/
 git checkout 4f5b5e101a081e05924990b1903d9d46553558d4
  • Create a patch file BUILD-envoy.patch with the following contents:

    --- a/bazel/BUILD
    +++ b/bazel/BUILD
    @@ -153,7 +153,7 @@ config_setting(
         name = "boringssl_fips",
         constraint_values = [
             "@bazel_tools//platforms:linux",
    -        "@bazel_tools//platforms:x86_64",
    +        "@bazel_tools//platforms:s390x",
         ],
         values = {"define": "boringssl=fips"},
     )
    @@ -194,6 +194,10 @@ config_setting(
         values = {"cpu": "x64_windows"},
     )
    
    +config_setting(
    +    name = "linux_s390x",
    +    values = {"cpu": "s390x"},
    +)
     # Configuration settings to make doing selects for Apple vs non-Apple platforms
     # easier. More details: https://docs.bazel.build/versions/master/configurable-    attributes.html#config_settingaliasing
     config_setting(

    Apply patch using command mention below:

    patch bazel/BUILD < BUILD-envoy.patch
    
  • Create a patch file luajit-patch.patch with the following contents:

    --- a/bazel/foreign_cc/luajit.patch
    +++ b/bazel/foreign_cc/luajit.patch
    @@ -1,48 +1,3 @@
    -diff --git a/src/Makefile b/src/Makefile
    -index f56465d..3f4f2fa 100644
    ---- a/src/Makefile
    -+++ b/src/Makefile
    -@@ -27,7 +27,7 @@ NODOTABIVER= 51
    - DEFAULT_CC = gcc
    - #
    - # LuaJIT builds as a native 32 or 64 bit binary by default.
    --CC= $(DEFAULT_CC)
    -+CC ?= $(DEFAULT_CC)
    - #
    - # Use this if you want to force a 32 bit build on a 64 bit multilib OS.
    - #CC= $(DEFAULT_CC) -m32
    -@@ -71,10 +71,10 @@ CCWARN= -Wall
    - # as dynamic mode.
    - #
    - # Mixed mode creates a static + dynamic library and a statically linked luajit.
    --BUILDMODE= mixed
    -+#BUILDMODE= mixed
    - #
    - # Static mode creates a static library and a statically linked luajit.
    --#BUILDMODE= static
    -+BUILDMODE= static
    - #
    - # Dynamic mode creates a dynamic library and a dynamically linked luajit.
    - # Note: this executable will only run when the library is installed!
    -@@ -99,7 +99,7 @@ XCFLAGS=
    - # enabled by default. Some other features that *might* break some existing
    - # code (e.g. __pairs or os.execute() return values) can be enabled here.
    - # Note: this does not provide full compatibility with Lua 5.2 at this time.
    --#XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
    -+XCFLAGS+= -DLUAJIT_ENABLE_LUA52COMPAT
    - #
    - # Disable the JIT compiler, i.e. turn LuaJIT into a pure interpreter.
    - #XCFLAGS+= -DLUAJIT_DISABLE_JIT
    -@@ -587,7 +587,7 @@ endif
    -
    - Q= @
    - E= @echo
    --#Q=
    -+Q=
    - #E= @:
    -
    - ##############################################################################
    -EOF
     diff --git a/build.py b/build.py
     new file mode 100755
     index 0000000..9c71271

    Apply patch using command mention below:

    patch bazel/foreign_cc/luajit.patch < luajit-patch.patch
  • Create a patch file repositories-envoy.bzl.patch with the following contents:

    --- a/bazel/repositories.bzl
    +++ b/bazel/repositories.bzl
    @@ -610,7 +610,7 @@ def _com_github_gperftools_gperftools():
         http_archive(
             name = "com_github_gperftools_gperftools",
             build_file_content = BUILD_ALL_CONTENT,
    -        patch_cmds = ["./autogen.sh"],
    +        #patch_cmds = ["./autogen.sh"],
             **location
         )
    
    @@ -632,5 +632,8 @@ def _is_arch(ctxt, arch):
     def _is_linux_ppc(ctxt):
         return _is_linux(ctxt) and _is_arch(ctxt, "ppc")
    
    +def _is_linux_s390x(ctxt):
    +    return _is_linux(ctxt) and _is_arch(ctxt, "s390x")
    +
     def _is_linux_x86_64(ctxt):
         return _is_linux(ctxt) and _is_arch(ctxt, "x86_64")

    Apply patch using command mention below:

    patch bazel/repositories.bzl < repositories-envoy.bzl.patch
    
  • Create a patch file BUILD-api.patch with the following contents:

    --- a/source/common/api/BUILD
    +++ b/source/common/api/BUILD
    @@ -26,12 +26,14 @@ envoy_cc_library(
             "//bazel:linux_x86_64": ["os_sys_calls_impl_linux.cc"],
             "//bazel:linux_aarch64": ["os_sys_calls_impl_linux.cc"],
             "//bazel:linux_ppc": ["os_sys_calls_impl_linux.cc"],
    +       "//bazel:linux_s390x": ["os_sys_calls_impl_linux.cc"],
             "//conditions:default": [],
         }) + envoy_select_hot_restart(["os_sys_calls_impl_hot_restart.cc"]),
         hdrs = ["os_sys_calls_impl.h"] + select({
             "//bazel:linux_x86_64": ["os_sys_calls_impl_linux.h"],
             "//bazel:linux_aarch64": ["os_sys_calls_impl_linux.h"],
             "//bazel:linux_ppc": ["os_sys_calls_impl_linux.h"],
    +       "//bazel:linux_s390x": ["os_sys_calls_impl_linux.h"],
             "//conditions:default": [],
         }) + envoy_select_hot_restart(["os_sys_calls_impl_hot_restart.h"]),
         deps = [

    Apply patch using command mention below:

    patch source/common/api/BUILD < BUILD-api.patch
    
  • Create a patch file BUILD-exe.patch with the following contents:

    --- ./source/exe/BUILD.oldfile  2019-06-24 11:29:15.929115941 +0000
    +++ ./source/exe/BUILD.newfile  2019-06-26 10:13:46.299394111 +0000
    @@ -46,6 +46,7 @@
         ] + select({
             "//bazel:windows_x86_64": envoy_windows_extensions(),
             "//bazel:linux_ppc": envoy_all_extensions(PPC_SKIP_TARGETS),
    +       "//bazel:linux_s390x": envoy_all_extensions(),
             "//conditions:default": envoy_all_extensions(),
         }),
     )

    Apply patch using command mention below:

    patch source/exe/BUILD < BUILD-exe.patch
    
  • Create a patch file repository_locations.bzl.patch with the following contents:

    --- a/bazel/repository_locations.bzl
    +++ b/bazel/repository_locations.bzl
    @@ -77,9 +77,10 @@ REPOSITORY_LOCATIONS = dict(
             # TODO(cmluciano): Bump to release 2.8
             # This sha is specifically chosen to fix ppc64le builds that require inclusion
             # of asm/ptrace.h
    -        sha256 = "18574813a062eee487bc1b761e8024a346075a7cb93da19607af362dc09565ef",
    -        strip_prefix = "gperftools-fc00474ddc21fff618fc3f009b46590e241e425e",
    -        urls = ["https://github.com/gperftools/gperftools/archive/fc00474ddc21fff618fc3f009b46590e241e425e.tar.gz"],
    +        sha256 = "1ee8c8699a0eff6b6a203e59b43330536b22bbcbe6448f54c7091e5efb0763c9",
    +        strip_prefix = "gperftools-2.7",
    +        urls = ["https://github.com/gperftools/gperftools/releases/download/gperftools-2.7/gperftools-2.7.tar.gz"],
    +
         ),
         com_github_grpc_grpc = dict(
             sha256 = "ba8b08a697b66e14af35da07753583cf32ff3d14dcd768f91b1bbe2e6c07c349",
    @@ -87,9 +88,9 @@ REPOSITORY_LOCATIONS = dict(
             urls = ["https://github.com/grpc/grpc/archive/v1.20.1.tar.gz"],
         ),
         com_github_luajit_luajit = dict(
    -        sha256 = "409f7fe570d3c16558e594421c47bdd130238323c9d6fd6c83dedd2aaeb082a8",
    -        strip_prefix = "LuaJIT-2.1.0-beta3",
    -        urls = ["https://github.com/LuaJIT/LuaJIT/archive/v2.1.0-beta3.tar.gz"],
    +        #sha256 = "409f7fe570d3c16558e594421c47bdd130238323c9d6fd6c83dedd2aaeb082a8",
    +        strip_prefix = "LuaJIT-2.1",
    +        urls = ["https://github.com/linux-on-ibm-z/LuaJIT/archive/v2.1.zip"],
         ),
         com_github_nanopb_nanopb = dict(
             sha256 = "5fb4dab0b7f6a239908407fe07c9d03877cd0502abb637e38c41091cb9c1d438",

    Apply patch using command mention below:

    patch bazel/repository_locations.bzl < repository_locations.bzl.patch
    
  • Create a patch file patch_utility.diff with the following contents:

    --- a/source/common/network/utility.cc
    +++ b/source/common/network/utility.cc
    @@ -452,16 +452,18 @@ bool Utility::portInRangeList(const Address::Instance& address, const std::list<
    
     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.3) Download BoringSSL

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

Step 3: Building Istio-proxy

3.1) Download source code of Istio Proxy version 1.2.2

 cd $SOURCE_ROOT
 git clone https://github.com/istio/proxy.git
 cd proxy && git checkout 1.2.2
  • Edit file $SOURCE_ROOT/proxy/WORKSPACE:

    Note: Substitute for $SOURCE_ROOT in the below diff.

    --- WORKSPACE.oldfile   2019-06-24 10:31:23.458994198 +0000
    +++ WORKSPACE.newfile   2019-06-26 12:48:33.088691442 +0000
    @@ -31,23 +31,28 @@
         name = "boringssl_crypto",
         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 commit date  05/16/2019
     # bazel version: 0.25.0
    -ENVOY_SHA = "4f5b5e101a081e05924990b1903d9d46553558d4"
    +#ENVOY_SHA = "4f5b5e101a081e05924990b1903d9d46553558d4"
    
     ENVOY_SHA256 = "59b1599b8847543d7614c5507a33f14f9de49c34ac112cf0d6e082392294eaff"
    
     LOCAL_ENVOY_PROJECT = "/PATH/TO/ENVOY"
    
    -http_archive(
    +local_repository(
         name = "envoy",
    -    sha256 = ENVOY_SHA256,
    -    strip_prefix = "envoy-" + ENVOY_SHA,
    -    url = "https://github.com/istio/envoy/archive/" + ENVOY_SHA + ".tar.gz",
    +    path = "$SOURCE_ROOT/envoy"
     )
    
     # TODO(silentdai) Use bazel args to select envoy between local or http

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:

      • On Ubuntu

        --- Makefile.oldfile	2019-06-26 13:17:38.258405053 +0000
        +++ Makefile.newfile	2019-06-26 13:18:00.698405053 +0000
        @@ -35,7 +35,7 @@
        
         # Removed 'bazel shutdown' as it could cause CircleCI to hang
         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
        
         # Build only envoy - fast
         build_envoy:   

      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

        --- Makefile.oldfile	2019-06-26 13:18:59.438394935 +0000
        +++ Makefile.newfile	2019-06-26 13:19:18.628394935 +0000
        @@ -35,7 +35,7 @@
        
         # Removed 'bazel shutdown' as it could cause CircleCI to hang
         build:
        -	PATH=$(PATH) CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) build $(BAZEL_BUILD_ARGS) $(BAZEL_TARGETS) --host_javabase=@local_jdk//:jdk
        +	PATH=$(PATH) CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) build -c opt $(BAZEL_BUILD_ARGS) $(BAZEL_TARGETS) --host_javabase=@local_jdk//:jdk
        
         # Build only envoy - fast
         build_envoy:

      Apply patch using command mention below:

      patch Makefile < patch_release.diff
      
    • Build Proxy

      cd $SOURCE_ROOT/proxy
      make build

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:

    • On Ubuntu
      --- Makefile.oldfile	2019-06-26 13:19:46.308379963 +0000
      +++ Makefile.newfile	2019-06-26 13:20:46.288379963 +0000
      @@ -45,7 +45,7 @@
       	@bazel clean
      
       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
      
       test_asan:
       	PATH=$(PATH) CC=$(CC) CXX=$(CXX) bazel $(BAZEL_STARTUP_ARGS) test $(BAZEL_TEST_ARGS) --config=clang-asan -- $(BAZEL_TARGETS) $(SANITIZER_EXCLUSIONS)

    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 case //test/integration:mixer_fault_test is failing on both x86 and s390x .

References:

https://github.com/istio/proxy