Add basic upb cmake support.
libupb will always be statically linked, and currently doesn't ever install itself. PiperOrigin-RevId: 615136389pull/16107/head
parent
a5e5e02bdf
commit
b6032d72e3
|
@ -151,7 +151,7 @@ jobs:
|
|||
command: >-
|
||||
/test.sh ${{ matrix.flags}} ${{ env.SCCACHE_CMAKE_FLAGS }}
|
||||
-Dprotobuf_BUILD_TESTS=ON -Dprotobuf_USE_EXTERNAL_GTEST=ON
|
||||
-Dprotobuf_ABSL_PROVIDER=package
|
||||
-Dprotobuf_ABSL_PROVIDER=package -Dprotobuf_BUILD_LIBUPB=ON
|
||||
|
||||
linux-cmake-install:
|
||||
name: Linux CMake Install
|
||||
|
@ -250,7 +250,7 @@ jobs:
|
|||
-c 'set -ex;
|
||||
cd /workspace;
|
||||
sccache -z;
|
||||
cmake . ${{ matrix.flags }} ${{ env.SCCACHE_CMAKE_FLAGS }};
|
||||
cmake . -Dprotobuf_BUILD_LIBUPB=ON ${{ matrix.flags }} ${{ env.SCCACHE_CMAKE_FLAGS }};
|
||||
cmake --build . --parallel 20;
|
||||
ctest --verbose --parallel 20;
|
||||
sccache -s'
|
||||
|
@ -278,7 +278,7 @@ jobs:
|
|||
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
|
||||
command: >-
|
||||
/test.sh ${{ env.SCCACHE_CMAKE_FLAGS }}
|
||||
-Dprotobuf_BUILD_CONFORMANCE=ON -Dprotobuf_BUILD_EXAMPLES=ON -DCMAKE_CXX_STANDARD=14
|
||||
-Dprotobuf_BUILD_CONFORMANCE=ON -Dprotobuf_BUILD_EXAMPLES=ON -DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_LIBUPB=ON
|
||||
|
||||
linux-cmake-32-bit:
|
||||
name: Linux CMake 32-bit
|
||||
|
@ -306,7 +306,7 @@ jobs:
|
|||
/bin/bash -cex '
|
||||
cd /workspace;
|
||||
sccache -z;
|
||||
cmake . -DCMAKE_CXX_STANDARD=14 ${{ env.SCCACHE_CMAKE_FLAGS }};
|
||||
cmake . -DCMAKE_CXX_STANDARD=14 -Dprotobuf_BUILD_LIBUPB=ON ${{ env.SCCACHE_CMAKE_FLAGS }};
|
||||
cmake --build . --parallel 20;
|
||||
ctest --verbose --parallel 20;
|
||||
sccache -s'
|
||||
|
@ -370,7 +370,7 @@ jobs:
|
|||
flags: >-
|
||||
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
|
||||
-Dprotobuf_BUILD_SHARED_LIBS=OFF
|
||||
-Dprotobuf_BUILD_EXAMPLES=ON
|
||||
-Dprotobuf_BUILD_EXAMPLES=ON -Dprotobuf_BUILD_LIBUPB=ON
|
||||
vsversion: '2022'
|
||||
cache-prefix: windows-2022-cmake
|
||||
- name: Windows CMake 2019
|
||||
|
@ -378,7 +378,7 @@ jobs:
|
|||
flags: >-
|
||||
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
|
||||
-Dprotobuf_BUILD_SHARED_LIBS=OFF
|
||||
-Dprotobuf_BUILD_EXAMPLES=ON
|
||||
-Dprotobuf_BUILD_EXAMPLES=ON -Dprotobuf_BUILD_LIBUPB=ON
|
||||
vsversion: '2019'
|
||||
cache-prefix: windows-2019-cmake
|
||||
# windows-2019 has python3.7 installed, which is incompatible with the latest gcloud
|
||||
|
@ -386,14 +386,14 @@ jobs:
|
|||
- name: Windows CMake 32-bit
|
||||
os: windows-2022
|
||||
flags: >-
|
||||
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
|
||||
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF -Dprotobuf_BUILD_LIBUPB=ON
|
||||
vsversion: '2022'
|
||||
windows-arch: 'win32'
|
||||
cache-prefix: windows-2022-win32-cmake
|
||||
- name: Windows CMake Shared
|
||||
os: windows-2022
|
||||
flags: >-
|
||||
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF
|
||||
-G Ninja -Dprotobuf_WITH_ZLIB=OFF -Dprotobuf_BUILD_CONFORMANCE=OFF -Dprotobuf_BUILD_LIBUPB=ON
|
||||
-Dprotobuf_BUILD_SHARED_LIBS=ON
|
||||
vsversion: '2022'
|
||||
cache-prefix: windows-2022-cmake
|
||||
|
|
|
@ -31,6 +31,7 @@ option(protobuf_BUILD_EXAMPLES "Build examples" OFF)
|
|||
option(protobuf_BUILD_PROTOBUF_BINARIES "Build protobuf libraries and protoc compiler" ON)
|
||||
option(protobuf_BUILD_PROTOC_BINARIES "Build libprotoc and protoc compiler" ON)
|
||||
option(protobuf_BUILD_LIBPROTOC "Build libprotoc" OFF)
|
||||
option(protobuf_BUILD_LIBUPB "Build libupb" OFF)
|
||||
option(protobuf_DISABLE_RTTI "Remove runtime type information in the binaries" OFF)
|
||||
option(protobuf_TEST_XML_OUTDIR "Output directory for XML logs from tests." "")
|
||||
option(protobuf_ALLOW_CCACHE "Adjust build flags to allow for ccache support." OFF)
|
||||
|
@ -52,7 +53,8 @@ mark_as_advanced(protobuf_DEBUG_POSTFIX)
|
|||
if(WITH_PROTOC)
|
||||
set(protobuf_PROTOC_EXE protoc)
|
||||
set(protobuf_BUILD_PROTOC_BINARIES OFF)
|
||||
add_executable(protoc IMPORTED)
|
||||
add_executable(protoc IMPORTED GLOBAL)
|
||||
add_executable(protobuf::protoc ALIAS protoc)
|
||||
set_property(TARGET protoc PROPERTY IMPORTED_LOCATION ${WITH_PROTOC})
|
||||
endif()
|
||||
|
||||
|
@ -312,6 +314,13 @@ if (protobuf_BUILD_PROTOBUF_BINARIES)
|
|||
set(protobuf_LIB_PROTOC libprotoc)
|
||||
endif ()
|
||||
endif ()
|
||||
if (protobuf_BUILD_LIBUPB)
|
||||
include(${protobuf_SOURCE_DIR}/cmake/libupb.cmake)
|
||||
include(${protobuf_SOURCE_DIR}/cmake/upb_generators.cmake)
|
||||
if (NOT DEFINED protobuf_LIB_UPB)
|
||||
set(protobuf_LIB_UPB libupb)
|
||||
endif ()
|
||||
endif ()
|
||||
if (protobuf_BUILD_PROTOC_BINARIES)
|
||||
include(${protobuf_SOURCE_DIR}/cmake/protoc.cmake)
|
||||
if (NOT DEFINED protobuf_PROTOC_EXE)
|
||||
|
@ -340,6 +349,7 @@ if (protobuf_BUILD_TESTS OR protobuf_BUILD_CONFORMANCE OR protobuf_BUILD_EXAMPLE
|
|||
message(STATUS "Using libprotobuf : ${protobuf_LIB_PROTOBUF}")
|
||||
message(STATUS "Using libprotobuf-lite : ${protobuf_LIB_PROTOBUF_LITE}")
|
||||
message(STATUS "Using libprotoc : ${protobuf_LIB_PROTOC}")
|
||||
message(STATUS "Using libupb : ${protobuf_LIB_UPB}")
|
||||
endif(protobuf_VERBOSE)
|
||||
endif ()
|
||||
|
||||
|
|
|
@ -81,6 +81,8 @@ else()
|
|||
absl::node_hash_map
|
||||
absl::node_hash_set
|
||||
absl::optional
|
||||
absl::random_distributions
|
||||
absl::random_random
|
||||
absl::span
|
||||
absl::status
|
||||
absl::statusor
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
# CMake definitions for libupb.
|
||||
|
||||
include(${protobuf_SOURCE_DIR}/src/file_lists.cmake)
|
||||
include(${protobuf_SOURCE_DIR}/cmake/protobuf-configure-target.cmake)
|
||||
|
||||
set(bootstrap_cmake_dir ${protobuf_SOURCE_DIR}/upb/reflection/cmake)
|
||||
set(bootstrap_sources
|
||||
# Hardcode bootstrap paths
|
||||
${bootstrap_cmake_dir}/google/protobuf/descriptor.upb.h
|
||||
${bootstrap_cmake_dir}/google/protobuf/descriptor.upb_minitable.h
|
||||
${bootstrap_cmake_dir}/google/protobuf/descriptor.upb_minitable.c
|
||||
)
|
||||
|
||||
# Note: upb does not support shared library builds, and is intended to be
|
||||
# statically linked as a private dependency.
|
||||
add_library(libupb STATIC
|
||||
${libupb_srcs}
|
||||
${libupb_hdrs}
|
||||
${bootstrap_sources}
|
||||
${protobuf_version_rc_file}
|
||||
)
|
||||
|
||||
target_include_directories(libupb PUBLIC ${bootstrap_cmake_dir})
|
||||
|
||||
protobuf_configure_target(libupb)
|
||||
|
||||
set_target_properties(libupb PROPERTIES
|
||||
VERSION ${protobuf_VERSION}
|
||||
OUTPUT_NAME ${LIB_PREFIX}upb
|
||||
DEBUG_POSTFIX "${protobuf_DEBUG_POSTFIX}"
|
||||
# For -fvisibility=hidden and -fvisibility-inlines-hidden
|
||||
C_VISIBILITY_PRESET hidden
|
||||
CXX_VISIBILITY_PRESET hidden
|
||||
VISIBILITY_INLINES_HIDDEN ON
|
||||
)
|
||||
add_library(protobuf::libupb ALIAS libupb)
|
||||
target_link_libraries(libupb PRIVATE utf8_range)
|
|
@ -6,6 +6,7 @@ option(protobuf_ABSOLUTE_TEST_PLUGIN_PATH
|
|||
mark_as_advanced(protobuf_ABSOLUTE_TEST_PLUGIN_PATH)
|
||||
|
||||
include(${protobuf_SOURCE_DIR}/src/file_lists.cmake)
|
||||
include(${protobuf_SOURCE_DIR}/cmake/protobuf-generate.cmake)
|
||||
|
||||
set(lite_test_protos
|
||||
${protobuf_lite_test_protos_files}
|
||||
|
@ -19,29 +20,21 @@ set(tests_protos
|
|||
|
||||
set(protoc_cpp_args)
|
||||
if (protobuf_BUILD_SHARED_LIBS)
|
||||
set(protoc_cpp_args "dllexport_decl=PROTOBUF_TEST_EXPORTS:")
|
||||
set(protoc_cpp_args "dllexport_decl=PROTOBUF_TEST_EXPORTS")
|
||||
endif ()
|
||||
|
||||
file(MAKE_DIRECTORY ${protobuf_BINARY_DIR}/src)
|
||||
|
||||
macro(compile_proto_file filename)
|
||||
file(RELATIVE_PATH rel_filename ${protobuf_SOURCE_DIR} ${filename})
|
||||
string(REPLACE .proto .pb.h pb_hdr ${rel_filename})
|
||||
string(REPLACE .proto .pb.cc pb_src ${rel_filename})
|
||||
add_custom_command(
|
||||
OUTPUT ${pb_hdr} ${pb_src}
|
||||
DEPENDS ${protobuf_PROTOC_EXE} ${filename}
|
||||
COMMAND ${protobuf_PROTOC_EXE} ${filename}
|
||||
--proto_path=${protobuf_SOURCE_DIR}/src
|
||||
--cpp_out=${protoc_cpp_args}${protobuf_BINARY_DIR}/src
|
||||
--experimental_allow_proto3_optional
|
||||
)
|
||||
endmacro(compile_proto_file)
|
||||
|
||||
set(lite_test_proto_files)
|
||||
foreach(proto_file ${lite_test_protos})
|
||||
compile_proto_file(${proto_file})
|
||||
set(lite_test_proto_files ${lite_test_proto_files} ${pb_src} ${pb_hdr})
|
||||
protobuf_generate(
|
||||
PROTOS ${proto_file}
|
||||
LANGUAGE cpp
|
||||
OUT_VAR pb_generated_files
|
||||
IMPORT_DIRS ${protobuf_SOURCE_DIR}/src
|
||||
PLUGIN_OPTIONS ${protoc_cpp_args}
|
||||
)
|
||||
set(lite_test_proto_files ${lite_test_proto_files} ${pb_generated_files})
|
||||
endforeach(proto_file)
|
||||
|
||||
set(tests_proto_files)
|
||||
|
@ -50,8 +43,14 @@ foreach(proto_file ${tests_protos})
|
|||
# Our enormous protos are too big for windows DLLs.
|
||||
continue()
|
||||
endif ()
|
||||
compile_proto_file(${proto_file})
|
||||
set(tests_proto_files ${tests_proto_files} ${pb_src} ${pb_hdr})
|
||||
protobuf_generate(
|
||||
PROTOS ${proto_file}
|
||||
LANGUAGE cpp
|
||||
OUT_VAR pb_generated_files
|
||||
IMPORT_DIRS ${protobuf_SOURCE_DIR}/src
|
||||
PLUGIN_OPTIONS ${protoc_cpp_args}
|
||||
)
|
||||
set(tests_proto_files ${tests_proto_files} ${pb_generated_files})
|
||||
endforeach(proto_file)
|
||||
|
||||
set(common_test_files
|
||||
|
@ -196,6 +195,41 @@ add_test(NAME full-test
|
|||
COMMAND tests ${protobuf_GTEST_ARGS}
|
||||
WORKING_DIRECTORY ${protobuf_SOURCE_DIR})
|
||||
|
||||
if (protobuf_BUILD_LIBUPB)
|
||||
set(upb_test_proto_genfiles)
|
||||
foreach(proto_file ${upb_test_protos_files} ${descriptor_proto_proto_srcs})
|
||||
foreach(generator upb upbdefs upb_minitable)
|
||||
protobuf_generate(
|
||||
PROTOS ${proto_file}
|
||||
LANGUAGE ${generator}
|
||||
GENERATE_EXTENSIONS .${generator}.h .${generator}.c
|
||||
OUT_VAR pb_generated_files
|
||||
IMPORT_DIRS ${protobuf_SOURCE_DIR}/src
|
||||
IMPORT_DIRS ${protobuf_SOURCE_DIR}
|
||||
PLUGIN protoc-gen-${generator}=$<TARGET_FILE:protoc-gen-${generator}>
|
||||
DEPENDENCIES $<TARGET_FILE:protoc-gen-${generator}>
|
||||
)
|
||||
set(upb_test_proto_genfiles ${upb_test_proto_genfiles} ${pb_generated_files})
|
||||
endforeach()
|
||||
endforeach(proto_file)
|
||||
|
||||
add_executable(upb-test
|
||||
${upb_test_files}
|
||||
${upb_test_proto_genfiles}
|
||||
${upb_test_util_files})
|
||||
|
||||
target_link_libraries(upb-test
|
||||
libprotobuf
|
||||
libupb
|
||||
${protobuf_ABSL_USED_TARGETS}
|
||||
${protobuf_ABSL_USED_TEST_TARGETS}
|
||||
GTest::gmock_main)
|
||||
|
||||
add_test(NAME upb-test
|
||||
COMMAND upb-test ${protobuf_GTEST_ARGS}
|
||||
WORKING_DIRECTORY ${protobuf_SOURCE_DIR})
|
||||
endif()
|
||||
|
||||
# For test purposes, remove headers that should already be installed. This
|
||||
# prevents accidental conflicts and also version skew (since local headers take
|
||||
# precedence over installed headers).
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
include(${protobuf_SOURCE_DIR}/src/file_lists.cmake)
|
||||
|
||||
set(bootstrap_cmake_dir ${protobuf_SOURCE_DIR}/upb_generator/cmake)
|
||||
set(bootstrap_sources
|
||||
${bootstrap_cmake_dir}/google/protobuf/compiler/plugin.upb.h
|
||||
${bootstrap_cmake_dir}/google/protobuf/compiler/plugin.upb_minitable.h
|
||||
${bootstrap_cmake_dir}/google/protobuf/compiler/plugin.upb_minitable.c
|
||||
)
|
||||
|
||||
foreach(generator upb upbdefs upb_minitable)
|
||||
add_executable(protoc-gen-${generator}
|
||||
${protoc-gen-${generator}_srcs}
|
||||
${protoc-gen-${generator}_hdrs}
|
||||
${bootstrap_sources}
|
||||
${protobuf_version_rc_file}
|
||||
)
|
||||
target_include_directories(protoc-gen-${generator} PUBLIC ${bootstrap_cmake_dir})
|
||||
target_link_libraries(protoc-gen-${generator}
|
||||
libprotobuf
|
||||
libupb
|
||||
${protobuf_ABSL_USED_TARGETS}
|
||||
)
|
||||
set_target_properties(protoc-gen-${generator} PROPERTIES VERSION ${protobuf_VERSION})
|
||||
endforeach()
|
|
@ -108,6 +108,10 @@ gen_file_lists(
|
|||
":protobuf": "libprotobuf",
|
||||
":protobuf_lite": "libprotobuf_lite",
|
||||
":protoc": "libprotoc",
|
||||
":upb": "libupb",
|
||||
":protoc-gen-upb": "protoc-gen-upb",
|
||||
":protoc-gen-upbdefs": "protoc-gen-upbdefs",
|
||||
":protoc-gen-upb_minitable": "protoc-gen-upb_minitable",
|
||||
# Protos:
|
||||
"//src/google/protobuf:well_known_type_protos": "wkt_protos",
|
||||
"//src/google/protobuf:cpp_features_proto": "cpp_features_proto",
|
||||
|
@ -119,7 +123,10 @@ gen_file_lists(
|
|||
":common_test": "common_test",
|
||||
":lite_test_util": "lite_test_util",
|
||||
":test_util": "test_util",
|
||||
"//upb:test_util": "upb_test_util",
|
||||
# Tests and test-only protos:
|
||||
"//upb:test_protos": "upb_test_protos",
|
||||
"//upb:test_srcs": "upb_test",
|
||||
"//src/google/protobuf:full_test_srcs": "protobuf_test",
|
||||
"//src/google/protobuf:test_proto_all_srcs": "protobuf_test_protos",
|
||||
"//src/google/protobuf:lite_test_srcs": "protobuf_lite_test",
|
||||
|
@ -197,6 +204,55 @@ cc_dist_library(
|
|||
],
|
||||
)
|
||||
|
||||
cc_dist_library(
|
||||
name = "upb",
|
||||
tags = ["manual"],
|
||||
deps = [
|
||||
"//upb/json",
|
||||
"//upb/message:compare",
|
||||
"//upb/message:copy",
|
||||
"//upb/text",
|
||||
"//upb/util:def_to_proto",
|
||||
"//upb/util:required_fields",
|
||||
],
|
||||
)
|
||||
|
||||
cc_dist_library(
|
||||
name = "protoc-gen-upb",
|
||||
dist_deps = [
|
||||
":protobuf",
|
||||
":upb",
|
||||
],
|
||||
tags = ["manual"],
|
||||
deps = [
|
||||
"//upb_generator:protoc-gen-upb_lib",
|
||||
],
|
||||
)
|
||||
|
||||
cc_dist_library(
|
||||
name = "protoc-gen-upbdefs",
|
||||
dist_deps = [
|
||||
":protobuf",
|
||||
":upb",
|
||||
],
|
||||
tags = ["manual"],
|
||||
deps = [
|
||||
"//upb_generator:protoc-gen-upbdefs_lib",
|
||||
],
|
||||
)
|
||||
|
||||
cc_dist_library(
|
||||
name = "protoc-gen-upb_minitable",
|
||||
dist_deps = [
|
||||
":protobuf",
|
||||
":upb",
|
||||
],
|
||||
tags = ["manual"],
|
||||
deps = [
|
||||
"//upb_generator:protoc-gen-upb_minitable_lib_lib",
|
||||
],
|
||||
)
|
||||
|
||||
cc_dist_library(
|
||||
name = "lite_test_util",
|
||||
testonly = 1,
|
||||
|
|
|
@ -952,6 +952,7 @@ exports_files(
|
|||
"//:__pkg__",
|
||||
"//python:__pkg__",
|
||||
"//ruby:__pkg__",
|
||||
"//upb:__pkg__",
|
||||
],
|
||||
)
|
||||
|
||||
|
|
36
upb/BUILD
36
upb/BUILD
|
@ -416,6 +416,42 @@ filegroup(
|
|||
"//upb/cmake:__pkg__",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "test_protos",
|
||||
srcs = [
|
||||
"//src/google/protobuf:test_messages_proto2.proto",
|
||||
"//src/google/protobuf:test_messages_proto3.proto",
|
||||
"//src/google/protobuf:well_known_type_protos",
|
||||
"//upb/json:test_protos",
|
||||
"//upb/message:test_protos",
|
||||
"//upb/test:test_protos",
|
||||
"//upb/util:test_protos",
|
||||
],
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "test_srcs",
|
||||
srcs = [
|
||||
"//upb/json:test_srcs",
|
||||
"//upb/mem:test_srcs",
|
||||
"//upb/message:test_srcs",
|
||||
"//upb/test:test_srcs",
|
||||
"//upb/util:test_srcs",
|
||||
"//upb/wire:test_srcs",
|
||||
],
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "test_util",
|
||||
srcs = [
|
||||
"//upb/test:test_util",
|
||||
"//upb/util:test_util",
|
||||
],
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
)
|
||||
# end:github_only
|
||||
|
||||
# begin:google_only
|
||||
|
|
|
@ -119,17 +119,18 @@ filegroup(
|
|||
[
|
||||
"**/*test.cc",
|
||||
],
|
||||
exclude = ["fuzz_test.cc"],
|
||||
),
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "test_utils",
|
||||
name = "test_protos",
|
||||
srcs = glob(
|
||||
[
|
||||
"**/*test.proto",
|
||||
],
|
||||
),
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
# end:github_only
|
||||
|
|
|
@ -78,6 +78,6 @@ filegroup(
|
|||
"**/*test.cc",
|
||||
],
|
||||
),
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
# end:github_only
|
||||
|
|
|
@ -247,7 +247,7 @@ cc_test(
|
|||
"//upb:port",
|
||||
"//upb:wire_reader",
|
||||
"//upb/base:internal",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_absl//absl/types:variant",
|
||||
"@com_google_googletest//:gtest",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
|
@ -411,17 +411,18 @@ filegroup(
|
|||
[
|
||||
"**/*test.cc",
|
||||
],
|
||||
exclude = ["promote_test.cc"],
|
||||
),
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "test_utils",
|
||||
name = "test_protos",
|
||||
srcs = glob(
|
||||
[
|
||||
"**/*test.proto",
|
||||
"**/*.proto",
|
||||
],
|
||||
),
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
# end:github_only
|
||||
|
|
|
@ -11,10 +11,10 @@
|
|||
|
||||
#include <initializer_list>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "absl/types/variant.h"
|
||||
#include "upb/base/internal/endian.h"
|
||||
#include "upb/wire/types.h"
|
||||
|
||||
|
@ -52,7 +52,7 @@ struct Group {
|
|||
|
||||
struct UnknownField {
|
||||
uint32_t field_number;
|
||||
std::variant<Varint, LongVarint, Delimited, Fixed64, Fixed32, Group> value;
|
||||
absl::variant<Varint, LongVarint, Delimited, Fixed64, Fixed32, Group> value;
|
||||
};
|
||||
|
||||
Group::Group(std::initializer_list<UnknownField> _val) : val(_val) {}
|
||||
|
@ -70,27 +70,27 @@ std::string ToBinaryPayload(const UnknownFields& fields) {
|
|||
std::string ret;
|
||||
|
||||
for (const auto& field : fields) {
|
||||
if (const auto* val = std::get_if<Varint>(&field.value)) {
|
||||
if (const auto* val = absl::get_if<Varint>(&field.value)) {
|
||||
EncodeVarint(field.field_number << 3 | kUpb_WireType_Varint, &ret);
|
||||
EncodeVarint(val->val, &ret);
|
||||
} else if (const auto* val = std::get_if<LongVarint>(&field.value)) {
|
||||
} else if (const auto* val = absl::get_if<LongVarint>(&field.value)) {
|
||||
EncodeVarint(field.field_number << 3 | kUpb_WireType_Varint, &ret);
|
||||
EncodeVarint(val->val, &ret);
|
||||
ret.back() |= 0x80;
|
||||
ret.push_back(0);
|
||||
} else if (const auto* val = std::get_if<Delimited>(&field.value)) {
|
||||
} else if (const auto* val = absl::get_if<Delimited>(&field.value)) {
|
||||
EncodeVarint(field.field_number << 3 | kUpb_WireType_Delimited, &ret);
|
||||
EncodeVarint(val->val.size(), &ret);
|
||||
ret.append(val->val);
|
||||
} else if (const auto* val = std::get_if<Fixed64>(&field.value)) {
|
||||
} else if (const auto* val = absl::get_if<Fixed64>(&field.value)) {
|
||||
EncodeVarint(field.field_number << 3 | kUpb_WireType_64Bit, &ret);
|
||||
uint64_t swapped = upb_BigEndian64(val->val);
|
||||
ret.append(reinterpret_cast<const char*>(&swapped), sizeof(swapped));
|
||||
} else if (const auto* val = std::get_if<Fixed32>(&field.value)) {
|
||||
} else if (const auto* val = absl::get_if<Fixed32>(&field.value)) {
|
||||
EncodeVarint(field.field_number << 3 | kUpb_WireType_32Bit, &ret);
|
||||
uint32_t swapped = upb_BigEndian32(val->val);
|
||||
ret.append(reinterpret_cast<const char*>(&swapped), sizeof(swapped));
|
||||
} else if (const auto* val = std::get_if<Group>(&field.value)) {
|
||||
} else if (const auto* val = absl::get_if<Group>(&field.value)) {
|
||||
EncodeVarint(field.field_number << 3 | kUpb_WireType_StartGroup, &ret);
|
||||
ret.append(ToBinaryPayload(val->val));
|
||||
EncodeVarint(field.field_number << 3 | kUpb_WireType_EndGroup, &ret);
|
||||
|
|
|
@ -117,6 +117,6 @@ filegroup(
|
|||
"**/*test.cc",
|
||||
],
|
||||
),
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
# end:github_only
|
||||
|
|
|
@ -312,20 +312,30 @@ filegroup(
|
|||
name = "test_srcs",
|
||||
srcs = glob(
|
||||
[
|
||||
"**/*.cc",
|
||||
"**/*.h",
|
||||
"**/*test.cc",
|
||||
"**/test_*.cc",
|
||||
],
|
||||
),
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "test_utils",
|
||||
name = "test_util",
|
||||
srcs = [
|
||||
"fuzz_util.cc",
|
||||
"fuzz_util.h",
|
||||
"parse_text_proto.h",
|
||||
],
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "test_protos",
|
||||
srcs = glob(
|
||||
[
|
||||
"**/*.proto",
|
||||
],
|
||||
),
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
# end:github_only
|
||||
|
|
|
@ -164,17 +164,28 @@ filegroup(
|
|||
[
|
||||
"**/*test.cc",
|
||||
],
|
||||
exclude = ["def_to_proto_fuzz_test.cc"],
|
||||
),
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "test_utils",
|
||||
name = "test_util",
|
||||
srcs = glob(
|
||||
[
|
||||
"**/*test.h",
|
||||
],
|
||||
),
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "test_protos",
|
||||
srcs = glob(
|
||||
[
|
||||
"**/*test.proto",
|
||||
],
|
||||
),
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
# end:github_only
|
||||
|
|
|
@ -105,6 +105,6 @@ filegroup(
|
|||
"**/*test.cc",
|
||||
],
|
||||
),
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
visibility = ["//upb:__pkg__"],
|
||||
)
|
||||
# end:github_only
|
||||
|
|
|
@ -182,7 +182,6 @@ bootstrap_cc_library(
|
|||
visibility = ["//protos_generator:__pkg__"],
|
||||
deps = [
|
||||
"//:protobuf",
|
||||
"//src/google/protobuf/compiler:code_generator",
|
||||
"@com_google_absl//absl/base:core_headers",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/strings",
|
||||
|
@ -250,6 +249,17 @@ cc_library(
|
|||
|
||||
bootstrap_cc_binary(
|
||||
name = "protoc-gen-upb",
|
||||
bootstrap_deps = [
|
||||
":protoc-gen-upb_lib",
|
||||
],
|
||||
copts = UPB_DEFAULT_CPPOPTS,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# TODO: This wrapper lib is a hack that we need because of how CcInfo works in Bazel 6.
|
||||
# In Bazel 7, our cmake dependency scraping works fine with cc_binary.
|
||||
bootstrap_cc_library(
|
||||
name = "protoc-gen-upb_lib",
|
||||
srcs = ["protoc-gen-upb.cc"],
|
||||
bootstrap_deps = [
|
||||
":common",
|
||||
|
@ -261,7 +271,7 @@ bootstrap_cc_binary(
|
|||
"//upb/reflection:reflection",
|
||||
],
|
||||
copts = UPB_DEFAULT_CPPOPTS,
|
||||
visibility = ["//visibility:public"],
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
deps = [
|
||||
"//upb:base",
|
||||
"//upb:mem",
|
||||
|
@ -318,6 +328,17 @@ bootstrap_cc_library(
|
|||
|
||||
bootstrap_cc_binary(
|
||||
name = "protoc-gen-upb_minitable",
|
||||
bootstrap_deps = [
|
||||
":protoc-gen-upb_minitable_lib_lib",
|
||||
],
|
||||
copts = UPB_DEFAULT_CPPOPTS,
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
# TODO: This wrapper lib is a hack that we need because of how CcInfo works in Bazel 6.
|
||||
# In Bazel 7, our cmake dependency scraping works fine with cc_binary.
|
||||
bootstrap_cc_library(
|
||||
name = "protoc-gen-upb_minitable_lib_lib",
|
||||
srcs = ["protoc-gen-upb_minitable-main.cc"],
|
||||
bootstrap_deps = [
|
||||
":file_layout",
|
||||
|
@ -326,7 +347,7 @@ bootstrap_cc_binary(
|
|||
":protoc-gen-upb_minitable_lib",
|
||||
],
|
||||
copts = UPB_DEFAULT_CPPOPTS,
|
||||
visibility = ["//visibility:public"],
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
deps = [
|
||||
"//upb:base",
|
||||
"//upb:port",
|
||||
|
@ -348,16 +369,26 @@ proto_lang_toolchain(
|
|||
|
||||
cc_binary(
|
||||
name = "protoc-gen-upbdefs",
|
||||
linkopts = ["-lm"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":protoc-gen-upbdefs_lib",
|
||||
],
|
||||
)
|
||||
|
||||
# TODO: This wrapper lib is a hack that we need because of how CcInfo works in Bazel 6.
|
||||
# In Bazel 7, our cmake dependency scraping works fine with cc_binary.
|
||||
cc_library(
|
||||
name = "protoc-gen-upbdefs_lib",
|
||||
srcs = [
|
||||
"protoc-gen-upbdefs.cc",
|
||||
],
|
||||
copts = UPB_DEFAULT_CPPOPTS,
|
||||
visibility = ["//pkg:__pkg__"],
|
||||
# To work around the following link error from ABSL:
|
||||
# /usr/bin/x86_64-linux-gnu-ld: bazel-out/k8-opt-exec-2B5CBBC6-ST-c1776f9924ec/bin/external/com_google_absl/absl/time/libtime.a(duration.o): undefined reference to symbol 'floor@@GLIBC_2.2.5'
|
||||
# /usr/bin/x86_64-linux-gnu-ld: /opt/manylinux/2014/x86_64/lib64/libm.so.6: error adding symbols: DSO missing from command line
|
||||
# clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
|
||||
linkopts = ["-lm"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
":common",
|
||||
":file_layout",
|
||||
|
|
Loading…
Reference in New Issue