make grpc work on Mac OSX with premake

This commit is contained in:
Erwin Coumans
2018-09-04 14:49:12 -07:00
parent 710e660763
commit 51f9a6fd0d
10 changed files with 8289 additions and 10911 deletions

View File

@@ -72,10 +72,81 @@
newoption
{
trigger = "grpc",
trigger = "enable_grpc",
description = "Build GRPC server/client features for PyBullet/BulletRobotics"
}
if os.is("Linux") then
default_grpc_include_dir = "usr/local/include/GRPC"
default_grpc_lib_dir = "/usr/local/lib/"
end
if os.is("macosx") then
default_grpc_include_dir = "/usr/local/Cellar/grpc/1.14.1/include"
default_grpc_lib_dir = "/usr/local/Cellar/grpc/1.14.1/lib"
default_protobuf_include_dir = "/usr/local/Cellar/protobuf/3.6.0/include/"
default_protobuf_lib_dir = "/usr/local/Cellar/protobuf/3.6.0/lib"
end
if os.is("Windows") then
default_grpc_include_dir = "c:/grpc/include"
default_grpc_lib_dir = "c:/grpc/lib"
end
newoption
{
trigger = "grpc_include_dir",
value = default_grpc_include_dir,
description = "(optional) GRPC include directory"
}
newoption
{
trigger = "grpc_lib_dir",
value = default_grpc_lib_dir,
description = "(optional) GRPC library directory "
}
newoption
{
trigger = "protobuf_include_dir",
value = default_protobuf_include_dir,
description = "(optional) protobuf include directory"
}
newoption
{
trigger = "protobuf_lib_dir",
value = default_protobuf_lib_dir,
description = "(optional) protobuf library directory "
}
if _OPTIONS["enable_grpc"] then
function initGRPC()
buildoptions { "-std=c++11", "-stdlib=libc++" }
defines {"BT_ENABLE_GRPC"}
includedirs {
_OPTIONS["grpc_include_dir"], _OPTIONS["protobuf_include_dir"],
}
libdirs {
_OPTIONS["grpc_lib_dir"], _OPTIONS["protobuf_lib_dir"],
}
links { "grpc","grpc++", "grpc++_reflection", "gpr", "protobuf"}
files { projectRootDir .. "examples/SharedMemory/grpc/ConvertGRPCBullet.cpp",
projectRootDir .. "examples/SharedMemory/grpc/ConvertGRPCBullet.h",
projectRootDir .. "examples/SharedMemory/grpc/pybullet.grpc.pb.cpp",
projectRootDir .. "examples/SharedMemory/grpc/pybullet.grpc.pb.h",
projectRootDir .. "examples/SharedMemory/grpc/pybullet.pb.cpp",
projectRootDir .. "examples/SharedMemory/grpc/pybullet.pb.h", }
end
end
-- _OPTIONS["midi"] = "1";
@@ -201,10 +272,6 @@ end
defines {"BT_USE_DOUBLE_PRECISION"}
end
if _OPTIONS["grpc"] then
defines {"BT_ENABLE_GRPC"}
end
configurations {"Release", "Debug"}
configuration "Release"
flags { "Optimize", "EnableSSE2","StaticRuntime", "NoMinimalRebuild", "FloatFast"}
@@ -299,6 +366,9 @@ if os.is("Windows") then
default_glfw_lib_name = "glfw3"
end
if not _OPTIONS["glfw_lib_dir"] then
_OPTIONS["glfw_lib_dir"] = default_glfw_lib_dir
end
@@ -342,8 +412,6 @@ end
if _OPTIONS["enable_glfw"] then
defines {"B3_USE_GLFW"}
function initOpenGL()
includedirs {
projectRootDir .. "examples/ThirdPartyLibs/glad"

View File

@@ -9,6 +9,16 @@ project ("App_RobotSimulator")
"../../examples/ThirdPartyLibs"}
defines {"B3_USE_ROBOTSIM_GUI", "PHYSICS_IN_PROCESS_EXAMPLE_BROWSER"}
if _OPTIONS["enable_grpc"] then
initGRPC()
files {
"../../examples/SharedMemory/PhysicsClientGRPC.cpp",
"../../examples/SharedMemory/PhysicsClientGRPC.h",
"../../examples/SharedMemory/PhysicsClientGRPC_C_API.cpp",
"../../examples/SharedMemory/PhysicsClientGRPC_C_API.h",
}
end
links{"BulletRobotics", "BulletExampleBrowserLib", "gwen", "OpenGL_Window","BulletFileLoader","BulletWorldImporter","BulletSoftBody", "BulletInverseDynamicsUtils", "BulletInverseDynamics", "BulletDynamics","BulletCollision","LinearMath","Bullet3Common"}
initOpenGL()

