Skip to content

Commit 44f59db

Browse files
authored
Use built-in protoc to generate the pb file (milvus-io#51)
Signed-off-by: SimFG <[email protected]> Signed-off-by: SimFG <[email protected]>
1 parent 84e9fa2 commit 44f59db

File tree

6 files changed

+40
-36
lines changed

6 files changed

+40
-36
lines changed

Makefile

+3-12
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,10 @@ PROTOC_VER := $(shell protoc --version)
66

77
all: generate-proto
88

9-
check-protoc:
10-
ifeq (, $(shell which protoc))
11-
$(error "No protoc in PATH, consider doing apt-get install protoc")
12-
else
13-
@echo "using $(shell which protoc)"
14-
endif
15-
16-
check-protoc-version: check-protoc
17-
@(env bash $(PWD)/scripts/check_protoc_version.sh)
18-
199
build:
2010
@(env bash $(PWD)/scripts/core_build.sh)
2111

22-
generate-proto: check-protoc-version build
23-
@which protoc-gen-go 1>/dev/null || (echo "Installing protoc-gen-go" && go get github.com/golang/protobuf/[email protected])
12+
generate-proto: export protoc:=${PWD}/cmake-build/protobuf/protobuf-build/protoc
13+
generate-proto: build
14+
@which protoc-gen-go 1>/dev/null || (echo "Installing protoc-gen-go" && go install github.com/golang/protobuf/[email protected])
2415
@(env bash $(PWD)/scripts/proto_gen_go.sh)

cmake/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ include(FetchContent)
55

66
message( STATUS "source dir ${PROJECT_SOURCE_DIR}" )
77

8+
set( THIRDPARTY_DOWNLOAD_PATH ${PROJECT_SOURCE_DIR}/3rdparty_download/download )
9+
810
add_subdirectory( protobuf )
911

1012
add_custom_target( Clean-All COMMAND ${CMAKE_BUILD_TOOL} clean )

cmake/protobuf/CMakeLists.txt

+13-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,20 @@ message( STATUS "Building protobuf-cpp-3.9.0 from source" )
66
FetchContent_Declare( protobuf
77
URL ${PROTOBUF_SOURCE_URL}
88
URL_MD5 "9562b27cc6ac5ebd087f201f1310c885"
9-
DOWNLOAD_DIR ${THIRDPARTY_DOWNLOAD_PATH}
9+
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/../3rdparty_download
1010
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobuf-src
1111
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/protobuf-build
1212
)
1313

14-
FetchContent_MakeAvailable(protobuf)
14+
set( protobuf_BUILD_TESTS CACHE BOOL OFF FORCE )
15+
set( protobuf_WITH_ZLIB CACHE BOOL OFF FORCE )
16+
if ( NOT protobuf_POPULATED )
17+
FetchContent_Populate( protobuf )
18+
19+
# Adding the following targets:
20+
# protobuf::libprotobuf - static target
21+
# protobuf::protoc - executable target
22+
add_subdirectory( ${protobuf_SOURCE_DIR}/cmake
23+
${protobuf_BINARY_DIR}
24+
EXCLUDE_FROM_ALL )
25+
endif()

scripts/check_protoc_version.sh

-19
This file was deleted.

scripts/core_build.sh

+17
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,21 @@ BUILD_OUTPUT_DIR="${SCRIPTS_DIR}/../cmake-build"
77
mkdir -p ${BUILD_OUTPUT_DIR}
88
pushd ${BUILD_OUTPUT_DIR}
99
cmake ${CMAKE_DIR}
10+
11+
if [[ ! ${jobs+1} ]]; then
12+
if command -v nproc &> /dev/null
13+
# For linux
14+
then
15+
jobs=$(nproc)
16+
elif command -v sysctl &> /dev/null
17+
# For macOS
18+
then
19+
jobs=$(sysctl -n hw.logicalcpu)
20+
else
21+
jobs=4
22+
fi
23+
fi
24+
25+
make -j ${jobs} protoc
26+
make -j ${jobs} install/local
1027
popd

scripts/proto_gen_go.sh

+5-3
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,21 @@ mkdir -p ../go-api/commonpb
3939
mkdir -p ../go-api/schemapb
4040
mkdir -p ../go-api/milvuspb
4141

42-
protoc --proto_path="${GOOGLE_PROTO_DIR}" --proto_path=. \
42+
$protoc --version
43+
44+
$protoc --proto_path="${GOOGLE_PROTO_DIR}" --proto_path=. \
4345
--go_opt="Mmilvus.proto=github.com/milvus-io/milvus-proto/go-api/milvuspb;milvuspb" \
4446
--go_opt=Mcommon.proto=github.com/milvus-io/milvus-proto/go-api/commonpb \
4547
--go_opt=Mschema.proto=github.com/milvus-io/milvus-proto/go-api/schemapb \
4648
--go_out=plugins=grpc,paths=source_relative:./../go-api/milvuspb milvus.proto
4749

48-
protoc --proto_path="${GOOGLE_PROTO_DIR}" --proto_path=. \
50+
$protoc --proto_path="${GOOGLE_PROTO_DIR}" --proto_path=. \
4951
--go_opt=Mmilvus.proto=github.com/milvus-io/milvus-proto/go-api/milvuspb \
5052
--go_opt=Mcommon.proto=github.com/milvus-io/milvus-proto/go-api/commonpb \
5153
--go_opt="Mschema.proto=github.com/milvus-io/milvus-proto/go-api/schemapb;schemapb" \
5254
--go_out=plugins=grpc,paths=source_relative:./../go-api/schemapb schema.proto
5355

54-
protoc --proto_path="${GOOGLE_PROTO_DIR}" --proto_path=. \
56+
$protoc --proto_path="${GOOGLE_PROTO_DIR}" --proto_path=. \
5557
--go_opt=Mmilvus.proto=github.com/milvus-io/milvus-proto/go-api/milvuspb \
5658
--go_opt="Mcommon.proto=github.com/milvus-io/milvus-proto/go-api/commonpb;commonpb" \
5759
--go_opt=Mschema.proto=github.com/milvus-io/milvus-proto/go-api/schemapb \

0 commit comments

Comments
 (0)