From b6a92a93c619e012b2f57640495cc48809e89860 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Sun, 2 Sep 2018 13:58:42 -0700 Subject: More work on CMake build, and updated conformance for proto3. --- CMakeLists.txt | 74 ++++++++++++++++++++++++++++++++++++----------- tests/conformance_upb.c | 6 +++- third_party/protobuf | 2 +- tools/copy_genfiles.sh.in | 22 ++++++++++++++ 4 files changed, 85 insertions(+), 19 deletions(-) create mode 100755 tools/copy_genfiles.sh.in diff --git a/CMakeLists.txt b/CMakeLists.txt index b192d75..e4a7041 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,12 @@ +cmake_minimum_required(VERSION 3.1) + +if(${CMAKE_VERSION} VERSION_LESS 3.12) + cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) +else() + cmake_policy(VERSION 3.12) +endif() + cmake_minimum_required (VERSION 3.0) cmake_policy(SET CMP0048 NEW) project (upb) @@ -15,16 +23,6 @@ if(NOT CMAKE_BUILD_TYPE) FORCE) endif() -# Check out Git submodules. -#if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.gitmodules") -# execute_process (COMMAND git submodule update --init --recursive -# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) -#endif() - -set(protobuf_BUILD_TESTS OFF CACHE BOOL "enable tests for proto2" FORCE) -set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "enable shared libs for proto2" FORCE) -add_subdirectory(third_party/protobuf/cmake) - # When using Ninja, compiler output won't be colorized without this. include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG(-fdiagnostics-color=always SUPPORTS_COLOR_ALWAYS) @@ -54,6 +52,10 @@ elseif(UNIX) endif() FIND_PACKAGE(Lua) +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/Makefile.am") + set(PROTOBUF_FOUND TRUE) +endif() +find_program(RAGEL NAMES ragel) if(LUA_FOUND) include_directories(${LUA_INCLUDE_DIR}) @@ -106,9 +108,6 @@ if(LUA_FOUND) ${CMAKE_SOURCE_DIR}/tools/upbc.lua ${CMAKE_SOURCE_DIR}/tools/dump_cinit.lua ${CMAKE_SOURCE_DIR}/tools/make_c_api.lua - ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb.lua - ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/table.lua - ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/pb.lua ${CMAKE_CURRENT_BINARY_DIR}/tools) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lua/upb.lua @@ -124,6 +123,29 @@ if(LUA_FOUND) ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/table.lua ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/pb.lua ${CMAKE_CURRENT_BINARY_DIR}/upb/bindings/lua/upb) + + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/upb/pb/compile_decoder_x64.h + DEPENDS upb/pb/compile_decoder_x64.dasc + COMMAND + cd ${CMAKE_CURRENT_SOURCE_DIR} && + lua third_party/dynasm/dynasm.lua + -c upb/pb/compile_decoder_x64.dasc + > ${CMAKE_CURRENT_BINARY_DIR}/upb/pb/compile_decoder_x64.h + ) + + add_custom_target( + genfiles2 ALL + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/upb/pb/compile_decoder_x64.h + ) +endif() + +if(LUA_FOUND AND PROTOBUF_FOUND) + set(protobuf_BUILD_TESTS OFF CACHE BOOL "enable tests for proto2" FORCE) + set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "enable shared libs for proto2" FORCE) + set(protobuf_BUILD_CONFORMANCE ON CACHE BOOL "Build conformance tests" FORCE) + add_subdirectory(third_party/protobuf/cmake) + add_custom_target( upbc ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/tools/upbc @@ -164,13 +186,14 @@ if(LUA_FOUND) ) add_custom_target( - genfiles + genfiles ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.h ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/descriptor.upb.h ) add_executable(conformance_upb tests/conformance_upb.c + ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.c ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.c ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/any.upb.c ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/duration.upb.c @@ -178,13 +201,30 @@ if(LUA_FOUND) ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/struct.upb.c ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/timestamp.upb.c ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/wrappers.upb.c - ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.c - ) + ) target_link_libraries(conformance_upb LINK_PRIVATE upb -) + ) + + add_custom_target( + conformance + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/conformance_upb + ${CMAKE_CURRENT_BINARY_DIR}/third_party/protobuf/cmake/conformance_test_runner + COMMAND ${CMAKE_CURRENT_BINARY_DIR}/third_party/protobuf/cmake/conformance_test_runner ${CMAKE_CURRENT_BINARY_DIR}/conformance_upb + ) + +endif() + +if (RAGEL) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/upb/json/parser.c + DEPENDS upb/json/parser.rl + COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && RAGEL -C -o ${CMAKE_CURRENT_BINARY_DIR}/upb/json/parser.c upb/json/parser.rl + ) endif() +configure_file(tools/copy_genfiles.sh.in tools/copy_genfiles.sh) + set(UPB_SRCS upb/decode.c upb/encode.c diff --git a/tests/conformance_upb.c b/tests/conformance_upb.c index 5c0ce88..ea5365c 100644 --- a/tests/conformance_upb.c +++ b/tests/conformance_upb.c @@ -39,6 +39,10 @@ void CheckedWrite(int fd, const void *buf, size_t len) { } } +bool stringview_eql(upb_stringview view, const char *str) { + return view.size == strlen(str) && memcmp(view.data, str, view.size) == 0; +} + static const char *proto3_msg = "protobuf_test_messages.proto3.TestAllTypesProto3"; @@ -48,7 +52,7 @@ void DoTest( upb_env *env) { upb_stringview message_type = conformance_ConformanceRequest_message_type(request); - if (strcmp(message_type.data, proto3_msg) != 0) { + if (!stringview_eql(message_type, proto3_msg)) { static const char msg[] = "Only proto3 for now."; conformance_ConformanceResponse_set_skipped( response, upb_stringview_make(msg, sizeof(msg))); diff --git a/third_party/protobuf b/third_party/protobuf index 45d03a9..d340bdf 160000 --- a/third_party/protobuf +++ b/third_party/protobuf @@ -1 +1 @@ -Subproject commit 45d03a977193d1dcce5251e4bffe17bf0ba738ec +Subproject commit d340bdf50821e6db173a9e41bc7bde740275ba33 diff --git a/tools/copy_genfiles.sh.in b/tools/copy_genfiles.sh.in new file mode 100755 index 0000000..5e22625 --- /dev/null +++ b/tools/copy_genfiles.sh.in @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -e + +BINDIR=`dirname "$0"`/.. +SRCDIR=${CMAKE_CURRENT_SOURCE_DIR} +EXIT=0 + +function try_copy() { + if [ ! -f $1 ]; then + echo "Can't find $1, skipping..." + EXIT=1 + else + cp $1 $2 + echo $1 + fi +} + +try_copy $BINDIR/google/protobuf/descriptor.upb.c $SRCDIR/google/protobuf +try_copy $BINDIR/google/protobuf/descriptor.upb.h $SRCDIR/google/protobuf +try_copy $BINDIR/upb/json/parser.c $SRCDIR/upb/json +try_copy $BINDIR/upb/pb/compile_decoder_x64.h $SRCDIR/upb/pb -- cgit v1.2.3