-
Notifications
You must be signed in to change notification settings - Fork 34
-
Notifications
You must be signed in to change notification settings - Fork 34
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
Which compile definitions are recommended for clang? #9
Comments
I am surprised it even attempted to build the C++20 coroutine example without Another option is to use Boost.Coroutine, the following code shows how to do that. You will also need to change lines 61-62 in 61: target_link_libraries(asio-grpc-hello-world-server-cpp20 PRIVATE asio-grpc-example-protos Boost::coroutine
62: Boost::thread) #include "protos/helloworld.grpc.pb.h"
#include <agrpc/asioGrpc.hpp>
#include <boost/asio/signal_set.hpp>
#include <boost/asio/spawn.hpp>
#include <grpcpp/server.h>
#include <grpcpp/server_builder.h>
#include <optional>
#include <thread>
int main()
{
std::optional<std::thread> shutdown_thread;
grpc::ServerBuilder builder;
std::unique_ptr<grpc::Server> server;
helloworld::Greeter::AsyncService service;
agrpc::GrpcContext grpc_context{builder.AddCompletionQueue()};
boost::asio::basic_signal_set signals{grpc_context, SIGINT, SIGTERM};
builder.AddListeningPort("0.0.0.0:50051", grpc::InsecureServerCredentials());
builder.RegisterService(&service);
server = builder.BuildAndStart();
boost::asio::spawn(grpc_context,
[&](const boost::asio::yield_context& yield)
{
while (true)
{
grpc::ServerContext server_context;
helloworld::HelloRequest request;
grpc::ServerAsyncResponseWriter<helloworld::HelloReply> writer{&server_context};
bool request_ok = agrpc::request(&helloworld::Greeter::AsyncService::RequestSayHello,
service, server_context, request, writer, yield);
if (!request_ok)
{
return;
}
helloworld::HelloReply response;
response.set_message("Hello " + request.name());
bool finish_ok = agrpc::finish(writer, response, grpc::Status::OK, yield);
}
});
signals.async_wait(
[&](auto&&, auto&&)
{
shutdown_thread.emplace(
[&]
{
server->Shutdown();
});
});
grpc_context.run();
shutdown_thread->join();
} I hope that is helpful and thank you for checking out the library! |
Thanks for pointing out that I was missing -fcoroutines-ts, I didn't realize that. But even when I do add -fcoroutines-ts in clang is crashing :( We build our product with both clang and gcc so if clang can't support C++20 coroutines then we have to use boost coroutines even for gcc so that we have the same source code. |
FYI: I got the C++20 coroutine example working with latest clang-13.0.0. The build doesn't crash and the examples work! |
I am able to compile and run the C++20 version with Clang 13 and Ah nice, I was just about to write the same :) |
I'm not using -D_LIBCPP_ENABLE_CXX20_REMOVED_TYPE_TRAITS and it works. But I am using ASIO_GRPC_USE_BOOST_CONTAINER. I also have -stdlib=libc++. I think for clang build that ASIO_GRPC_USE_BOOST_CONTAINER is required, you are using ASIO_GRPC_USE_BOOST_CONTAINER for your working clang 13 build? |
Correct, I am using that as well since libc++ does not provide <memory_resource>. For me Boost.Asio tries to use |
To handle the boost.asio issue I used -DBOOST_ASIO_HAS_STD_INVOKE_RESULT for my boost build for clang13. I meant to also use this for my build of the asio-grpc example but looks like I mistakenly left it out. |
Actually -DBOOST_ASIO_HAS_STD_INVOKE_RESULT was also in my build of the asio-grpc example. I made an error in my last comment to say it wasn't there. |
Clang 10, 11 and 12 are now also building and testing with coroutines on CI: https://github.com/Tradias/asio-grpc/runs/4193734840?check_suite_focus=true Although I do not understand the warning
Sounds like it is cross-compiling. Do you have any idea perhaps? |
I don't understand your warning. Today after doing some cleanup I tried again with clang-10.0.1 and C++20 coroutines worked with clang-10.0.1! Don't know why they didn't work before? What is even more surprising is that on my first attempt I forgot the -fcoroutines-ts, but it compiled and ran anyway and worked with C++20 coroutijnes! Here is my compilation command line with clang-10.0.1 in case it helps:
And here is my link:
I'm using more than your CMakeLists.txt to build these examples. I also did some slight modifications to your CMakeLists.txt to fit in our system. I removed upper portions of paths to source/object files in the above. We also link with many more of our own libraries that aren't relevant so I left those out. |
Excellent, so it works for you just like it does for CI and CI uses Clang 10.0.0 even. Do you think some of the changes you did to the CMakeLists.txt could be added upstream as well? Can you maybe list some of them? I have already added the |
The main changes I did the CMakeLists.txt hard code some paths and options vs what is in the library. It would not be appropriate to add them to the github as they wouldn't apply. So I think just having the -fcoroutines-ts is all that is needed. |
Which compile definitions are recommended for clang build on Linux?
I already figured out that I need to set on my cmake line:
-DASIO_GRPC_USE_BOOST_CONTAINER=1
But I wonder if there are any others?
I'm using a slightly older version of asio-grpc, it would take me a little effort to update so don't want to have to do that. I'm using commit a17b559. Don't know if this is the reason?
The reason that I ask is that when I use clang 10.0.1 I get a clang crash when trying to build hello-world-server-cpp20:
The text was updated successfully, but these errors were encountered: