Skip to content

Commit 00326fb

Browse files
committed
1. base on vcpkg + cmake build
0 parents  commit 00326fb

File tree

128 files changed

+25919
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+25919
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.DS_Store
2+
build/*
3+
log/*
4+
._.*
5+
._*
6+
*.out
7+
*.tar.gz
8+
publish/*
9+
vcpkg_installed/*

CMakeLists.txt

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
project(grpc-c)
4+
5+
set(CMAKE_VERBOSE_MAKEFILE ON)
6+
7+
set(CMAKE_CXX_STANDARD 20)
8+
9+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
10+
set(CMAKE_C_FLAGS " -g -fPIC -fpermissive ")
11+
endif()
12+
13+
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
14+
15+
execute_process(
16+
COMMAND bash -c "git rev-parse HEAD"
17+
OUTPUT_VARIABLE COMMIT_ID
18+
OUTPUT_STRIP_TRAILING_WHITESPACE
19+
)
20+
execute_process(
21+
COMMAND bash -c "git log -1 --format=%cd --date=format:'%Y-%m-%d %H:%M:%S'"
22+
OUTPUT_VARIABLE COMMIT_DATE
23+
OUTPUT_STRIP_TRAILING_WHITESPACE
24+
)
25+
26+
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
27+
message("This is a Linux environment.")
28+
add_definitions(-DLINUX)
29+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
30+
message("This is a Windows environment.")
31+
add_definitions(-DWINDOWS)
32+
elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
33+
message("This is a macOS environment.")
34+
add_definitions(-DDARWIN)
35+
else()
36+
message(FATAL_ERROR "Unsupported operating system: ${CMAKE_SYSTEM_NAME}.")
37+
endif()
38+
39+
set(CMAKE_CXX_FLAGS "${CXX_ONLY_FLAGS} ${CMAKE_CXX_FLAGS}")
40+
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
41+
42+
set(CMAKE_INSTALL_PREFIX "publish")
43+
44+
add_subdirectory(lib)
45+
add_subdirectory(compiler)
46+
add_subdirectory(example)

CMakePresets.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"version": 3,
3+
"configurePresets": [
4+
{
5+
"name": "release",
6+
"binaryDir": "${sourceDir}/build",
7+
"cacheVariables": {
8+
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
9+
"CMAKE_BUILD_TYPE": "Release"
10+
}
11+
},
12+
{
13+
"name": "debug",
14+
"binaryDir": "${sourceDir}/build",
15+
"cacheVariables": {
16+
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
17+
"CMAKE_BUILD_TYPE": "Debug"
18+
}
19+
}
20+
]
21+
}

README.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# GRPC-C
2+
3+
C implementation of [gRPC](http://www.grpc.io/) layered of top of core libgrpc.
4+
5+
## Prerequisites
6+
7+
The current project is built based on [vcpkg + cmake] and supports multi-platform, such as windows, linux, macos.
8+
You need to prepare the [vcpkg + cmake] tool local platform first.
9+
Refer to the official website: https://github.com/microsoft/vcpkg
10+
11+
## Build
12+
13+
```sh
14+
git clone https://github.com/linimbus/grpc-c.git
15+
cd grpc-c
16+
#For linux/macos
17+
./build_release.sh
18+
#For windows
19+
./build_release.bat
20+
```
21+
22+
23+
If you see the following result, congratulations, you have compiled successfully.
24+
25+
```
26+
-- Install configuration: "Release"
27+
-- Installing: /Users/linimbus/workspace/grpc-c/publish/lib/libgrpc-c.dylib
28+
-- Installing: /Users/linimbus/workspace/grpc-c/publish/lib/libgrpc-c.a
29+
-- Up-to-date: /Users/linimbus/workspace/grpc-c/publish/include/grpc-c.h
30+
-- Installing: /Users/linimbus/workspace/grpc-c/publish/bin/protoc-gen-grpc-c
31+
-- Installing: /Users/linimbus/workspace/grpc-c/publish/bin/example-foo
32+
```
33+
34+
To run example code:
35+
36+
```sh
37+
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
38+
cd publish/bin
39+
./bin/foo_bin server
40+
./bin/foo_bin client
41+
```
42+
43+
## Dependencies
44+
45+
Maintain in vcpkg.json file
46+
47+
```
48+
{
49+
"dependencies": [
50+
"protobuf",
51+
{
52+
"name": "protobuf-c",
53+
"features": []
54+
},
55+
"grpc"
56+
]
57+
}
58+
```

build_release.bat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cmake --preset=release && cmake --build build && cmake --install build

build_release.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
cmake --preset=release && cmake --build build --parallel 8 && cmake --install build

compiler/CMakeLists.txt

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
cmake_minimum_required(VERSION 3.20)
2+
3+
project(protoc-gen-grpc-c)
4+
5+
set(PROTO_C_FILE "protobuf-c.proto")
6+
set(PROTO_C_DIR "${PROJECT_SOURCE_DIR}/../protobuf-c/")
7+
8+
include_directories("${PROJECT_SOURCE_DIR}/")
9+
include_directories("${PROTO_C_DIR}")
10+
11+
find_package(protobuf CONFIG REQUIRED)
12+
find_package(protobuf-c CONFIG REQUIRED)
13+
14+
add_custom_command(
15+
OUTPUT ${PROTO_C_DIR}/protobuf-c/protobuf-c.pb.cc
16+
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --cpp_out=${PROTO_C_DIR}/protobuf-c/ --proto_path=${PROTO_C_DIR}/protobuf-c/ ${PROTO_C_FILE}
17+
)
18+
19+
# add the executable
20+
add_executable(protoc-gen-grpc-c
21+
${PROTO_C_DIR}/protobuf-c/protobuf-c.pb.cc
22+
${PROTO_C_DIR}/protoc-c/c_bytes_field.cc
23+
${PROTO_C_DIR}/protoc-c/c_enum.cc
24+
${PROTO_C_DIR}/protoc-c/c_enum_field.cc
25+
${PROTO_C_DIR}/protoc-c/c_extension.cc
26+
${PROTO_C_DIR}/protoc-c/c_field.cc
27+
${PROTO_C_DIR}/protoc-c/c_file.cc
28+
${PROTO_C_DIR}/protoc-c/c_generator.cc
29+
${PROTO_C_DIR}/protoc-c/c_helpers.cc
30+
${PROTO_C_DIR}/protoc-c/c_message.cc
31+
${PROTO_C_DIR}/protoc-c/c_message_field.cc
32+
${PROTO_C_DIR}/protoc-c/c_primitive_field.cc
33+
${PROTO_C_DIR}/protoc-c/c_service.cc
34+
${PROTO_C_DIR}/protoc-c/c_string_field.cc
35+
grpc_c_file.cc
36+
grpc_c_generator.cc
37+
grpc_c_helpers.cc
38+
grpc_c_message.cc
39+
grpc_c_service.cc
40+
main.cc )
41+
42+
TARGET_LINK_LIBRARIES(protoc-gen-grpc-c PRIVATE protobuf::libprotoc protobuf::libprotobuf protobuf-c::protobuf-c )
43+
44+
install(TARGETS protoc-gen-grpc-c DESTINATION bin
45+
PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ
46+
GROUP_EXECUTE GROUP_READ
47+
WORLD_EXECUTE WORLD_READ)

0 commit comments

Comments
 (0)