pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mme...@apache.org
Subject [pulsar] branch master updated: Build static lib with bundled dependencies (#3488)
Date Thu, 07 Feb 2019 22:25:16 GMT
This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 3b1dd8c  Build static lib with bundled dependencies (#3488)
3b1dd8c is described below

commit 3b1dd8cfaa22ecf24eeaac2c6da026e0747cbcfd
Author: Matteo Merli <mmerli@apache.org>
AuthorDate: Thu Feb 7 14:22:59 2019 -0800

    Build static lib with bundled dependencies (#3488)
    
    * Build static lib with bundled dependencies
    
    * Added gitignore entry
    
    * Fixed target_link_libraries when not linking statically
    
    * Fixed linking on python wrapper
---
 pulsar-client-cpp/.gitignore                       |  3 ++
 pulsar-client-cpp/build-support/merge_archives.sh  | 50 ++++++++++++++++++++++
 .../docker/build-wheel-file-within-docker.sh       |  2 +-
 pulsar-client-cpp/lib/CMakeLists.txt               | 39 +++++++++++++----
 pulsar-client-cpp/pkg/deb/build-deb.sh             |  1 -
 pulsar-client-cpp/python/CMakeLists.txt            |  4 +-
 6 files changed, 86 insertions(+), 13 deletions(-)

diff --git a/pulsar-client-cpp/.gitignore b/pulsar-client-cpp/.gitignore
index e14b081..dd09eb2 100644
--- a/pulsar-client-cpp/.gitignore
+++ b/pulsar-client-cpp/.gitignore
@@ -70,3 +70,6 @@ CMakeFiles
 CMakeCache.txt
 
 pulsar-dist
+install_manifest.txt
+merged-library
+python/venv
\ No newline at end of file
diff --git a/pulsar-client-cpp/build-support/merge_archives.sh b/pulsar-client-cpp/build-support/merge_archives.sh
new file mode 100755
index 0000000..065130d
--- /dev/null
+++ b/pulsar-client-cpp/build-support/merge_archives.sh
@@ -0,0 +1,50 @@
+#!/usr/bin/env bash
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+set -e
+
+MERGED_LIBRARY=$1
+shift
+ITEMS=$*
+
+echo "MERGED_LIBRARY=$MERGED_LIBRARY"
+
+rm -rf merged-library
+mkdir -p merged-library
+
+cd merged-library
+
+LIBS=""
+
+for ITEM in $ITEMS; do
+    LIB_NAME=$(basename $ITEM .a)
+    echo "Packing $LIB_NAME -- '$ITEM'"
+
+    mkdir $LIB_NAME
+    cd $LIB_NAME
+    ar -x $ITEM
+
+    LIBS="$LIBS $LIB_NAME/*.o"
+    cd ..
+done
+
+ar -qc $MERGED_LIBRARY $LIBS
+
+
diff --git a/pulsar-client-cpp/docker/build-wheel-file-within-docker.sh b/pulsar-client-cpp/docker/build-wheel-file-within-docker.sh
index cdaa795..33a225d 100755
--- a/pulsar-client-cpp/docker/build-wheel-file-within-docker.sh
+++ b/pulsar-client-cpp/docker/build-wheel-file-within-docker.sh
@@ -31,7 +31,7 @@ cmake . -DPYTHON_INCLUDE_DIR=/opt/python/$PYTHON_SPEC/include/python$PYTHON_VERS
         -DBUILD_TESTS=OFF
 
 make clean
-make _pulsar -j3
+make _pulsar -j3 VERBOSE=1
 
 cd python
 python setup.py bdist_wheel
diff --git a/pulsar-client-cpp/lib/CMakeLists.txt b/pulsar-client-cpp/lib/CMakeLists.txt
index 2116ed6..8f74b96 100644
--- a/pulsar-client-cpp/lib/CMakeLists.txt
+++ b/pulsar-client-cpp/lib/CMakeLists.txt
@@ -31,21 +31,42 @@ ADD_CUSTOM_COMMAND(
          ../../pulsar-common/src/main/proto/PulsarApi.proto
          WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
 
-add_library(pulsarStatic STATIC ${PULSAR_SOURCES} PulsarApi.pb.h PulsarApi.pb.cc)
-add_library(pulsarShared SHARED ${PULSAR_SOURCES} PulsarApi.pb.h PulsarApi.pb.cc)
-
 set(LIBRARY_VERSION $ENV{PULSAR_LIBRARY_VERSION})
 if (NOT LIBRARY_VERSION)
     set(LIBRARY_VERSION ${PV})
 endif(NOT LIBRARY_VERSION)
 
-set_target_properties(pulsarStatic PROPERTIES OUTPUT_NAME ${LIB_NAME} VERSION ${LIBRARY_VERSION})
-set_target_properties(pulsarShared PROPERTIES OUTPUT_NAME ${LIB_NAME} VERSION ${LIBRARY_VERSION})
 
-target_link_libraries(pulsarStatic ${COMMON_LIBS})
+add_library(pulsarShared SHARED ${PULSAR_SOURCES} PulsarApi.pb.h PulsarApi.pb.cc)
+set_target_properties(pulsarShared PROPERTIES OUTPUT_NAME ${LIB_NAME} VERSION ${LIBRARY_VERSION})
 target_link_libraries(pulsarShared ${COMMON_LIBS})
 
-install(TARGETS pulsarStatic DESTINATION lib)
-install(TARGETS pulsarShared DESTINATION lib)
+add_library(pulsarStatic STATIC ${PULSAR_SOURCES} PulsarApi.pb.h PulsarApi.pb.cc)
+set_target_properties(pulsarStatic PROPERTIES OUTPUT_NAME ${LIB_NAME} VERSION ${LIBRARY_VERSION})
 
-install(DIRECTORY "../include/pulsar" DESTINATION include)
\ No newline at end of file
+# When linking statically, install a libpulsar.a that contains all the
+# required dependencies
+if (LINK_STATIC)
+    # Build a list of the requird .a libs to merge
+    SET(STATIC_LIBS "")
+    foreach (LIB IN LISTS COMMON_LIBS)
+        if (${LIB} MATCHES ".+\\.a")
+            set(STATIC_LIBS "${STATIC_LIBS} ${LIB}")
+        endif()
+    endforeach()
+
+    add_custom_target(pulsarStaticWithDeps
+            ALL
+            BYPRODUCTS merged-library
+            COMMAND ./build-support/merge_archives.sh libpulsar.a $<TARGET_FILE:pulsarStatic>
${STATIC_LIBS}
+            DEPENDS pulsarStatic
+            WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
+    install(FILES ../merged-library/libpulsar.a DESTINATION lib)
+else()
+    # Install regular libpulsar.a
+    target_link_libraries(pulsarStatic ${COMMON_LIBS})
+    install(TARGETS pulsarStatic DESTINATION lib)
+endif(LINK_STATIC)
+
+install(TARGETS pulsarShared DESTINATION lib)
+install(DIRECTORY "../include/pulsar" DESTINATION include)
diff --git a/pulsar-client-cpp/pkg/deb/build-deb.sh b/pulsar-client-cpp/pkg/deb/build-deb.sh
index 09af1a7..d1120b8 100755
--- a/pulsar-client-cpp/pkg/deb/build-deb.sh
+++ b/pulsar-client-cpp/pkg/deb/build-deb.sh
@@ -39,7 +39,6 @@ pushd $CPP_DIR
 
 cmake . -DBUILD_TESTS=OFF -DLINK_STATIC=ON
 make pulsarShared pulsarStatic -j 3
-strip lib/libpulsar.*
 popd
 
 DEST_DIR=apache-pulsar-client
diff --git a/pulsar-client-cpp/python/CMakeLists.txt b/pulsar-client-cpp/python/CMakeLists.txt
index e57f583..e71ef4f 100644
--- a/pulsar-client-cpp/python/CMakeLists.txt
+++ b/pulsar-client-cpp/python/CMakeLists.txt
@@ -60,8 +60,8 @@ if (NOT PYTHON_WRAPPER_LIBS)
 endif ()
 
 if (APPLE)
-    target_link_libraries(_pulsar -Wl,-all_load pulsarStatic ${PYTHON_WRAPPER_LIBS})
+    target_link_libraries(_pulsar -Wl,-all_load pulsarStatic ${PYTHON_WRAPPER_LIBS} ${COMMON_LIBS})
 else ()
     set (CMAKE_SHARED_LINKER_FLAGS " -static-libgcc  -static-libstdc++")
-    target_link_libraries(_pulsar pulsarStatic ${PYTHON_WRAPPER_LIBS})
+    target_link_libraries(_pulsar pulsarStatic ${PYTHON_WRAPPER_LIBS} ${COMMON_LIBS})
 endif ()


Mime
View raw message