Skip to content

Commit

Permalink
Fixed protobuf-plugin for newer versions of protobuf (#3910)
Browse files Browse the repository at this point in the history
* Fixed protobuf-plugin for newer versions of protobuf

* Fixed `protobuf` build on `install-dependencies`

* Added missing namespace annotation on `protobuf-plugin`

---------

Co-authored-by: satoshiotomakan <127754187+satoshiotomakan@users.noreply.github.com>
  • Loading branch information
EduMenges and satoshiotomakan authored Aug 19, 2024
1 parent 160a6e6 commit 43c9283
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
19 changes: 7 additions & 12 deletions protobuf-plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@
#
# Copyright © 2017 Trust Wallet.

cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(TrustWalletCoreProtobufPlugin)

set(CMAKE_OSX_DEPLOYMENT_TARGET "10.14" CACHE STRING "Minimum OS X deployment version" FORCE)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if ("$ENV{PREFIX}" STREQUAL "")
if("$ENV{PREFIX}" STREQUAL "")
set(PREFIX "${CMAKE_SOURCE_DIR}/../build/local")
else()
set(PREFIX "$ENV{PREFIX}")
endif()

include_directories(${PREFIX}/include)
link_directories(${PREFIX}/lib)
find_package(Protobuf CONFIG REQUIRED PATH ${PREFIX}/lib/pkgconfig)

find_package(Protobuf REQUIRED PATH ${PREFIX}/lib/pkgconfig)
include_directories(${Protobuf_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(protoc-gen-c-typedef c_typedef.cc)
target_link_libraries(protoc-gen-c-typedef protobuf::libprotobuf protobuf::libprotoc)

add_executable(protoc-gen-c-typedef c_typedef.cc ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(protoc-gen-c-typedef protobuf -lprotoc -pthread)

add_executable(protoc-gen-swift-typealias swift_typealias.cc ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(protoc-gen-swift-typealias protobuf -lprotoc -pthread)
add_executable(protoc-gen-swift-typealias swift_typealias.cc)
target_link_libraries(protoc-gen-swift-typealias protobuf::libprotobuf protobuf::libprotoc)

install(TARGETS protoc-gen-c-typedef protoc-gen-swift-typealias DESTINATION bin)
2 changes: 1 addition & 1 deletion protobuf-plugin/c_typedef.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Generator : public compiler::CodeGenerator {
return "TW" + proto_file.substr(0, index) + "Proto.h";
}

bool Generate(const FileDescriptor* file, const std::string& parameter, compiler::GeneratorContext* generator_context, string* error) const {
bool Generate(const FileDescriptor* file, const std::string& parameter, compiler::GeneratorContext* generator_context, std::string* error) const {
std::unique_ptr<io::ZeroCopyOutputStream> output(generator_context->Open(GetOutputFilename(file->name())));
io::Printer printer(output.get(), '$');

Expand Down
2 changes: 1 addition & 1 deletion protobuf-plugin/swift_typealias.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Generator : public compiler::CodeGenerator {
return proto_file.substr(0, index) + "+Proto.swift";
}

bool Generate(const FileDescriptor* file, const std::string& parameter, compiler::GeneratorContext* generator_context, string* error) const {
bool Generate(const FileDescriptor* file, const std::string& parameter, compiler::GeneratorContext* generator_context, std::string* error) const {
std::unique_ptr<io::ZeroCopyOutputStream> output(generator_context->Open(GetOutputFilename(file->name())));
io::Printer printer(output.get(), '$');

Expand Down
25 changes: 14 additions & 11 deletions tools/install-dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ CMAKE=cmake
MAKE=make

# Load dependencies version
BASE_DIR=$(cd `dirname $0`; pwd)
BASE_DIR=$(
cd $(dirname $0)
pwd
)
source ${BASE_DIR}/dependencies-version

# Setup up folders
Expand Down Expand Up @@ -50,28 +53,28 @@ function build_protobuf() {
PROTOBUF_DIR="$ROOT/build/local/src/protobuf"
cd ${PROTOBUF_DIR}/protobuf-$PROTOBUF_VERSION

./configure --prefix="$PREFIX"
$MAKE -j4
$MAKE install
$CMAKE -Scmake -B . -Dprotobuf_BUILD_TESTS=OFF -Dprotobuf_MODULE_COMPATIBLE=ON
$CMAKE --build . -j
$CMAKE --install . --prefix $PREFIX

# after install, cleanup to save space (docker)
make clean
$CMAKE --build . --target clean
"$PREFIX/bin/protoc" --version

# Protobuf plugins
cd "$ROOT/protobuf-plugin"
$CMAKE -H. -Bbuild -DCMAKE_INSTALL_PREFIX=$PREFIX
$MAKE -Cbuild -j12
$MAKE -Cbuild install
rm -rf build
$CMAKE . -Bbuild -DProtobuf_DIR=$PREFIX/lib/cmake/protobuf
$CMAKE --build build -j
$CMAKE --install build --prefix $PREFIX
$CMAKE --build build --target clean

if [[ -x "$(command -v swift)" && `uname` == "Darwin" ]]; then
if [[ -x "$(command -v swift)" && $(uname) == "Darwin" ]]; then
build_swift_plugin
fi
}

function build_swift_plugin() {
# Download Swift Protobuf sources
# Download Swift Protobuf sources
SWIFT_PROTOBUF_DIR="$ROOT/build/local/src/swift-protobuf"
mkdir -p "$SWIFT_PROTOBUF_DIR"
cd "$SWIFT_PROTOBUF_DIR"
Expand Down

0 comments on commit 43c9283

Please sign in to comment.