Skip to content

Conversation

@BewareMyPower
Copy link
Contributor

Motivation

See discussions here: #28 (comment)

The original purpose to not include static OpenSSL library in libpulsarwithnossl.so and libpulsarwithdeps.a is apache/pulsar#6458. However, the ABI compatibility of OpenSSL is not good. If the Pulsar C++ library links dynamically to OpenSSL and the user only changes the OpenSSL dynamic library, some symbols might not be found.

Modifications

Use LINK_STATIC option to determine whether to link to OpenSSL library statically. After that, there are only 3 libraries generated when LINK_STATIC is ON.

  • libpulsar.so: the dynamic pulsar-client-cpp library.
  • libpulsar.a: the static pulsar-client-cpp library. When it's used, users must link to all 3rd party dependencies (OpenSSL, curl, etc.)
  • libpulsarwithdeps.a: the static pulsar-client-cpp library.

Documentation

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

### Motivation

See discussions here: apache#28 (comment)

The original purpose to not include static OpenSSL library in
`libpulsarwithnossl.so` and `libpulsarwithdeps.a` is
apache/pulsar#6458. However, the ABI
compatibility of OpenSSL is not good. If the Pulsar C++ library links
dynamically to OpenSSL and the user only changes the OpenSSL dynamic
library, some symbols might not be found.

### Modifications

Use `LINK_STATIC` option to determine whether to link to OpenSSL library
statically. After that, there are only 3 libraries generated when
`LINK_STATIC` is ON.
- `libpulsar.so`: the dynamic pulsar-client-cpp library.
- `libpulsar.a`: the static pulsar-client-cpp library. When it's used,
  users must link to all 3rd party dependencies (OpenSSL, curl, etc.)
- `libpulsarwithdeps.a`: the static pulsar-client-cpp library.
@BewareMyPower BewareMyPower added this to the 3.0.0 milestone Oct 9, 2022
@BewareMyPower BewareMyPower self-assigned this Oct 9, 2022
@BewareMyPower
Copy link
Contributor Author

BewareMyPower commented Oct 9, 2022

After this PR, here are examples about how do I build an application with the given three libraries on macOS. Assume they are built with LINK_STATIC=ON option. It's a little tricky to build the static library of libcurl, see my comments here: apache/pulsar#4967 (comment)

Given such an application code (example.cc):

#include <pulsar/Client.h>
using namespace pulsar;

int main() {
    Client client("pulsar://localhost:6650");
    client.close();
}

Assuming the headers are under include/ directory and the libraries are under lib/ directory, which is not a system path.

libpulsar.so

Build:

clang++ example.cc -I include/ -L lib/ -lpulsar

Run:

# You have to add the path of `libpulsar.dylib` to a specific env variable so that symbols can be found
DYLD_LIBRARY_PATH=$PWD/lib ./a.out

libpulsar.a

Build:

# You have to link all 3rd party dependencies.
# BTW, the directory followed by `-L` might be different in your actual env.
clang++ example.cc -I include/ \
lib/libpulsar.a \
-lcurl -lz -lzstd \
-L /usr/local/opt/protobuf/lib/ -lprotobuf \
-L /usr/local/opt/openssl@3/lib/ -lssl -lcrypto \
-L /usr/local/opt/snappy/lib/ -lsnappy

Run:

./a.out

libpulsarwithdeps.a

Build:

# NOTE: these -framework options are required by curl.a and only needed on macOS 
clang++ example.cc lib/libpulsarwithdeps.a -framework SystemConfiguration -framework CoreFoundation

Run:

./a.out

@BewareMyPower
Copy link
Contributor Author

I will fix the rpm / deb scripts soon.

@BewareMyPower
Copy link
Contributor Author

image

I see the "Squash and merge" button is not disabled even if some tests failed. Could you help make some workflows REQUIRED? @merlimat

@merlimat merlimat merged commit d72924f into apache:main Oct 10, 2022
@BewareMyPower BewareMyPower deleted the bewaremypower/optimize-openssl-find branch October 11, 2022 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants