Skip to content

Commit e975f0e

Browse files
cuihairucuihairu
andauthored
[sproto]Add new port for sproto serialization library (#46727)
Co-authored-by: cuihairu <[email protected]>
1 parent 87d5af0 commit e975f0e

File tree

8 files changed

+201
-0
lines changed

8 files changed

+201
-0
lines changed

ports/sproto/CMakeLists.txt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(sproto C)
3+
4+
set(CMAKE_C_STANDARD 99)
5+
6+
find_package(unofficial-lua CONFIG REQUIRED)
7+
8+
add_library(sproto sproto.c lsproto.c)
9+
10+
if(BUILD_SHARED_LIBS)
11+
target_compile_definitions(sproto PRIVATE SPROTO_BUILD_DLL)
12+
# Set symbol visibility for GCC/Clang
13+
if(NOT WIN32)
14+
target_compile_options(sproto PRIVATE -fvisibility=hidden)
15+
endif()
16+
else()
17+
target_compile_definitions(sproto PUBLIC SPROTO_STATIC)
18+
endif()
19+
20+
target_link_libraries(sproto PRIVATE lua)
21+
22+
target_include_directories(sproto PRIVATE ${LUA_INCLUDE_DIR})
23+
24+
target_include_directories(sproto PUBLIC
25+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
26+
$<INSTALL_INTERFACE:include>
27+
)
28+
29+
install(TARGETS sproto
30+
EXPORT sproto-targets
31+
LIBRARY DESTINATION lib
32+
ARCHIVE DESTINATION lib
33+
RUNTIME DESTINATION bin
34+
)
35+
36+
install(FILES sproto.h
37+
DESTINATION include
38+
)
39+
40+
install(EXPORT sproto-targets
41+
FILE sproto-targets.cmake
42+
NAMESPACE unofficial::sproto::
43+
DESTINATION share/unofficial-sproto
44+
)
45+
46+
include(CMakePackageConfigHelpers)
47+
configure_package_config_file(
48+
"${CMAKE_CURRENT_LIST_DIR}/sproto-config.cmake.in"
49+
"${CMAKE_CURRENT_BINARY_DIR}/unofficial-sproto-config.cmake"
50+
INSTALL_DESTINATION share/unofficial-sproto
51+
)
52+
53+
install(FILES
54+
"${CMAKE_CURRENT_BINARY_DIR}/unofficial-sproto-config.cmake"
55+
DESTINATION share/unofficial-sproto
56+
)

ports/sproto/add-symbol-exports.patch

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
diff --git a/sproto.h b/sproto.h
2+
index 1234567..8901234 100644
3+
--- a/sproto.h
4+
+++ b/sproto.h
5+
@@ -6,6 +6,24 @@
6+
struct sproto;
7+
struct sproto_type;
8+
9+
+#if defined(_WIN32)
10+
+ #if defined(SPROTO_BUILD_DLL)
11+
+ #define SPROTO_API __declspec(dllexport)
12+
+ #elif defined(SPROTO_STATIC)
13+
+ #define SPROTO_API
14+
+ #else
15+
+ #define SPROTO_API __declspec(dllimport)
16+
+ #endif
17+
+#elif defined(__GNUC__) || defined(__clang__)
18+
+ #if defined(SPROTO_BUILD_DLL)
19+
+ #define SPROTO_API __attribute__((visibility("default")))
20+
+ #else
21+
+ #define SPROTO_API
22+
+ #endif
23+
+#else
24+
+ #define SPROTO_API
25+
+#endif
26+
+
27+
#define SPROTO_REQUEST 0
28+
#define SPROTO_RESPONSE 1
29+
30+
@@ -25,19 +43,19 @@
31+
#define SPROTO_CB_NIL -2
32+
#define SPROTO_CB_NOARRAY -3
33+
34+
-struct sproto * sproto_create(const void * proto, size_t sz);
35+
-void sproto_release(struct sproto *);
36+
+SPROTO_API struct sproto * sproto_create(const void * proto, size_t sz);
37+
+SPROTO_API void sproto_release(struct sproto *);
38+
39+
-int sproto_prototag(const struct sproto *, const char * name);
40+
-const char * sproto_protoname(const struct sproto *, int proto);
41+
+SPROTO_API int sproto_prototag(const struct sproto *, const char * name);
42+
+SPROTO_API const char * sproto_protoname(const struct sproto *, int proto);
43+
// SPROTO_REQUEST(0) : request, SPROTO_RESPONSE(1): response
44+
-struct sproto_type * sproto_protoquery(const struct sproto *, int proto, int what);
45+
-int sproto_protoresponse(const struct sproto *, int proto);
46+
+SPROTO_API struct sproto_type * sproto_protoquery(const struct sproto *, int proto, int what);
47+
+SPROTO_API int sproto_protoresponse(const struct sproto *, int proto);
48+
49+
-struct sproto_type * sproto_type(const struct sproto *, const char * type_name);
50+
+SPROTO_API struct sproto_type * sproto_type(const struct sproto *, const char * type_name);
51+
52+
-int sproto_pack(const void * src, int srcsz, void * buffer, int bufsz);
53+
-int sproto_unpack(const void * src, int srcsz, void * buffer, int bufsz);
54+
+SPROTO_API int sproto_pack(const void * src, int srcsz, void * buffer, int bufsz);
55+
+SPROTO_API int sproto_unpack(const void * src, int srcsz, void * buffer, int bufsz);
56+
57+
struct sproto_arg {
58+
void *ud;
59+
@@ -58,11 +76,11 @@ struct sproto_arg {
60+
61+
typedef int (*sproto_callback)(const struct sproto_arg *args);
62+
63+
-int sproto_decode(const struct sproto_type *, const void * data, int size, sproto_callback cb, void *ud);
64+
-int sproto_encode(const struct sproto_type *, void * buffer, int size, sproto_callback cb, void *ud);
65+
+SPROTO_API int sproto_decode(const struct sproto_type *, const void * data, int size, sproto_callback cb, void *ud);
66+
+SPROTO_API int sproto_encode(const struct sproto_type *, void * buffer, int size, sproto_callback cb, void *ud);
67+
68+
// for debug use
69+
-void sproto_dump(struct sproto *);
70+
-const char * sproto_name(struct sproto_type *);
71+
+SPROTO_API void sproto_dump(struct sproto *);
72+
+SPROTO_API const char * sproto_name(struct sproto_type *);
73+
74+
#endif

ports/sproto/portfile.cmake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
vcpkg_from_github(
3+
OUT_SOURCE_PATH SOURCE_PATH
4+
REPO cloudwu/sproto
5+
REF 63df1ad8be4a7b295d389afaca7019e86f70d39c
6+
SHA512 5613a04e6197b6fa00828f457aeee0270a7f4d300df609d62e405123f3623516c5761bd2c6b0b8e21be12aa30ca3288ae6307121bf8461535ad8c3efe9a750a2
7+
HEAD_REF master
8+
PATCHES add-symbol-exports.patch
9+
)
10+
11+
file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}")
12+
file(COPY "${CMAKE_CURRENT_LIST_DIR}/sproto-config.cmake.in" DESTINATION "${SOURCE_PATH}")
13+
14+
vcpkg_cmake_configure(
15+
SOURCE_PATH "${SOURCE_PATH}"
16+
)
17+
18+
vcpkg_cmake_build()
19+
20+
vcpkg_cmake_install()
21+
22+
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
23+
24+
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE")
25+
26+
file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}")
27+
28+
vcpkg_cmake_config_fixup(CONFIG_PATH "share/unofficial-sproto" PACKAGE_NAME "unofficial-sproto")

ports/sproto/sproto-config.cmake.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@PACKAGE_INIT@
2+
3+
include(CMakeFindDependencyMacro)
4+
find_dependency(unofficial-lua CONFIG)
5+
6+
include("${CMAKE_CURRENT_LIST_DIR}/sproto-targets.cmake")
7+
8+
check_required_components(sproto)

ports/sproto/usage

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
The package sproto provides CMake targets:
2+
3+
find_package(unofficial-sproto CONFIG REQUIRED)
4+
target_link_libraries(main PRIVATE unofficial::sproto::sproto)

ports/sproto/vcpkg.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "sproto",
3+
"version-date": "2024-07-08",
4+
"description": "Yet another protocol library like google protocol buffers, but simple and fast",
5+
"homepage": "https://github.com/cloudwu/sproto",
6+
"license": "MIT",
7+
"dependencies": [
8+
"lua",
9+
{
10+
"name": "vcpkg-cmake",
11+
"host": true
12+
},
13+
{
14+
"name": "vcpkg-cmake-config",
15+
"host": true
16+
}
17+
]
18+
}

versions/baseline.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9088,6 +9088,10 @@
90889088
"baseline": "2.007.010",
90899089
"port-version": 0
90909090
},
9091+
"sproto": {
9092+
"baseline": "2024-07-08",
9093+
"port-version": 0
9094+
},
90919095
"sprout": {
90929096
"baseline": "2019-06-20",
90939097
"port-version": 2

versions/s-/sproto.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"versions": [
3+
{
4+
"git-tree": "a13ca7a665693b716b040d84c0592f3aec0aef8d",
5+
"version-date": "2024-07-08",
6+
"port-version": 0
7+
}
8+
]
9+
}

0 commit comments

Comments
 (0)