Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue 2461][pulsar-client-cpp] Modified CMake files and source to enable compilation on Windows #4071

Merged
merged 13 commits into from
Apr 26, 2019

Conversation

heronr
Copy link
Contributor

@heronr heronr commented Apr 18, 2019

Fixes #2461

Motivation

My motivation was to be able to use the pulsar cpp client on Windows systems.

Modifications

There are a number of modifications I needed to make to enable Windows compilation

  • Extensive rework of multiple CMakeLists.txt files
  • The creation of a PULSAR_PUBLIC define to define symbol visibility in lieue of #pragma GCC visibility push(default). This is because Windows requires specifying __declspec(dllexport) and __declspec(import) explicitly and does not have a #pragma GCC visibility push(default) analogue.
  • all calls to usleep or sleep have been replaced with calls to boost::this_thread::sleep()

Verifying this change

This change is a trivial rework / code cleanup without any test coverage. However, it does introduce a new platform to test on. It is likely that CI checks will have to be created.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): yes
    • It adds a dependency to the dlfcn-win32 library for Windows builds.
  • The public API: no
  • The schema: no
  • The default values of configurations: no
  • The wire protocol: no
  • The rest endpoints: no
  • The admin cli options: no
  • Anything that affects deployment: no

Documentation

  • Does this pull request introduce a new feature?: No
  • The README.md file in pulsar-client-cpp has been updated with instructions for Windows compilation

heronr added 2 commits April 18, 2019 00:31
This introduces a dependency on dlfcn-win32
(https://github.com/dlfcn-win32/dlfcn-win32). This change involved some
reworking of the CMake file and creating 2 new defines, PULSAR_PUBLIC and PULSAR_STATIC, to
enable building static or shared libraries on Windows.
@heronr heronr force-pushed the CppClientWinCompile branch from b0e39b5 to edbdcc8 Compare April 18, 2019 07:31
find_package call to get the include dir and library and expects the
user to have gotten the library separately.
Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

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

Very nice work!

Just left few minor comments

mandatoryStop_(mandatoryStop),
randomSeed_(time(NULL)) {}
mandatoryStop_(mandatoryStop)
#ifndef _MSC_VER
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we could use boost::random to get a portable version of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a great idea. I went ahead modified Backoff to use a boost::random::mt19937 object for random number generation.

@@ -51,7 +53,7 @@ TEST(BackoffTest, firstBackoffTimerTest) {
Backoff backoff(milliseconds(100), seconds(60), milliseconds(1900));
ASSERT_EQ(backoff.next().total_milliseconds(), 100);
boost::posix_time::ptime firstBackOffTime = PulsarFriend::getFirstBackoffTime(backoff);
usleep(300 * 1000);
boost::this_thread::sleep(boost::posix_time::milliseconds(300));
Copy link
Contributor

Choose a reason for hiding this comment

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

We could also std::this_thread::sleep_for() instead of boost

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's true and it does mean one less boost lib to link. If that is preferable I can go ahead and make the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did go ahead and switch everything to std::this_thread::sleep_for as you suggested

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice. Thanks!

// Ensure this service has not already been closed. This is
// because worker_.join() is not re-entrant on Windows
if (work_)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Even if Windows related, can you submit this fix as a separate PR so that it gets more visible?

Also, the { on new line will fail on the make check-format. You should be able to do make format and automatically fix all the formatting (that uses clang-format underneath)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I took this change out of this PR and into a new one, #4084

In addition, I realized that I didn't notice the check-format failure because the Windows version of the CMake files were omitting those targets. I re-added them and was able to correct a host of formatting mistakes.

@merlimat merlimat added this to the 2.4.0 milestone Apr 19, 2019
@merlimat merlimat added component/c++ type/feature The PR added a new feature or issue requested a new feature labels Apr 19, 2019
@merlimat
Copy link
Contributor

Once this is merged, we can start looking in how to enable C++ build validation for Windows. Apache's Jenkins has several Windows worker nodes.

@merlimat
Copy link
Contributor

@heronr There seems to be a linking issue on the test tools (protobuf missing) : https://builds.apache.org/job/pulsar_precommit_cpp/7133/console

@heronr
Copy link
Contributor Author

heronr commented Apr 26, 2019

@merlimat Finally got all the tests passing. Should be good to go.

@sijie sijie merged commit b3596c4 into apache:master Apr 26, 2019
@heronr heronr deleted the CppClientWinCompile branch April 26, 2019 04:18
codelipenghui pushed a commit that referenced this pull request Nov 17, 2020
### Motivation

I don't think the following `--exclude-libs,ALL` are reflected in linker.
 [https://github.com/apache/pulsar/blob/f8080f4eb690d751f1b07ca54c23e1cd7774473f/pulsar-client-cpp/CMakeLists.txt#L214](https://github.com/apache/pulsar/blob/f8080f4eb690d751f1b07ca54c23e1cd7774473f/pulsar-client-cpp/CMakeLists.txt#L214)

I think `--exclude-libs,ALL` needs to be set in `add_link_options`.
 [add_link_options](https://cmake.org/cmake/help/latest/command/add_link_options.html)

`add_link_options` can be used from v3.13.
Therefore, fixed(reverted) `add_compile_options` to `set`.([#4071](#4071))
flowchartsman pushed a commit to flowchartsman/pulsar that referenced this pull request Nov 17, 2020
### Motivation

I don't think the following `--exclude-libs,ALL` are reflected in linker.
 [https://github.com/apache/pulsar/blob/f8080f4eb690d751f1b07ca54c23e1cd7774473f/pulsar-client-cpp/CMakeLists.txt#L214](https://github.com/apache/pulsar/blob/f8080f4eb690d751f1b07ca54c23e1cd7774473f/pulsar-client-cpp/CMakeLists.txt#L214)

I think `--exclude-libs,ALL` needs to be set in `add_link_options`.
 [add_link_options](https://cmake.org/cmake/help/latest/command/add_link_options.html)

`add_link_options` can be used from v3.13.
Therefore, fixed(reverted) `add_compile_options` to `set`.([apache#4071](apache#4071))
merlimat pushed a commit to apache/pulsar-client-python that referenced this pull request Sep 29, 2022
### Motivation

I don't think the following `--exclude-libs,ALL` are reflected in linker.
 [https://github.com/apache/pulsar/blob/f8080f4eb690d751f1b07ca54c23e1cd7774473f/pulsar-client-cpp/CMakeLists.txt#L214](https://github.com/apache/pulsar/blob/f8080f4eb690d751f1b07ca54c23e1cd7774473f/pulsar-client-cpp/CMakeLists.txt#L214)

I think `--exclude-libs,ALL` needs to be set in `add_link_options`.
 [add_link_options](https://cmake.org/cmake/help/latest/command/add_link_options.html)

`add_link_options` can be used from v3.13.
Therefore, fixed(reverted) `add_compile_options` to `set`.([#4071](apache/pulsar#4071))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature The PR added a new feature or issue requested a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

windows server support needed!
3 participants