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

C++ SDK cross-platform build #421

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sdks/cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
grpc
Makefile
CMakeFiles
CMakeCache.txt
*.cmake
lib
97 changes: 97 additions & 0 deletions sdks/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright 2018 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required (VERSION 3.1.3)

project(agonessdk C CXX)

find_package(Git)

include(ExternalProject)

# Enable C++11 support
set(CMAKE_CXX_STANDARD 11)
set(GRPC_TARGET_NAME gRPC_LIBRARY)

# Build gRPC codebase
ExternalProject_Add(${GRPC_TARGET_NAME}
PREFIX grpc
GIT_REPOSITORY "https://github.com/grpc/grpc.git"
GIT_TAG "v1.16.0"
CMAKE_ARGS
-DCMAKE_BUILD_TYPE:STRING=Release
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/grpc
-DgRPC_BUILD_TESTS:BOOL=OFF
-DgRPC_BUILD_CODEGEN:BOOL=OFF
-DgRPC_BUILD_CSHARP_EXT:BOOL=OFF
-DgRPC_BACKWARDS_COMPATIBILITY_MODE:BOOL=OFF
-DgRPC_INSTALL:BOOL=OFF
)

# Have CMake output libraries to ./lib
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib/${CMAKE_BUILD_TYPE})

if (MSVC)
# Required by gRPC's headers when compiling on Windows
add_definitions(-D_WIN32_WINNT=0x600)
endif()

# Agones SDK source files
set(AGONES_SDK_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/sdk.cc
${CMAKE_CURRENT_SOURCE_DIR}/sdk.pb.cc
${CMAKE_CURRENT_SOURCE_DIR}/sdk.grpc.pb.cc
${CMAKE_CURRENT_SOURCE_DIR}/google/api/annotations.pb.cc
${CMAKE_CURRENT_SOURCE_DIR}/google/api/http.pb.cc
)

# Agones SDK library target
add_library(${PROJECT_NAME} SHARED ${AGONES_SDK_SOURCES})

# Header directories
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/grpc/include
)

# Make sure we build gRPC before we build Agones
add_dependencies(${PROJECT_NAME} ${GRPC_TARGET_NAME})

# gRPC dependency libraries
if (MSVC)
set(GRPC_LIBRARIES
ws2_32.lib
${CMAKE_CURRENT_BINARY_DIR}/grpc/lib/libprotobuf.lib
${CMAKE_CURRENT_BINARY_DIR}/grpc/lib/cares.lib
${CMAKE_CURRENT_BINARY_DIR}/grpc/lib/zlib.lib
${CMAKE_CURRENT_BINARY_DIR}/grpc/src/${GRPC_TARGET_NAME}-build/Release/address_sorting.lib
${CMAKE_CURRENT_BINARY_DIR}/grpc/src/${GRPC_TARGET_NAME}-build/Release/gpr.lib
${CMAKE_CURRENT_BINARY_DIR}/grpc/src/${GRPC_TARGET_NAME}-build/Release/grpc++_unsecure.lib
${CMAKE_CURRENT_BINARY_DIR}/grpc/src/${GRPC_TARGET_NAME}-build/Release/grpc_unsecure.lib
)
else()
set(GRPC_LIBRARIES
${CMAKE_CURRENT_BINARY_DIR}/grpc/lib/libprotobuf.a
${CMAKE_CURRENT_BINARY_DIR}/grpc/lib/libcares.a
${CMAKE_CURRENT_BINARY_DIR}/grpc/lib/libz.a
${CMAKE_CURRENT_BINARY_DIR}/grpc/src/${GRPC_TARGET_NAME}-build/libaddress_sorting.a
${CMAKE_CURRENT_BINARY_DIR}/grpc/src/${GRPC_TARGET_NAME}-build/libgpr.a
${CMAKE_CURRENT_BINARY_DIR}/grpc/src/${GRPC_TARGET_NAME}-build/libgrpc++_unsecure.a
${CMAKE_CURRENT_BINARY_DIR}/grpc/src/${GRPC_TARGET_NAME}-build/libgrpc_unsecure.a
)
endif()

