[sproto]Add new port for sproto serialization library (#46727)

Co-authored-by: cuihairu <cuihairu@gmail.com>
This commit is contained in:
cuihairu
2025-08-05 06:38:21 +08:00
committed by GitHub
parent 87d5af08e9
commit e975f0e62b
8 changed files with 201 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
cmake_minimum_required(VERSION 3.14)
project(sproto C)
set(CMAKE_C_STANDARD 99)
find_package(unofficial-lua CONFIG REQUIRED)
add_library(sproto sproto.c lsproto.c)
if(BUILD_SHARED_LIBS)
target_compile_definitions(sproto PRIVATE SPROTO_BUILD_DLL)
# Set symbol visibility for GCC/Clang
if(NOT WIN32)
target_compile_options(sproto PRIVATE -fvisibility=hidden)
endif()
else()
target_compile_definitions(sproto PUBLIC SPROTO_STATIC)
endif()
target_link_libraries(sproto PRIVATE lua)
target_include_directories(sproto PRIVATE ${LUA_INCLUDE_DIR})
target_include_directories(sproto PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
install(TARGETS sproto
EXPORT sproto-targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)
install(FILES sproto.h
DESTINATION include
)
install(EXPORT sproto-targets
FILE sproto-targets.cmake
NAMESPACE unofficial::sproto::
DESTINATION share/unofficial-sproto
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_LIST_DIR}/sproto-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/unofficial-sproto-config.cmake"
INSTALL_DESTINATION share/unofficial-sproto
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/unofficial-sproto-config.cmake"
DESTINATION share/unofficial-sproto
)

View File

@@ -0,0 +1,74 @@
diff --git a/sproto.h b/sproto.h
index 1234567..8901234 100644
--- a/sproto.h
+++ b/sproto.h
@@ -6,6 +6,24 @@
struct sproto;
struct sproto_type;
+#if defined(_WIN32)
+ #if defined(SPROTO_BUILD_DLL)
+ #define SPROTO_API __declspec(dllexport)
+ #elif defined(SPROTO_STATIC)
+ #define SPROTO_API
+ #else
+ #define SPROTO_API __declspec(dllimport)
+ #endif
+#elif defined(__GNUC__) || defined(__clang__)
+ #if defined(SPROTO_BUILD_DLL)
+ #define SPROTO_API __attribute__((visibility("default")))
+ #else
+ #define SPROTO_API
+ #endif
+#else
+ #define SPROTO_API
+#endif
+
#define SPROTO_REQUEST 0
#define SPROTO_RESPONSE 1
@@ -25,19 +43,19 @@
#define SPROTO_CB_NIL -2
#define SPROTO_CB_NOARRAY -3
-struct sproto * sproto_create(const void * proto, size_t sz);
-void sproto_release(struct sproto *);
+SPROTO_API struct sproto * sproto_create(const void * proto, size_t sz);
+SPROTO_API void sproto_release(struct sproto *);
-int sproto_prototag(const struct sproto *, const char * name);
-const char * sproto_protoname(const struct sproto *, int proto);
+SPROTO_API int sproto_prototag(const struct sproto *, const char * name);
+SPROTO_API const char * sproto_protoname(const struct sproto *, int proto);
// SPROTO_REQUEST(0) : request, SPROTO_RESPONSE(1): response
-struct sproto_type * sproto_protoquery(const struct sproto *, int proto, int what);
-int sproto_protoresponse(const struct sproto *, int proto);
+SPROTO_API struct sproto_type * sproto_protoquery(const struct sproto *, int proto, int what);
+SPROTO_API int sproto_protoresponse(const struct sproto *, int proto);
-struct sproto_type * sproto_type(const struct sproto *, const char * type_name);
+SPROTO_API struct sproto_type * sproto_type(const struct sproto *, const char * type_name);
-int sproto_pack(const void * src, int srcsz, void * buffer, int bufsz);
-int sproto_unpack(const void * src, int srcsz, void * buffer, int bufsz);
+SPROTO_API int sproto_pack(const void * src, int srcsz, void * buffer, int bufsz);
+SPROTO_API int sproto_unpack(const void * src, int srcsz, void * buffer, int bufsz);
struct sproto_arg {
void *ud;
@@ -58,11 +76,11 @@ struct sproto_arg {
typedef int (*sproto_callback)(const struct sproto_arg *args);
-int sproto_decode(const struct sproto_type *, const void * data, int size, sproto_callback cb, void *ud);
-int sproto_encode(const struct sproto_type *, void * buffer, int size, sproto_callback cb, void *ud);
+SPROTO_API int sproto_decode(const struct sproto_type *, const void * data, int size, sproto_callback cb, void *ud);
+SPROTO_API int sproto_encode(const struct sproto_type *, void * buffer, int size, sproto_callback cb, void *ud);
// for debug use
-void sproto_dump(struct sproto *);
-const char * sproto_name(struct sproto_type *);
+SPROTO_API void sproto_dump(struct sproto *);
+SPROTO_API const char * sproto_name(struct sproto_type *);
#endif

View File

@@ -0,0 +1,28 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO cloudwu/sproto
REF 63df1ad8be4a7b295d389afaca7019e86f70d39c
SHA512 5613a04e6197b6fa00828f457aeee0270a7f4d300df609d62e405123f3623516c5761bd2c6b0b8e21be12aa30ca3288ae6307121bf8461535ad8c3efe9a750a2
HEAD_REF master
PATCHES add-symbol-exports.patch
)
file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")
file(COPY "${CMAKE_CURRENT_LIST_DIR}/sproto-config.cmake.in" DESTINATION "${SOURCE_PATH}")
vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
)
vcpkg_cmake_build()
vcpkg_cmake_install()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
vcpkg_cmake_config_fixup(CONFIG_PATH "share/unofficial-sproto" PACKAGE_NAME "unofficial-sproto")

View File

@@ -0,0 +1,8 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(unofficial-lua CONFIG)
include("${CMAKE_CURRENT_LIST_DIR}/sproto-targets.cmake")
check_required_components(sproto)

4
ports/sproto/usage Normal file
View File

@@ -0,0 +1,4 @@
The package sproto provides CMake targets:
find_package(unofficial-sproto CONFIG REQUIRED)
target_link_libraries(main PRIVATE unofficial::sproto::sproto)

18
ports/sproto/vcpkg.json Normal file
View File

@@ -0,0 +1,18 @@
{
"name": "sproto",
"version-date": "2024-07-08",
"description": "Yet another protocol library like google protocol buffers, but simple and fast",
"homepage": "https://github.com/cloudwu/sproto",
"license": "MIT",
"dependencies": [
"lua",
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}

View File

@@ -9088,6 +9088,10 @@
"baseline": "2.007.010",
"port-version": 0
},
"sproto": {
"baseline": "2024-07-08",
"port-version": 0
},
"sprout": {
"baseline": "2019-06-20",
"port-version": 2

9
versions/s-/sproto.json Normal file
View File

@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "a13ca7a665693b716b040d84c0592f3aec0aef8d",
"version-date": "2024-07-08",
"port-version": 0
}
]
}