Merge branch 'next' into options

This commit is contained in:
Robert Edmonds 2021-04-06 19:57:36 -04:00 committed by GitHub
commit 5ae0762b85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 185 additions and 52 deletions

142
.github/workflows/build.yml vendored Normal file
View File

@ -0,0 +1,142 @@
name: Test Build
on:
push:
schedule:
- cron: '0 0 * * 0' # Every Sunday at 00:00
jobs:
distcheck:
strategy:
matrix:
os: [macos-latest, ubuntu-20.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Install Linux dependencies
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev
- name: Install Mac dependencies
if: startsWith(matrix.os, 'macos')
run: brew install protobuf automake
- name: Run distcheck
run: |
./autogen.sh
./configure
make -j${nproc} distcheck VERBOSE=1
distcheck-multiarch:
runs-on: ubuntu-20.04
strategy:
matrix:
include:
- arch: armv7
- arch: aarch64
- arch: s390x
- arch: ppc64le
steps:
- uses: actions/checkout@v2
- uses: uraimo/run-on-arch-action@v2.0.9
name: Install dependencies and run distcheck
id: runcmd
with:
arch: ${{ matrix.arch }}
githubToken: ${{ github.token }}
distro: ubuntu20.04
install: |
apt-get update -q -y
apt-get install -q -y build-essential autoconf automake libtool pkg-config
apt-get install -q -y protobuf-compiler libprotobuf-dev libprotoc-dev
run: |
./autogen.sh
./configure
make -j3 distcheck VERBOSE=1
valgrind:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev valgrind
- name: Run distcheck with valgrind
run: |
./autogen.sh
./configure --enable-valgrind-tests CFLAGS="-fsanitize=undefined -fno-sanitize-recover=undefined"
make -j${nproc} distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-valgrind-tests CFLAGS=\"-fsanitize=undefined -fno-sanitize-recover=undefined\"" VERBOSE=1
coverage:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install dependencies
run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev lcov
- name: Run coverage build
run: |
./autogen.sh
./configure --enable-code-coverage
make -j${nproc}
mkdir coverage
lcov --no-external --capture --initial --directory . --output-file ./coverage/lcov.info --include '*protobuf-c.c'
make check
lcov --no-external --capture --directory . --output-file ./coverage/lcov.info --include '*protobuf-c.c'
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
cmake:
strategy:
matrix:
build_type: [Debug, Release]
os: [macos-latest, ubuntu-20.04]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Install Linux dependencies
if: startsWith(matrix.os, 'ubuntu')
run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev
- name: Install Mac dependencies
if: startsWith(matrix.os, 'macos')
run: brew install protobuf
- name: Run cmake tests
run: |
mkdir build-cmake/bin
cd build-cmake/bin
cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DBUILD_TESTS=ON -DCMAKE_INSTALL_PREFIX=protobuf-c-bin ../
make -j3
make test
make install
cmake-msvc:
strategy:
matrix:
build-type: [Debug, Release]
shared-lib: [ON, OFF]
name: "MSVC CMake (${{ matrix.build-type }}, DLL: ${{ matrix.shared-lib }})"
runs-on: windows-latest
env:
PROTOBUF_VERSION: 3.15.6
steps:
- uses: actions/checkout@v2
- uses: ilammy/msvc-dev-cmd@v1
- uses: actions/cache@v2
id: cache
with:
path: ~/protobuf-bin
key: ${{ env.PROTOBUF_VERSION }}-${{ matrix.shared-lib }}-${{ matrix.build-type}}
- name: Build and install protobuf
if: steps.cache.outputs.cache-hit != 'true'
run: |
cd ~
C:\msys64\usr\bin\wget.exe https://github.com/protocolbuffers/protobuf/releases/download/v${{ env.PROTOBUF_VERSION }}/protobuf-cpp-${{ env.PROTOBUF_VERSION }}.zip
C:\msys64\usr\bin\unzip protobuf-cpp-${{ env.PROTOBUF_VERSION }}.zip
cd ~/protobuf-${{ env.PROTOBUF_VERSION }}/cmake && mkdir build && cd build
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -Dprotobuf_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=~/protobuf-bin -Dprotobuf_BUILD_SHARED_LIBS=${{ matrix.shared-lib }} ..
nmake
nmake install
- name: Run cmake tests
run: |
mkdir build-cmake/bin
cd build-cmake/bin
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DBUILD_TESTS=ON -DCMAKE_PREFIX_PATH=~/protobuf-bin -DCMAKE_INSTALL_PREFIX=protobuf-c-bin -DBUILD_SHARED_LIBS=${{ matrix.shared-lib }} ..
nmake
nmake test
nmake install

View File

@ -1,41 +0,0 @@
language:
- c
- cpp
arch:
- amd64
- arm64
- ppc64le
- s390x
dist: bionic
addons:
apt:
packages:
- lcov
- valgrind
env:
global:
- PROTOBUF_VERSION=3.7.1
- PKG_CONFIG_PATH=$HOME/protobuf-$PROTOBUF_VERSION-bin/lib/pkgconfig
- CMAKE_PREFIX_PATH=$HOME/protobuf-$PROTOBUF_VERSION-bin
install:
- pip install --user cpp-coveralls
- wget https://github.com/protocolbuffers/protobuf/archive/v$PROTOBUF_VERSION.tar.gz
- tar xf v$PROTOBUF_VERSION.tar.gz
- ( cd protobuf-$PROTOBUF_VERSION && ./autogen.sh && ./configure --prefix=$HOME/protobuf-$PROTOBUF_VERSION-bin && make -j2 && make install )
script:
- ./autogen.sh
- ./configure && make -j2 distcheck VERBOSE=1 && make clean
- ./configure --enable-valgrind-tests CFLAGS="-fsanitize=undefined -fno-sanitize-recover=undefined" && make -j2 distcheck DISTCHECK_CONFIGURE_FLAGS="--enable-valgrind-tests CFLAGS=\"-fsanitize=undefined -fno-sanitize-recover=undefined\"" VERBOSE=1 && make clean
- ./configure --enable-code-coverage && make -j2 && make check
- ( mkdir build-cmake/bin && cd build-cmake/bin && cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=protobuf-c-bin ../ && make -j2 && make test && make install)
after_success:
- if [ $(uname -m) = "x86_64" ]; then
cpp-coveralls --build-root . --exclude t/ --exclude /usr/include --exclude protobuf-$PROTOBUF_VERSION --exclude protoc-c;
fi

View File

@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/protobuf-c/protobuf-c.png?branch=master)](https://travis-ci.org/protobuf-c/protobuf-c) [![Coverage Status](https://coveralls.io/repos/protobuf-c/protobuf-c/badge.png)](https://coveralls.io/r/protobuf-c/protobuf-c)
[![Build Status](https://github.com/protobuf-c/protobuf-c/actions/workflows/build.yml/badge.svg)](https://github.com/protobuf-c/protobuf-c/actions) [![Coverage Status](https://coveralls.io/repos/protobuf-c/protobuf-c/badge.png)](https://coveralls.io/r/protobuf-c/protobuf-c)
## Overview

View File

@ -4,12 +4,11 @@ SET(PACKAGE_VERSION 1.3.3)
SET(PACKAGE_URL https://github.com/protobuf-c/protobuf-c)
SET(PACKAGE_DESCRIPTION "Protocol Buffers implementation in C")
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR)
PROJECT(protobuf-c)
#options
option(MSVC_STATIC_BUILD "MSVC_STATIC_BUILD" OFF)
option(BUILD_PROTO3 "BUILD_PROTO3" ON)
option(BUILD_PROTOC "Build protoc-gen-c" ON)
if(CMAKE_BUILD_TYPE MATCHES Debug)
@ -28,6 +27,10 @@ if (${WORDS_BIGENDIAN})
ADD_DEFINITIONS(-DWORDS_BIGENDIAN)
endif()
IF (MSVC AND BUILD_SHARED_LIBS)
ADD_DEFINITIONS(-DPROTOBUF_C_USE_SHARED_LIB)
ENDIF (MSVC AND BUILD_SHARED_LIBS)
if(MSVC)
# using Visual Studio C++
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4267 /wd4244")
@ -45,6 +48,9 @@ SET (PC_SOURCES
ADD_LIBRARY(protobuf-c ${PC_SOURCES})
set_target_properties(protobuf-c PROPERTIES COMPILE_PDB_NAME protobuf-c)
IF (MSVC AND BUILD_SHARED_LIBS)
TARGET_COMPILE_DEFINITIONS(protobuf-c PRIVATE -DPROTOBUF_C_EXPORT)
ENDIF (MSVC AND BUILD_SHARED_LIBS)
INCLUDE_DIRECTORIES(${MAIN_DIR})
INCLUDE_DIRECTORIES(${MAIN_DIR}/protobuf-c)
@ -52,6 +58,10 @@ INCLUDE_DIRECTORIES(${MAIN_DIR}/protobuf-c)
IF(BUILD_PROTOC)
INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}) # for generated files
if (MSVC AND NOT BUILD_SHARED_LIBS)
SET(Protobuf_USE_STATIC_LIBS ON)
endif (MSVC AND NOT BUILD_SHARED_LIBS)
FIND_PACKAGE(Protobuf REQUIRED)
INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR})
@ -60,7 +70,7 @@ if (BUILD_PROTO3)
endif()
ENDIF()
if (MSVC AND MSVC_STATIC_BUILD)
if (MSVC AND NOT BUILD_SHARED_LIBS)
# In case we are building static libraries, link also the runtime library statically
# so that MSVCR*.DLL is not required at runtime.
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
@ -75,7 +85,7 @@ if (MSVC AND MSVC_STATIC_BUILD)
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
endif (MSVC AND MSVC_STATIC_BUILD)
endif (MSVC AND NOT BUILD_SHARED_LIBS)
IF(BUILD_PROTOC)
SET(CMAKE_CXX_STANDARD 11)
@ -89,6 +99,13 @@ ADD_EXECUTABLE(protoc-gen-c ${PROTOC_GEN_C_SRC} protobuf-c/protobuf-c.pb.cc prot
TARGET_LINK_LIBRARIES(protoc-gen-c ${PROTOBUF_PROTOC_LIBRARY} ${PROTOBUF_LIBRARY})
IF (MSVC AND BUILD_SHARED_LIBS)
TARGET_COMPILE_DEFINITIONS(protoc-gen-c PRIVATE -DPROTOBUF_USE_DLLS)
GET_FILENAME_COMPONENT(PROTOBUF_DLL_DIR ${PROTOBUF_PROTOC_EXECUTABLE} DIRECTORY)
FILE(GLOB PROTOBUF_DLLS ${PROTOBUF_DLL_DIR}/*.dll)
FILE(COPY ${PROTOBUF_DLLS} DESTINATION ${CMAKE_BINARY_DIR})
ENDIF (MSVC AND BUILD_SHARED_LIBS)
IF(CMAKE_HOST_UNIX)
ADD_CUSTOM_COMMAND(TARGET ${PROJECT_NAME} POST_BUILD
COMMAND ln -sf protoc-gen-c protoc-c
@ -120,6 +137,9 @@ GENERATE_TEST_SOURCES(${TEST_DIR}/test-full.proto t/test-full.pb-c.c t/test-full
ADD_EXECUTABLE(cxx-generate-packed-data ${TEST_DIR}/generated-code2/cxx-generate-packed-data.cc t/test-full.pb.h t/test-full.pb.cc protobuf-c/protobuf-c.pb.cc protobuf-c/protobuf-c.pb.h)
TARGET_LINK_LIBRARIES(cxx-generate-packed-data ${PROTOBUF_LIBRARY})
IF (MSVC AND BUILD_SHARED_LIBS)
TARGET_COMPILE_DEFINITIONS(cxx-generate-packed-data PRIVATE -DPROTOBUF_USE_DLLS)
ENDIF (MSVC AND BUILD_SHARED_LIBS)
FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/t/generated-code2)
ADD_CUSTOM_COMMAND(OUTPUT t/generated-code2/test-full-cxx-output.inc
@ -164,7 +184,7 @@ ENDIF()
INSTALL(TARGETS protoc-gen-c RUNTIME DESTINATION bin)
ENDIF() # BUILD_PROTOC
INSTALL(TARGETS protobuf-c LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
INSTALL(TARGETS protobuf-c LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin)
INSTALL(FILES ${MAIN_DIR}/protobuf-c/protobuf-c.h ${MAIN_DIR}/protobuf-c/protobuf-c.proto DESTINATION include/protobuf-c)
INSTALL(FILES ${MAIN_DIR}/protobuf-c/protobuf-c.h DESTINATION include)
INSTALL(FILES ${CMAKE_BINARY_DIR}/protobuf-c.pdb DESTINATION lib OPTIONAL)

View File

@ -84,7 +84,9 @@
# define PROTOBUF_C_UNPACK_ERROR(...)
#endif
#if !defined(_WIN32) || !defined(PROTOBUF_C_USE_SHARED_LIB)
const char protobuf_c_empty_string[] = "";
#endif
/**
* Internal `ProtobufCMessage` manipulation macro.
@ -2062,7 +2064,7 @@ static size_t
parse_tag_and_wiretype(size_t len,
const uint8_t *data,
uint32_t *tag_out,
ProtobufCWireType *wiretype_out)
uint8_t *wiretype_out)
{
unsigned max_rv = len > 5 ? 5 : len;
uint32_t tag = (data[0] & 0x7f) >> 3;
@ -2499,7 +2501,7 @@ parse_required_member(ScannedMember *scanned_member,
{
unsigned len = scanned_member->len;
const uint8_t *data = scanned_member->data;
ProtobufCWireType wire_type = scanned_member->wire_type;
uint8_t wire_type = scanned_member->wire_type;
switch (scanned_member->field->type) {
case PROTOBUF_C_TYPE_ENUM:
@ -3081,7 +3083,7 @@ protobuf_c_message_unpack(const ProtobufCMessageDescriptor *desc,
while (rem > 0) {
uint32_t tag;
ProtobufCWireType wire_type;
uint8_t wire_type;
size_t used = parse_tag_and_wiretype(rem, at, &tag, &wire_type);
const ProtobufCFieldDescriptor *field;
ScannedMember tmp;

View File

@ -238,7 +238,11 @@ PROTOBUF_C__BEGIN_DECLS
#define PROTOBUF_C__ENUM_DESCRIPTOR_MAGIC 0x114315af
/* Empty string used for initializers */
PROTOBUF_C__API extern const char protobuf_c_empty_string[];
#if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB)
static const char protobuf_c_empty_string[] = "";
#else
extern const char protobuf_c_empty_string[];
#endif
/**
* \defgroup api Public API

View File

@ -68,6 +68,12 @@
#include <string>
#include <google/protobuf/compiler/code_generator.h>
#if defined(_WIN32) && defined(PROTOBUF_C_USE_SHARED_LIB)
# define PROTOC_C_EXPORT __declspec(dllexport)
#else
# define PROTOC_C_EXPORT
#endif
namespace google {
namespace protobuf {
namespace compiler {
@ -77,7 +83,7 @@ namespace c {
// header. If you create your own protocol compiler binary and you want
// it to support C++ output, you can do so by registering an instance of this
// CodeGenerator with the CommandLineInterface in your main() function.
class LIBPROTOC_EXPORT CGenerator : public CodeGenerator {
class PROTOC_C_EXPORT CGenerator : public CodeGenerator {
public:
CGenerator();
~CGenerator();