-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
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.
b0e39b5
to
edbdcc8
Compare
find_package call to get the include dir and library and expects the user to have gotten the library separately.
There was a problem hiding this 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
pulsar-client-cpp/lib/Backoff.cc
Outdated
mandatoryStop_(mandatoryStop), | ||
randomSeed_(time(NULL)) {} | ||
mandatoryStop_(mandatoryStop) | ||
#ifndef _MSC_VER |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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_) | ||
{ |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
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. |
and including format corrected files
better portability
and removed the dependency on boost::thread
@heronr There seems to be a linking issue on the test tools (protobuf missing) : https://builds.apache.org/job/pulsar_precommit_cpp/7133/console |
and fixed other linker errors
@merlimat Finally got all the tests passing. Should be good to go. |
### 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))
### 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))
### 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))
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
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:
Documentation