Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Support building with libc++ #183

Closed
lizan opened this issue Oct 13, 2019 · 2 comments
Closed

Support building with libc++ #183

lizan opened this issue Oct 13, 2019 · 2 comments

Comments

@lizan
Copy link

lizan commented Oct 13, 2019

Requirement

We're considering switch Envoy default build to libc++, and all released Istio proxy are already built with libc++ since August.

Proposal

Add cmake flags to not adding -static-libstdc++, and propagate -stdlib=libc++ to the dependencies pulled by Hunter. I did a hack tetratelabs-attic/getenvoy-package#35 (comment) but that's not a good one.

@prahaladramji
Copy link

prahaladramji commented Mar 6, 2020

@lizan could you please share your snippet to help compile this plugin so it's compatible with envoy 1.13.1

I've successfully built jaeger-client-cpp v0.5.0 and works well with envoyproxy/envoy:v1.13.1 image
I haven't statically linked libc++ and libc++abi, so in the above image you will need to install apt-get install -y libc++1-8

I haven't figured out how to statically link that to the libjaegertracing_plugin.so, that would be necessary to have it working with the alpine image.

Here's what I've done.
build image used envoyproxy/envoy-build-ubuntu:latest
build steps

git checkout v0.5.0
git apply  jaeger-client-cpp-build.patch
docker run --rm -it -v $(pwd):/mnt/jaeger-client-cpp envoyproxy/envoy-build-ubuntu:latest bash
cd /mnt/jaeger-client-cpp
./scripts/build-plugin.sh

jaeger-client-cpp-build.patch

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5893f31..280b53c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -271,7 +271,6 @@ if(JAEGERTRACING_PLUGIN)
   add_lib_deps(jaegertracing_plugin)
   target_link_libraries(jaegertracing_plugin PUBLIC
     -static-libgcc
-    -static-libstdc++
     -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/export.map)
 endif()
 
diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake
index ad7a02f..24e5d0c 100644
--- a/cmake/toolchain.cmake
+++ b/cmake/toolchain.cmake
@@ -1,5 +1,5 @@
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
-set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD 14)
 set(CMAKE_CXX_EXTENSIONS OFF)
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
\ No newline at end of file
diff --git a/scripts/build-plugin.sh b/scripts/build-plugin.sh
index 192c824..da7a99d 100755
--- a/scripts/build-plugin.sh
+++ b/scripts/build-plugin.sh
@@ -5,11 +5,14 @@ set -e
 function main() {
     local project_dir
     project_dir="$(git rev-parse --show-toplevel)"
+    cd "$project_dir"
 
     mkdir -p build
     cd build
     export CFLAGS="$CFLAGS -march=x86-64"
     export CXXFLAGS="$CXXFLAGS -march=x86-64"
+    export CXX=/usr/bin/clang++
+    export CC=/usr/bin/clang
 
     cat <<EOF > export.map
 {
@@ -23,10 +26,21 @@ EOF
         -DJAEGERTRACING_PLUGIN=ON \
         -DBUILD_TESTING=ON \
         -DHUNTER_CONFIGURATION_TYPES=Release \
+        -DHUNTER_BUILD_SHARED_LIBS=OFF \
+        -DBUILD_SHARED_LIBS=OFF \
         ..
     make -j3
-    mv libjaegertracing_plugin.so /libjaegertracing_plugin.so
-    ./DynamicallyLoadTracerTest /libjaegertracing_plugin.so
 }
 
+function clangwrap() {
+    tee -a /usr/bin/clang++ > /dev/null <<EOT
+#!/bin/bash
+/usr/bin/clang++-8 -stdlib=libc++ "\$@"
+EOT
+
+    chmod +x /usr/bin/clang++
+    ln -sf /usr/bin/clang-8 /usr/bin/clang
+}
+
+clangwrap
 main

@maksim-paskal
Copy link

maksim-paskal commented Jul 24, 2020

I've successfully built jaeger-client-cpp v0.5.0 and works well with envoyproxy/envoy:v1.15.0 - and there is no need to install some specials packages, it's statically linked to libc++ and libc++abi

jaeger-client-cpp-build.patch - same as here

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5893f31..280b53c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -271,7 +271,6 @@ if(JAEGERTRACING_PLUGIN)
   add_lib_deps(jaegertracing_plugin)
   target_link_libraries(jaegertracing_plugin PUBLIC
     -static-libgcc
-    -static-libstdc++
     -Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/export.map)
 endif()
 
diff --git a/cmake/toolchain.cmake b/cmake/toolchain.cmake
index ad7a02f..24e5d0c 100644
--- a/cmake/toolchain.cmake
+++ b/cmake/toolchain.cmake
@@ -1,5 +1,5 @@
 set(CMAKE_CXX_STANDARD_REQUIRED ON)
-set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD 14)
 set(CMAKE_CXX_EXTENSIONS OFF)
 set(CMAKE_POSITION_INDEPENDENT_CODE ON)
 set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