# Link against grpc dependencies
target_link_libraries(${PROJECT_NAME} PRIVATE ${GRPC_LIBRARIES})
81 changes: 0 additions & 81 deletions sdks/cpp/Makefile

This file was deleted.

62 changes: 49 additions & 13 deletions sdks/cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,59 @@ headers as well as dynamic and static libraries that are needed for development
- `argonsdk-$(VERSION)-runtime-linux-arch_64.tar.gz`: This includes just the dynamic libraries that
are needed to run a binary compiled against the SDK and its dependencies.

### Building the Libraries
## Windows and macOS

If you want to build the libraries from Agones source,
the `make` target `build-sdk-cpp` will compile both static and dynamic libraries for Debian/Linux
for your usage, to be found in the `bin` directory inside this one.
If you are building a server on Windows or macOS, and need a development build to run on
that platform, at this time you will need to compile from source. Windows and macOS libraries
for the C++ SDK for easier cross platform development are planned and will be provided in the near future.

## Building From Source
If you wish to compile from source, you will need to compile and install the following dependencies:
Agones' C++ SDK is built via CMake. The build is self-contained so no additional dependencies need to be installed or built manually. That said, your choice of platform will require a different set of development tools:

- [gRPC](https://grpc.io), v1.8.x - [C++ compilation guide](https://github.com/grpc/grpc/blob/v1.8.x/INSTALL.md)
- [protobuf](https://developers.google.com/protocol-buffers/), v3.5.0 - [C++ compilation guide](https://github.com/google/protobuf/blob/master/src/README.md)
### Windows

For convenience, it's worth noting that protobuf is include in gRPC's source code, in the `third_party`
directory, and can be compiled from there, rather than being pulling down separately.
You'll need to set up your development environment and install the following tools:

## Windows and macOS
- Visual Studio 2017/2015 for C++.
- Install [Chocolatey](https://chocolatey.org/docs/installation) package manager.
- Install required libraries by running `choco install git cmake activeperl golang yasm`

If you are building a server on Windows or macOS, and need a development build to run on
that platform, at this time you will need to compile from source. Windows and macOS libraries
for the C++ SDK for easier cross platform development are planned and will be provided in the near future.
Open a new developer terminal so that your path includes all the newly installed tools and then run the following command:
```
cd <agones_dir>\sdks\cpp; build_VS_2017.bat
```

This should build both Release and Debug versions of `agonessdk.dll`.

Build Agones C++ SDK:

- Clone Agones: "git clone https://github.com/GoogleCloudPlatform/agones.git agones"
- Run "cd agones\sdks\cpp; build_VS_2017.bat"

You might need to tweak the PATH system variable to include the installed commands' path so you can call them from the command prompt

### Linux

The following command will install the necessary packages required by CMake to build Agones:
```
sudo apt install git cmake golang yasm
```

Build Agones:
```
cd <agones_dir>/sdks/cpp; ./build.sh
```

### macOS

On macOS you'll need to install a few additional packages required by the CMake build. This guide uses Homebrew to install them.

First install [Homebrew](https://brew.sh/), and then run the following command:
```
brew install cmake go
```

Now build:
```
cd <agones_dir>/sdks/cpp; ./build.sh
```
19 changes: 19 additions & 0 deletions sdks/cpp/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Copyright 2018 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Configure makefile and build Agones C++ SDK
cmake -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles" && make
cmake -DCMAKE_BUILD_TYPE=Release -G "Unix Makefiles" && make
16 changes: 16 additions & 0 deletions sdks/cpp/build_VS_2015.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@echo off
REM Copyright 2018 Google Inc. All Rights Reserved.
REM
REM Licensed under the Apache License, Version 2.0 (the "License");
REM you may not use this file except in compliance with the License.
REM You may obtain a copy of the License at
REM
REM http://www.apache.org/licenses/LICENSE-2.0
REM
REM Unless required by applicable law or agreed to in writing, software
REM distributed under the License is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM See the License for the specific language governing permissions and
REM limitations under the License.

cmake -G "Visual Studio 14 2015" & MSBuild agonessdk.sln /m /t:Build /p:Configuration=Debug & MSBuild agonessdk.sln /m /t:Build /p:Configuration=Release
16 changes: 16 additions & 0 deletions sdks/cpp/build_VS_2017.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@echo off
REM Copyright 2018 Google Inc. All Rights Reserved.
REM
REM Licensed under the Apache License, Version 2.0 (the "License");
REM you may not use this file except in compliance with the License.
REM You may obtain a copy of the License at
REM
REM http://www.apache.org/licenses/LICENSE-2.0
REM
REM Unless required by applicable law or agreed to in writing, software
REM distributed under the License is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM See the License for the specific language governing permissions and
REM limitations under the License.

cmake -G "Visual Studio 15 2017" & MSBuild agonessdk.sln /m /t:Build /p:Configuration=Debug & MSBuild agonessdk.sln /m /t:Build /p:Configuration=Release
23 changes: 16 additions & 7 deletions sdks/cpp/google/api/annotations.pb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include <google/protobuf/stubs/common.h>
#include <google/protobuf/stubs/port.h>
#include <google/protobuf/stubs/once.h>
#include <google/protobuf/io/coded_stream.h>
#include <google/protobuf/wire_format_lite_inl.h>
#include <google/protobuf/descriptor.h>
Expand All @@ -34,26 +33,32 @@
#include "third_party/protobuf/version.h"
#endif
// @@protoc_insertion_point(includes)

namespace protobuf_google_2fapi_2fhttp_2eproto {
extern PROTOBUF_INTERNAL_EXPORT_protobuf_google_2fapi_2fhttp_2eproto ::google::protobuf::internal::SCCInfo<1> scc_info_HttpRule;
} // namespace protobuf_google_2fapi_2fhttp_2eproto
namespace google {
namespace api {
} // namespace api
} // namespace google
namespace protobuf_google_2fapi_2fannotations_2eproto {
void InitDefaults() {
}

const ::google::protobuf::uint32 TableStruct::offsets[1] = {};
static const ::google::protobuf::internal::MigrationSchema* schemas = NULL;
static const ::google::protobuf::Message* const* file_default_instances = NULL;

void protobuf_AssignDescriptors() {
AddDescriptors();
::google::protobuf::MessageFactory* factory = NULL;
AssignDescriptors(
"google/api/annotations.proto", schemas, file_default_instances, TableStruct::offsets, factory,
"google/api/annotations.proto", schemas, file_default_instances, TableStruct::offsets,
NULL, NULL, NULL);
}

void protobuf_AssignDescriptorsOnce() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &protobuf_AssignDescriptors);
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, protobuf_AssignDescriptors);
}

void protobuf_RegisterTypes(const ::std::string&) GOOGLE_PROTOBUF_ATTRIBUTE_COLD;
Expand Down Expand Up @@ -82,8 +87,8 @@ void AddDescriptorsImpl() {
}

void AddDescriptors() {
static GOOGLE_PROTOBUF_DECLARE_ONCE(once);
::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);
static ::google::protobuf::internal::once_flag once;
::google::protobuf::internal::call_once(once, AddDescriptorsImpl);
}
// Force AddDescriptors() to be called at dynamic initialization time.
struct StaticDescriptorInitializer {
Expand All @@ -101,5 +106,9 @@ ::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::MethodOpt
// @@protoc_insertion_point(namespace_scope)
} // namespace api
} // namespace google
namespace google {
namespace protobuf {
} // namespace protobuf
} // namespace google

// @@protoc_insertion_point(global_scope)
Loading