Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/ci-pr-validation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,28 @@ jobs:
- name: Stop Pulsar service
run: ./build-support/pulsar-test-service-stop.sh

build-static-link:
name: Build statically linked Python library
runs-on: ubuntu-latest
timeout-minutes: 120

steps:
- name: checkout
uses: actions/checkout@v3

- name: Install OpenSSL
run: sudo apt install libssl-dev

- name: Install Pulsar C++ client
run: build-support/install-cpp-client.sh

- name: Install dependencies
run: ./build-support/install-dependencies.sh ./deps

- name: Build Python
run: |
cmake -B build -DLINK_STATIC=ON -DCMAKE_PREFIX_PATH=$PWD/deps/install -DLINK_OPENSSL=ON
cmake --build build -j8

- name: Verify the extension
run: cd build && python3 -c 'import _pulsar'
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,24 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
option(LINK_STATIC "Link against static libraries" OFF)
MESSAGE(STATUS "LINK_STATIC: " ${LINK_STATIC})

# The pre-built C++ client might not link to OpenSSL statically.
# Enable this option to find OpenSSL when LINK_STATIC is ON.
option(LINK_OPENSSL "Link against OpenSSL" OFF)
message(STATUS "LINK_OPENSSL: " ${LINK_OPENSSL})

MESSAGE(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
MESSAGE(STATUS "Threads library: " ${CMAKE_THREAD_LIBS_INIT})

if (LINK_STATIC)
find_library(PULSAR_LIBRARY NAMES libpulsar.a)
find_library(PULSAR_LIBRARY NAMES libpulsarwithdeps.a)
if (LINK_OPENSSL)
find_package(OpenSSL REQUIRED)
message(STATUS "Found OPENSSL_LIBRARIES: " ${OPENSSL_LIBRARIES})
endif ()
else()
find_library(PULSAR_LIBRARY NAMES libpulsar.so)
find_library(PULSAR_LIBRARY NAMES pulsar)
endif()
message(STATUS "PULSAR_LIBRARY: ${PULSAR_LIBRARY}")

Expand Down Expand Up @@ -150,12 +159,14 @@ message(STATUS "All libraries: ${PYTHON_WRAPPER_LIBS}")
if (LINK_STATIC)
if (APPLE)
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS} -undefined dynamic_lookup")
target_link_libraries(_pulsar -Wl,-all_load ${PYTHON_WRAPPER_LIBS})
target_link_libraries(_pulsar -Wl,-all_load ${PYTHON_WRAPPER_LIBS}
"-framework Foundation"
"-framework SystemConfiguration")
else ()
if (NOT MSVC)
set (CMAKE_SHARED_LINKER_FLAGS " -static-libgcc -static-libstdc++")
endif()
target_link_libraries(_pulsar ${PYTHON_WRAPPER_LIBS})
target_link_libraries(_pulsar ${PYTHON_WRAPPER_LIBS} ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY})
endif ()
else()
target_link_libraries(_pulsar ${PYTHON_WRAPPER_LIBS})
Expand Down
24 changes: 24 additions & 0 deletions build-support/dep-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
#
# 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.
#

import yaml, sys

deps = yaml.safe_load(open("dependencies.yaml"))
print(deps[sys.argv[1]])
63 changes: 63 additions & 0 deletions build-support/install-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/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.
#
Copy link
Contributor Author

@BewareMyPower BewareMyPower Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script can be used for both CI verification and local development environment establishment. In future, we can replace this script with vcpkg.


set -e -x

ROOT_DIR=$(git rev-parse --show-toplevel)
cd $ROOT_DIR

CACHE_DIR=~/.pulsar-python-deps
if [[ $# -le 1 ]]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if [[ $# -le 1 ]]; then
if [[ $# -ge 1 ]]; then

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry I forgot to push latest commits. I found this issue as well.

CACHE_DIR=$(mkdir -p $1 && cd $1 && pwd)
fi
PREFIX=$CACHE_DIR/install
echo "Use $CACHE_DIR to cache dependencies"

python3 -m pip install pyyaml

BOOST_VERSION=$(./build-support/dep-version.py boost)
mkdir -p $CACHE_DIR
cd $CACHE_DIR

download() {
URL=$1
BASENAME=$(basename $URL)
if [[ ! -f $BASENAME ]]; then
echo "curl -O -L $URL"
curl -O -L $URL
fi
tar xfz $BASENAME
}

# Install Boost
BOOST_VERSION_=${BOOST_VERSION//./_}
DIR=boost_$BOOST_VERSION_
if [[ ! -f $DIR/.done ]]; then
echo "Building Boost $BOOST_VERSION"
download https://boostorg.jfrog.io/artifactory/main/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION_}.tar.gz
mkdir -p $PREFIX/include
pushd $DIR
./bootstrap.sh --with-libraries=python --with-python=python3 --prefix=$PREFIX 2>&1 >/dev/null
./b2 address-model=64 cxxflags="-fPIC" link=static threading=multi -j8 install 2>&1 >/dev/null
touch .done
popd
else
echo "Using cached Boost $BOOST_VERSION"
fi
20 changes: 20 additions & 0 deletions dependencies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# 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.
#

boost: 1.80.0