\ No newline at end of file
diff --git a/scripts/build-plugin.sh b/scripts/build-plugin.sh
index 192c824..da7a99d 100755
--- a/scripts/build-plugin.sh
+++ b/scripts/build-plugin.sh
@@ -5,11 +5,14 @@ set -e
 function main() {
     local project_dir
     project_dir="$(git rev-parse --show-toplevel)"
+    cd "$project_dir"
 
     mkdir -p build
     cd build
     export CFLAGS="$CFLAGS -march=x86-64"
     export CXXFLAGS="$CXXFLAGS -march=x86-64"
+    export CXX=/usr/bin/clang++
+    export CC=/usr/bin/clang
 
     cat <<EOF > export.map
 {
@@ -23,10 +26,21 @@ EOF
         -DJAEGERTRACING_PLUGIN=ON \
         -DBUILD_TESTING=ON \
         -DHUNTER_CONFIGURATION_TYPES=Release \
+        -DHUNTER_BUILD_SHARED_LIBS=OFF \
+        -DBUILD_SHARED_LIBS=OFF \
         ..
     make -j3
-    mv libjaegertracing_plugin.so /libjaegertracing_plugin.so
-    ./DynamicallyLoadTracerTest /libjaegertracing_plugin.so
 }
 
+function clangwrap() {
+    tee -a /usr/bin/clang++ > /dev/null <<EOT
+#!/bin/bash
+/usr/bin/clang++-8 -stdlib=libc++ "\$@"
+EOT
+
+    chmod +x /usr/bin/clang++
+    ln -sf /usr/bin/clang-8 /usr/bin/clang
+}
+
+clangwrap
 main

Dockerfile

FROM ubuntu:bionic

RUN apt update \
&& apt install -y build-essential git curl libc++-dev libc++abi-dev clang-8 \
&& curl -L -O "https://cmake.org/files/v3.11/cmake-3.11.0-Linux-x86_64.sh" \
&& bash cmake-3.11.0-Linux-x86_64.sh --skip-license

RUN echo 'INPUT(-l:libc++.a -l:libc++abi.a -lm -lpthread)' > /usr/lib/x86_64-linux-gnu/libc++.so

WORKDIR /tmp
RUN git clone --recurse-submodules --branch=v0.5.0 https://github.com/jaegertracing/jaeger-client-cpp.git

WORKDIR /tmp/jaeger-client-cpp/
ADD ./jaeger-client-cpp-build.patch ./jaeger-client-cpp-build.patch
RUN git apply jaeger-client-cpp-build.patch
RUN ./scripts/build-plugin.sh

FROM envoyproxy/envoy:v1.15.0

COPY --from=0 /tmp/jaeger-client-cpp/build/libjaegertracing_plugin.so /usr/local/lib/libjaegertracing_plugin.so

or you can use precompiled binary

FROM envoyproxy/envoy:v1.15.0

ADD --chown=envoy:envoy https://github.com/maksim-paskal/jaeger-client-cpp/releases/download/v0.5.0/libjaegertracing_plugin.so /usr/local/lib/libjaegertracing_plugin.so

jaeger-client-cpp v0.6.0 is not compatible with envoy v1.15.0

failed to load dynamic library: opentracing: versions of opentracing libraries are incompatible

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants