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

Try GameNetworkingSockets #7040

Merged
merged 35 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1a41e74
Try GameNetworkingSockets
TheClonerx Aug 24, 2021
2de2cab
bcrypt only on windows
TheClonerx Aug 26, 2021
1450f15
Add test_package
TheClonerx Aug 26, 2021
76dfb6f
Add package_info
TheClonerx Aug 26, 2021
25d6247
Properly set USE_CRYPTO25519
TheClonerx Aug 26, 2021
4860ca5
Static build has a '_s' suffix
TheClonerx Aug 26, 2021
da90445
We indeed use openssl>=1.1.1
TheClonerx Aug 26, 2021
1af27dc
Disable runtime override
TheClonerx Aug 26, 2021
4df5929
Correctly set Protobuf_USE_STATIC_LIBS
TheClonerx Aug 30, 2021
c7c6246
Make test less modern
TheClonerx Aug 30, 2021
afa18ca
Use SPDX identifier
TheClonerx Aug 30, 2021
815fdf1
Bump openssl version
TheClonerx Aug 30, 2021
6d9271b
Add TARGETS
TheClonerx Sep 7, 2021
60741a2
Define STEAMNETWORKINGSOCKETS_STATIC_LINK on static builds
TheClonerx Sep 7, 2021
a7eb3b6
Link to socket and crypt libraries on windows
TheClonerx Sep 7, 2021
0423794
Add compiler version & cppstd checks
TheClonerx Oct 5, 2021
06bfbe1
Add protobuf as a build requirement
TheClonerx Oct 5, 2021
ac36d90
Build and install either static or shared
TheClonerx Oct 5, 2021
9f310fd
Add extra generators
TheClonerx Oct 8, 2021
7cee1df
Require C++11 on test package
TheClonerx Oct 8, 2021
32dcc07
Remove unnecessary patch
TheClonerx Oct 8, 2021
3868093
Remove unnecessary if
TheClonerx Oct 8, 2021
a224bd1
Safer patch access
TheClonerx Oct 8, 2021
5ca7979
Pass `self` to tools.cross_building
TheClonerx Oct 8, 2021
86f430a
Lower minimun gcc version required
TheClonerx Oct 8, 2021
774367b
Remove unnecessary patch
TheClonerx Oct 8, 2021
3a3830a
Check openssl version
TheClonerx Oct 8, 2021
f46a753
Add missing system lib
TheClonerx Oct 8, 2021
7a40547
Rename to gamenetworkingsockets
TheClonerx Oct 11, 2021
97d1e2c
Be more soft with cppstd validation
TheClonerx Oct 11, 2021
8956fc8
Remove unused generators
TheClonerx Oct 11, 2021
2e2bbd6
Be consistent with cmake definitions
TheClonerx Oct 11, 2021
f13f053
Add back the pkg_config generator (needed by libsodium)
TheClonerx Oct 11, 2021
5d1c88a
deps_cpp_info is only avaible in the build method
TheClonerx Oct 11, 2021
58c76d4
Remove openssl version check
TheClonerx Oct 11, 2021
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
7 changes: 7 additions & 0 deletions recipes/gamenetworkingsockets/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.11)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory("source_subfolder")
10 changes: 10 additions & 0 deletions recipes/gamenetworkingsockets/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
"1.3.0":
url: "https://github.com/ValveSoftware/GameNetworkingSockets/archive/refs/tags/v1.3.0.zip"
sha256: "22e409546babc449c44f492b253b547a2f5f11abe11a100686a10a990b5091cd"
patches:
"1.3.0":
- patch_file: "patches/001-disable-runtime-override.patch"
base_path: "source_subfolder"
- patch_file: "patches/002-either-static-or-shared.patch"
base_path: "source_subfolder"
126 changes: 126 additions & 0 deletions recipes/gamenetworkingsockets/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
import os

required_conan_version = ">=1.33.0"


class GameNetworkingSocketsConan(ConanFile):
name = "gamenetworkingsockets"
description = "GameNetworkingSockets is a basic transport layer for games."
topics = ("networking", "game-development")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/ValveSoftware/GameNetworkingSockets"
license = "BSD-3-Clause"
generators = "cmake", "pkg_config"
settings = "os", "arch", "compiler", "build_type"
exports_sources = ["CMakeLists.txt", "patches/**"]

options = {
"shared": [True, False],
"fPIC": [True, False],
"encryption": ["openssl", "libsodium", "bcrypt"]
}

default_options = {
"shared": False,
"fPIC": True,
"encryption": "openssl"
}

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 11)

if self.options.encryption == "bcrypt" and self.settings.os != "Windows":
raise ConanInvalidConfiguration("bcrypt is only valid on Windows")

def build_requirements(self):
self.build_requires("protobuf/3.17.1")

def requirements(self):
self.requires("protobuf/3.17.1")
if self.options.encryption == "openssl":
self.requires("openssl/1.1.1l")
elif self.options.encryption == "libsodium":
self.requires("libsodium/1.0.18")

def source(self):
tools.get(**self.conan_data["sources"][self.version], strip_root=True, destination=self._source_subfolder)

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["BUILD_STATIC"] = not self.options.shared
self._cmake.definitions["BUILD_SHARED"] = self.options.shared
self._cmake.definitions["GAMENETWORKINGSOCKETS_BUILD_EXAMPLES"] = False
self._cmake.definitions["GAMENETWORKINGSOCKETS_BUILD_TESTS"] = False
self._cmake.definitions["Protobuf_USE_STATIC_LIBS"] = not self.options["protobuf"].shared
crypto = {"openssl": "OpenSSL", "libsodium": "libsodium", "bcrypt": "BCrypt"}
self._cmake.definitions["USE_CRYPTO"] = crypto[str(self.options.encryption)]
crypto25519 = {"openssl": "OpenSSL", "libsodium": "libsodium", "bcrypt": "Reference"}
self._cmake.definitions["USE_CRYPTO25519"] = crypto25519[str(self.options.encryption)]
if self.options.encryption == "openssl":
self._cmake.definitions["OPENSSL_NEW_ENOUGH"] = True
self._cmake.definitions["OPENSSL_HAS_25519_RAW"] = True
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "GameNetworkingSockets"
self.cpp_info.names["cmake_find_package_multi"] = "GameNetworkingSockets"
self.cpp_info.names["pkg_config"] = "GameNetworkingSockets"
self.cpp_info.includedirs.append(os.path.join("include", "GameNetworkingSockets"))
if self.options.shared:
self.cpp_info.libs = ["GameNetworkingSockets"]
else:
self.cpp_info.libs = ["GameNetworkingSockets_s"]
self.cpp_info.defines = ["STEAMNETWORKINGSOCKETS_STATIC_LINK"]

self.cpp_info.requires = ["protobuf::libprotobuf"]
if self.options.encryption == "openssl":
self.cpp_info.requires += ["openssl::crypto"]
elif self.options.encryption == "libsodium":
self.cpp_info.requires += ["libsodium::libsodium"]

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["pthread"]
elif self.settings.os == "Windows":
self.cpp_info.system_libs = ["ws2_32", "crypt32", "winmm"]
if self.options.encryption == "bcrypt":
self.cpp_info.system_libs += ["bcrypt"]

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/CMakeLists.txt b/tmp/CMakeLists.txt
index 3471701..49efee3 100644
--- a/CMakeLists.txt
+++ b/tmp/CMakeLists.txt
@@ -35,7 +35,7 @@ endif()

include(FlagsMSVC)
set(MSVC_RUNTIME "dynamic")
-configure_msvc_runtime()
+# configure_msvc_runtime()
print_default_msvc_flags()

add_definitions( -DVALVE_CRYPTO_ENABLE_25519 )
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 7040ab3..c75897e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -282,28 +282,38 @@ macro(gamenetworkingsockets_common GNS_TARGET)

endmacro()

+if (BUILD_SHARED)
add_library(GameNetworkingSockets SHARED "")
add_library(GameNetworkingSockets::GameNetworkingSockets ALIAS GameNetworkingSockets)
add_library(GameNetworkingSockets::shared ALIAS GameNetworkingSockets)
gamenetworkingsockets_common(GameNetworkingSockets)

+install(
+ TARGETS GameNetworkingSockets
+ EXPORT GameNetworkingSockets
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+)
+endif()
+
+if (BUILD_STATIC)
add_library(GameNetworkingSockets_s STATIC "")
add_library(GameNetworkingSockets::GameNetworkingSockets_s ALIAS GameNetworkingSockets_s)
add_library(GameNetworkingSockets::static ALIAS GameNetworkingSockets_s)
target_compile_definitions(GameNetworkingSockets_s INTERFACE STEAMNETWORKINGSOCKETS_STATIC_LINK)
gamenetworkingsockets_common(GameNetworkingSockets_s)

-# Install rules
-
install(
- TARGETS
- GameNetworkingSockets
- GameNetworkingSockets_s
+ TARGETS GameNetworkingSockets_s
EXPORT GameNetworkingSockets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- )
+)
+endif()
+
+# Install rules

install(DIRECTORY ../include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/GameNetworkingSockets)

11 changes: 11 additions & 0 deletions recipes/gamenetworkingsockets/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(GameNetworkingSockets REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
target_link_libraries(${PROJECT_NAME} GameNetworkingSockets::GameNetworkingSockets)
17 changes: 17 additions & 0 deletions recipes/gamenetworkingsockets/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
55 changes: 55 additions & 0 deletions recipes/gamenetworkingsockets/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <assert.h>
#include <stdio.h>
#include <string.h>

#include <steam/isteamnetworkingutils.h>
#include <steam/steamnetworkingsockets.h>

static FILE* g_fpLog = NULL;
static SteamNetworkingMicroseconds g_logTimeZero;

static void DebugOutput(ESteamNetworkingSocketsDebugOutputType eType, char const* pszMsg)
{
SteamNetworkingMicroseconds time = SteamNetworkingUtils()->GetLocalTimestamp() - g_logTimeZero;
if (g_fpLog) {
fprintf(g_fpLog, "%10.6f %s\n", time * 1e-6, pszMsg);
}

if (eType <= k_ESteamNetworkingSocketsDebugOutputType_Msg) {
printf("%10.6f %s\n", time * 1e-6, pszMsg);
fflush(stdout);
}

if (eType == k_ESteamNetworkingSocketsDebugOutputType_Bug) {
fflush(stdout);
fflush(stderr);
if (g_fpLog) {
fflush(g_fpLog);
}

if (strstr(pszMsg, "SteamNetworkingGlobalLock held for")) {
return;
}

assert(!"TEST FAILED");
}
}

int main()
{
g_fpLog = stderr;
g_logTimeZero = SteamNetworkingUtils()->GetLocalTimestamp();

SteamNetworkingUtils()->SetDebugOutputFunction(k_ESteamNetworkingSocketsDebugOutputType_Debug, DebugOutput);
SteamNetworkingUtils()->SetDebugOutputFunction(k_ESteamNetworkingSocketsDebugOutputType_Verbose, DebugOutput);
SteamNetworkingUtils()->SetDebugOutputFunction(k_ESteamNetworkingSocketsDebugOutputType_Msg, DebugOutput);

SteamDatagramErrMsg errMsg;
if (!GameNetworkingSockets_Init(NULL, errMsg)) {
fprintf(stderr, "GameNetworkingSockets_Init failed. %s", errMsg);
return 1;
}

GameNetworkingSockets_Kill();
return 0;
}
3 changes: 3 additions & 0 deletions recipes/gamenetworkingsockets/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.3.0":
folder: all