diff options
-rw-r--r-- | CMakeLists.txt | 122 | ||||
-rw-r--r-- | tests/conformance_upb.c | 33 | ||||
m--------- | third_party/protobuf | 0 | ||||
-rwxr-xr-x | tools/copy_genfiles.sh.in | 22 |
4 files changed, 135 insertions, 42 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index ef68296..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) @@ -45,13 +43,19 @@ endif() include_directories(.) include_directories(${CMAKE_CURRENT_BINARY_DIR}) +set(CMAKE_CXX_FLAGS "-std=c++11 -W -Wall -Wno-sign-compare") if(APPLE) + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup -flat_namespace") elseif(UNIX) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--build-id") 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}) @@ -78,12 +82,14 @@ if(LUA_FOUND) set_target_properties(upb_c PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "lua" - PREFIX "") + LIBRARY_OUTPUT_DIRECTORY "upb/bindings/lua" + PREFIX "" + SUFFIX ".so") set_target_properties(table_c pb_c PROPERTIES - LIBRARY_OUTPUT_DIRECTORY "lua/upb" - PREFIX "") + LIBRARY_OUTPUT_DIRECTORY "upb/bindings/lua/upb" + PREFIX "" + SUFFIX ".so") add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/tools/upbc @@ -102,16 +108,13 @@ 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 DEPENDS ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb.lua COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb.lua - ${CMAKE_CURRENT_BINARY_DIR}/lua) + ${CMAKE_CURRENT_BINARY_DIR}/upb/bindings/lua) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lua/upb/pb.lua DEPENDS ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/table.lua @@ -119,7 +122,30 @@ if(LUA_FOUND) COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/table.lua ${CMAKE_SOURCE_DIR}/upb/bindings/lua/upb/pb.lua - ${CMAKE_CURRENT_BINARY_DIR}/lua/upb) + ${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 @@ -129,6 +155,14 @@ if(LUA_FOUND) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/conformance.upb.h + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.upb.h + ${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 + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/field_mask.upb.c + ${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 DEPENDS upbc ${CMAKE_CURRENT_SOURCE_DIR}/third_party/protobuf/conformance/conformance.proto COMMAND protoc --include_imports @@ -152,12 +186,45 @@ 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 + ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/field_mask.upb.c + ${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 + ) + 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 @@ -211,18 +278,3 @@ set_property(TARGET upbhandlers_pic PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET upbpb_pic PROPERTY POSITION_INDEPENDENT_CODE ON) set_property(TARGET upbjson_pic PROPERTY POSITION_INDEPENDENT_CODE ON) -add_executable(conformance_upb - tests/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 - ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/field_mask.upb.c - ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/struct.upb.c - ${CMAKE_CURRENT_BINARY_DIR}/google/protobuf/test_messages_proto3.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 -) diff --git a/tests/conformance_upb.c b/tests/conformance_upb.c index 70ea300..ea5365c 100644 --- a/tests/conformance_upb.c +++ b/tests/conformance_upb.c @@ -39,17 +39,34 @@ 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"; + void DoTest( const conformance_ConformanceRequest* request, conformance_ConformanceResponse *response, upb_env *env) { - conformance_ConformanceResponse_new(env); - protobuf_test_messages_proto3_TestAllTypes *test_message; + upb_stringview message_type = + conformance_ConformanceRequest_message_type(request); + 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))); + return; + } + + protobuf_test_messages_proto3_TestAllTypesProto3 *test_message; switch (conformance_ConformanceRequest_payload_case(request)) { - case conformance_ConformanceRequest_payload_protobuf_payload: - test_message = protobuf_test_messages_proto3_TestAllTypes_parsenew( - conformance_ConformanceRequest_protobuf_payload(request), env); + case conformance_ConformanceRequest_payload_protobuf_payload: { + upb_stringview payload = + conformance_ConformanceRequest_protobuf_payload(request); + test_message = protobuf_test_messages_proto3_TestAllTypesProto3_parsenew( + payload, env); if (!test_message) { /* TODO(haberman): return details. */ @@ -59,6 +76,7 @@ void DoTest( return; } break; + } case conformance_ConformanceRequest_payload_json_payload: { static const char msg[] = "JSON support not yet implemented."; @@ -79,8 +97,9 @@ void DoTest( case conformance_PROTOBUF: { size_t serialized_len; - char *serialized = protobuf_test_messages_proto3_TestAllTypes_serialize( - test_message, env, &serialized_len); + char *serialized = + protobuf_test_messages_proto3_TestAllTypesProto3_serialize( + test_message, env, &serialized_len); if (!serialized) { static const char msg[] = "Error serializing."; conformance_ConformanceResponse_set_serialize_error( diff --git a/third_party/protobuf b/third_party/protobuf -Subproject 6bd51a59df41b99058ec8c2b03a177a218267ce +Subproject d340bdf50821e6db173a9e41bc7bde740275ba3 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 |