View File

@@ -546,6 +546,7 @@ SharedMemoryCommand* convertGRPCToBulletCommand(const PyBulletCommand& grpcComma
}
int sz = grpcCommand.unknowncommandbinaryblob_size();
if (sz)
{
@@ -571,7 +572,7 @@ SharedMemoryCommand* convertGRPCToBulletCommand(const PyBulletCommand& grpcComma
if (cmdPtr == 0)
{
switch (grpcCommand.commandtype())
switch (cmd.m_type)
{
case CMD_RESET_SIMULATION:
@@ -1244,7 +1245,7 @@ SharedMemoryCommand* convertGRPCToBulletCommand(const PyBulletCommand& grpcComma
printf("unknown convertGRPCToBulletCommand");
assert(0);
}
}
}
}

View File

@@ -7,20 +7,7 @@ project ("App_PhysicsServerSharedMemoryBridgeGRPC")
includedirs {"../../ThirdPartyLibs/clsocket/src","../../../src",".."}
if os.is("Windows") then
defines { "WIN32", "_WIN32_WINNT=0x0600" }
includedirs {"../../ThirdPartyLibs/grpc/include"}
libdirs {"../../ThirdPartyLibs/grpc/lib/win64"}
links {"grpc","grpc++","grpc++_reflection","gpr",
"libprotobufd","crypto","ssl","zlibstaticd","Ws2_32","Winmm" }
end
if os.is("Linux") then
defines {"_LINUX"}
end
if os.is("MacOSX") then
defines {"_DARWIN"}
end
initGRPC()
links {
"BulletFileLoader",
@@ -30,12 +17,6 @@ project ("App_PhysicsServerSharedMemoryBridgeGRPC")
files {
"main.cpp",
"ConvertGRPCBullet.cpp",
"ConvertGRPCBullet.h",
"pybullet.grpc.pb.cpp",
"pybullet.grpc.pb.h",
"pybullet.pb.cpp",
"pybullet.pb.h",
"../PhysicsClient.cpp",
"../PhysicsClient.h",
"../PhysicsDirect.cpp",
@@ -73,21 +54,8 @@ links {
}
initGRPC()
if os.is("Windows") then
defines { "WIN32", "_WIN32_WINNT=0x0600" }
includedirs {"../../ThirdPartyLibs/grpc/include"}
libdirs {"../../ThirdPartyLibs/grpc/lib/win64"}
links {"grpc","grpc++","grpc++_reflection","gpr",
"libprotobufd","crypto","ssl","zlibstaticd","Ws2_32","Winmm" }
end
if os.is("Linux") then
defines {"_LINUX"}
links{"dl"}
end
if os.is("MacOSX") then
defines {"_DARWIN"}
end
language "C++"
@@ -156,11 +124,5 @@ myfiles =
files {
myfiles,
"main.cpp",
"ConvertGRPCBullet.cpp",
"ConvertGRPCBullet.h",
"pybullet.grpc.pb.cpp",
"pybullet.grpc.pb.h",
"pybullet.pb.cpp",
"pybullet.pb.h",
}

View File

@@ -5,14 +5,14 @@
#include "pybullet.pb.h"
#include "pybullet.grpc.pb.h"
#include <grpc++/impl/codegen/async_stream.h>
#include <grpc++/impl/codegen/async_unary_call.h>
#include <grpc++/impl/codegen/channel_interface.h>
#include <grpc++/impl/codegen/client_unary_call.h>
#include <grpc++/impl/codegen/method_handler_impl.h>
#include <grpc++/impl/codegen/rpc_service_method.h>
#include <grpc++/impl/codegen/service_type.h>
#include <grpc++/impl/codegen/sync_stream.h>
#include <grpcpp/impl/codegen/async_stream.h>
#include <grpcpp/impl/codegen/async_unary_call.h>
#include <grpcpp/impl/codegen/channel_interface.h>
#include <grpcpp/impl/codegen/client_unary_call.h>
#include <grpcpp/impl/codegen/method_handler_impl.h>
#include <grpcpp/impl/codegen/rpc_service_method.h>
#include <grpcpp/impl/codegen/service_type.h>
#include <grpcpp/impl/codegen/sync_stream.h>
namespace pybullet_grpc {
static const char* PyBulletAPI_method_names[] = {
@@ -20,27 +20,32 @@ static const char* PyBulletAPI_method_names[] = {
};
std::unique_ptr< PyBulletAPI::Stub> PyBulletAPI::NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options) {
(void)options;
std::unique_ptr< PyBulletAPI::Stub> stub(new PyBulletAPI::Stub(channel));
return stub;
}
PyBulletAPI::Stub::Stub(const std::shared_ptr< ::grpc::ChannelInterface>& channel)
: channel_(channel), rpcmethod_SubmitCommand_(PyBulletAPI_method_names[0], ::grpc::RpcMethod::NORMAL_RPC, channel)
: channel_(channel), rpcmethod_SubmitCommand_(PyBulletAPI_method_names[0], ::grpc::internal::RpcMethod::NORMAL_RPC, channel)
{}
::grpc::Status PyBulletAPI::Stub::SubmitCommand(::grpc::ClientContext* context, const ::pybullet_grpc::PyBulletCommand& request, ::pybullet_grpc::PyBulletStatus* response) {
return ::grpc::BlockingUnaryCall(channel_.get(), rpcmethod_SubmitCommand_, context, request, response);
return ::grpc::internal::BlockingUnaryCall(channel_.get(), rpcmethod_SubmitCommand_, context, request, response);
}
::grpc::ClientAsyncResponseReader< ::pybullet_grpc::PyBulletStatus>* PyBulletAPI::Stub::AsyncSubmitCommandRaw(::grpc::ClientContext* context, const ::pybullet_grpc::PyBulletCommand& request, ::grpc::CompletionQueue* cq) {
return new ::grpc::ClientAsyncResponseReader< ::pybullet_grpc::PyBulletStatus>(channel_.get(), cq, rpcmethod_SubmitCommand_, context, request);
return ::grpc::internal::ClientAsyncResponseReaderFactory< ::pybullet_grpc::PyBulletStatus>::Create(channel_.get(), cq, rpcmethod_SubmitCommand_, context, request, true);
}
::grpc::ClientAsyncResponseReader< ::pybullet_grpc::PyBulletStatus>* PyBulletAPI::Stub::PrepareAsyncSubmitCommandRaw(::grpc::ClientContext* context, const ::pybullet_grpc::PyBulletCommand& request, ::grpc::CompletionQueue* cq) {
return ::grpc::internal::ClientAsyncResponseReaderFactory< ::pybullet_grpc::PyBulletStatus>::Create(channel_.get(), cq, rpcmethod_SubmitCommand_, context, request, false);
}
PyBulletAPI::Service::Service() {
AddMethod(new ::grpc::RpcServiceMethod(
AddMethod(new ::grpc::internal::RpcServiceMethod(
PyBulletAPI_method_names[0],
::grpc::RpcMethod::NORMAL_RPC,
new ::grpc::RpcMethodHandler< PyBulletAPI::Service, ::pybullet_grpc::PyBulletCommand, ::pybullet_grpc::PyBulletStatus>(
::grpc::internal::RpcMethod::NORMAL_RPC,
new ::grpc::internal::RpcMethodHandler< PyBulletAPI::Service, ::pybullet_grpc::PyBulletCommand, ::pybullet_grpc::PyBulletStatus>(
std::mem_fn(&PyBulletAPI::Service::SubmitCommand), this)));
}

View File

@@ -6,20 +6,20 @@
#include "pybullet.pb.h"
#include <grpc++/impl/codegen/async_stream.h>
#include <grpc++/impl/codegen/async_unary_call.h>
#include <grpc++/impl/codegen/method_handler_impl.h>
#include <grpc++/impl/codegen/proto_utils.h>
#include <grpc++/impl/codegen/rpc_method.h>
#include <grpc++/impl/codegen/service_type.h>
#include <grpc++/impl/codegen/status.h>
#include <grpc++/impl/codegen/stub_options.h>
#include <grpc++/impl/codegen/sync_stream.h>
#include <grpcpp/impl/codegen/async_generic_service.h>
#include <grpcpp/impl/codegen/async_stream.h>
#include <grpcpp/impl/codegen/async_unary_call.h>
#include <grpcpp/impl/codegen/method_handler_impl.h>
#include <grpcpp/impl/codegen/proto_utils.h>
#include <grpcpp/impl/codegen/rpc_method.h>
#include <grpcpp/impl/codegen/service_type.h>
#include <grpcpp/impl/codegen/status.h>
#include <grpcpp/impl/codegen/stub_options.h>
#include <grpcpp/impl/codegen/sync_stream.h>
namespace grpc {
class CompletionQueue;
class Channel;
class RpcService;
class ServerCompletionQueue;
class ServerContext;
} // namespace grpc
@@ -28,6 +28,9 @@ namespace pybullet_grpc {
class PyBulletAPI final {
public:
static constexpr char const* service_full_name() {
return "pybullet_grpc.PyBulletAPI";
}
class StubInterface {
public:
virtual ~StubInterface() {}
@@ -36,8 +39,12 @@ class PyBulletAPI final {
std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::pybullet_grpc::PyBulletStatus>> AsyncSubmitCommand(::grpc::ClientContext* context, const ::pybullet_grpc::PyBulletCommand& request, ::grpc::CompletionQueue* cq) {
return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::pybullet_grpc::PyBulletStatus>>(AsyncSubmitCommandRaw(context, request, cq));
}
std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::pybullet_grpc::PyBulletStatus>> PrepareAsyncSubmitCommand(::grpc::ClientContext* context, const ::pybullet_grpc::PyBulletCommand& request, ::grpc::CompletionQueue* cq) {
return std::unique_ptr< ::grpc::ClientAsyncResponseReaderInterface< ::pybullet_grpc::PyBulletStatus>>(PrepareAsyncSubmitCommandRaw(context, request, cq));
}
private:
virtual ::grpc::ClientAsyncResponseReaderInterface< ::pybullet_grpc::PyBulletStatus>* AsyncSubmitCommandRaw(::grpc::ClientContext* context, const ::pybullet_grpc::PyBulletCommand& request, ::grpc::CompletionQueue* cq) = 0;
virtual ::grpc::ClientAsyncResponseReaderInterface< ::pybullet_grpc::PyBulletStatus>* PrepareAsyncSubmitCommandRaw(::grpc::ClientContext* context, const ::pybullet_grpc::PyBulletCommand& request, ::grpc::CompletionQueue* cq) = 0;
};
class Stub final : public StubInterface {
public:
@@ -46,11 +53,15 @@ class PyBulletAPI final {
std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::pybullet_grpc::PyBulletStatus>> AsyncSubmitCommand(::grpc::ClientContext* context, const ::pybullet_grpc::PyBulletCommand& request, ::grpc::CompletionQueue* cq) {
return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::pybullet_grpc::PyBulletStatus>>(AsyncSubmitCommandRaw(context, request, cq));
}
std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::pybullet_grpc::PyBulletStatus>> PrepareAsyncSubmitCommand(::grpc::ClientContext* context, const ::pybullet_grpc::PyBulletCommand& request, ::grpc::CompletionQueue* cq) {
return std::unique_ptr< ::grpc::ClientAsyncResponseReader< ::pybullet_grpc::PyBulletStatus>>(PrepareAsyncSubmitCommandRaw(context, request, cq));
}
private:
std::shared_ptr< ::grpc::ChannelInterface> channel_;
::grpc::ClientAsyncResponseReader< ::pybullet_grpc::PyBulletStatus>* AsyncSubmitCommandRaw(::grpc::ClientContext* context, const ::pybullet_grpc::PyBulletCommand& request, ::grpc::CompletionQueue* cq) override;
const ::grpc::RpcMethod rpcmethod_SubmitCommand_;
::grpc::ClientAsyncResponseReader< ::pybullet_grpc::PyBulletStatus>* PrepareAsyncSubmitCommandRaw(::grpc::ClientContext* context, const ::pybullet_grpc::PyBulletCommand& request, ::grpc::CompletionQueue* cq) override;
const ::grpc::internal::RpcMethod rpcmethod_SubmitCommand_;
};
static std::unique_ptr<Stub> NewStub(const std::shared_ptr< ::grpc::ChannelInterface>& channel, const ::grpc::StubOptions& options = ::grpc::StubOptions());
@@ -73,7 +84,7 @@ class PyBulletAPI final {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status SubmitCommand(::grpc::ServerContext* context, const ::pybullet_grpc::PyBulletCommand* request, ::pybullet_grpc::PyBulletStatus* response) final override {
::grpc::Status SubmitCommand(::grpc::ServerContext* context, const ::pybullet_grpc::PyBulletCommand* request, ::pybullet_grpc::PyBulletStatus* response) override {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
@@ -94,25 +105,45 @@ class PyBulletAPI final {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status SubmitCommand(::grpc::ServerContext* context, const ::pybullet_grpc::PyBulletCommand* request, ::pybullet_grpc::PyBulletStatus* response) final override {
::grpc::Status SubmitCommand(::grpc::ServerContext* context, const ::pybullet_grpc::PyBulletCommand* request, ::pybullet_grpc::PyBulletStatus* response) override {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
};
template <class BaseClass>
class WithRawMethod_SubmitCommand : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(const Service *service) {}
public:
WithRawMethod_SubmitCommand() {
::grpc::Service::MarkMethodRaw(0);
}
~WithRawMethod_SubmitCommand() override {
BaseClassMustBeDerivedFromService(this);
}
// disable synchronous version of this method
::grpc::Status SubmitCommand(::grpc::ServerContext* context, const ::pybullet_grpc::PyBulletCommand* request, ::pybullet_grpc::PyBulletStatus* response) override {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}
void RequestSubmitCommand(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) {
::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag);
}
};
template <class BaseClass>
class WithStreamedUnaryMethod_SubmitCommand : public BaseClass {
private:
void BaseClassMustBeDerivedFromService(const Service *service) {}
public:
WithStreamedUnaryMethod_SubmitCommand() {
::grpc::Service::MarkMethodStreamed(0,
new ::grpc::StreamedUnaryHandler< ::pybullet_grpc::PyBulletCommand, ::pybullet_grpc::PyBulletStatus>(std::bind(&WithStreamedUnaryMethod_SubmitCommand<BaseClass>::StreamedSubmitCommand, this, std::placeholders::_1, std::placeholders::_2)));
new ::grpc::internal::StreamedUnaryHandler< ::pybullet_grpc::PyBulletCommand, ::pybullet_grpc::PyBulletStatus>(std::bind(&WithStreamedUnaryMethod_SubmitCommand<BaseClass>::StreamedSubmitCommand, this, std::placeholders::_1, std::placeholders::_2)));
}
~WithStreamedUnaryMethod_SubmitCommand() override {
BaseClassMustBeDerivedFromService(this);
}
// disable regular version of this method
::grpc::Status SubmitCommand(::grpc::ServerContext* context, const ::pybullet_grpc::PyBulletCommand* request, ::pybullet_grpc::PyBulletStatus* response) final override {
::grpc::Status SubmitCommand(::grpc::ServerContext* context, const ::pybullet_grpc::PyBulletCommand* request, ::pybullet_grpc::PyBulletStatus* response) override {
abort();
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, "");
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -58,10 +58,10 @@ def run():
#for i in range (1000):
# print("submit StepSimulationCommand: ", i)
# response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(stepSimulationCommand=pybullet_pb2.StepSimulationCommand()))
# print("PyBullet client received: " , response.statusType)
for i in range (1000):
print("submit StepSimulationCommand: ", i)
response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(stepSimulationCommand=pybullet_pb2.StepSimulationCommand()))
print("PyBullet client received: " , response.statusType)
#print("TerminateServerCommand")
#response = stub.SubmitCommand(pybullet_pb2.PyBulletCommand(terminateServerCommand=pybullet_pb2.TerminateServerCommand()))

View File

@@ -474,6 +474,6 @@ include "plugins/tinyRendererPlugin"
include "plugins/pdControlPlugin"
include "plugins/collisionFilterPlugin"
if _OPTIONS["grpc"] then
if _OPTIONS["enable_grpc"] then
include "grpc"
end