Skip to content

Commit

Permalink
upb: Fix using host tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Tradias committed Jul 15, 2024
1 parent 16f44c7 commit 3e13edc
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 164 deletions.
331 changes: 169 additions & 162 deletions ports/upb/fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -1,162 +1,169 @@
diff --git a/upb/cmake/CMakeLists.txt b/upb/cmake/CMakeLists.txt
index 513d34041..a78bb1ee4 100644
--- a/upb/cmake/CMakeLists.txt
+++ b/upb/cmake/CMakeLists.txt
@@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.10...3.24)

project(upb)
set(CMAKE_C_STANDARD 99)
+set(CMAKE_CXX_STANDARD 11)

# Prevent CMake from setting -rdynamic on Linux (!!).
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
@@ -39,6 +40,7 @@ if(UPB_ENABLE_UBSAN)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
endif()

+find_package(utf8_range REQUIRED CONFIG)
if(NOT TARGET utf8_range)
if(EXISTS ../../third_party/utf8_range)
# utf8_range is already installed
@@ -58,6 +60,11 @@ if(NOT TARGET utf8_range)
endif()
endif()

+if (VCPKG_UPB_BUILD_CODEGEN)
+ find_package(absl CONFIG REQUIRED)
+ find_package(protobuf CONFIG REQUIRED)
+endif()
+
if(APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup -flat_namespace")
elseif(UNIX)
@@ -94,3 +101,129 @@ target_include_directories(generated_cpp_support__only_for_generated_code_do_not
)


+file(GLOB_RECURSE source_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/../" "${CMAKE_CURRENT_SOURCE_DIR}/../*.c")
+list(FILTER source_files EXCLUDE REGEX ".*(_test|upb_so|util|cmake|conformance|stage0).*")
+list(TRANSFORM source_files PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/../")
+
+add_library(upb_stage0 OBJECT ${source_files} "${CMAKE_CURRENT_SOURCE_DIR}/../reflection/stage0/google/protobuf/descriptor.upb.c")
+target_include_directories(upb_stage0 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../reflection/stage0>)
+target_link_libraries(upb_stage0 PRIVATE utf8_range::utf8_range)
+target_compile_definitions(upb_stage0 PUBLIC UPB_BOOTSTRAP_STAGE0)
+
+if (VCPKG_UPB_BUILD_CODEGEN)
+ add_library(common OBJECT
+ ../util/def_to_proto.c
+ ../../upb_generator/common.cc
+ ../../upb_generator/file_layout.cc
+ ../../upb_generator/names.cc
+ ../../upb_generator/stage0/google/protobuf/compiler/plugin.upb.c
+ )
+ target_link_libraries(common PUBLIC
+ upb_stage0
+ absl::flat_hash_map
+ absl::flat_hash_set
+ )
+ target_include_directories(common PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../upb_generator/stage0>)
+
+ add_executable(protoc-gen-upbdefs
+ ../../upb_generator/protoc-gen-upbdefs.cc
+ )
+ target_link_libraries(protoc-gen-upbdefs PRIVATE
+ common
+ upb_stage0
+ absl::absl_log
+ absl::strings
+ protobuf::libprotobuf
+ protobuf::libprotoc
+ )
+
+ add_executable(protoc-gen-upb
+ ../../upb_generator/protoc-gen-upb.cc
+ )
+ target_link_libraries(protoc-gen-upb PRIVATE
+ common
+ upb_stage0
+ absl::absl_check
+ absl::absl_log
+ absl::strings
+ protobuf::libprotobuf
+ protobuf::libprotoc
+ )
+
+ add_executable(protoc-gen-upb_minitable
+ ../../upb_generator/protoc-gen-upb_minitable.cc
+ ../../upb_generator/protoc-gen-upb_minitable-main.cc
+ )
+ target_link_libraries(protoc-gen-upb_minitable PRIVATE
+ common
+ upb_stage0
+ absl::absl_check
+ absl::absl_log
+ absl::strings
+ protobuf::libprotobuf
+ protobuf::libprotoc
+ )
+
+ list(APPEND _upb_codegen_targets protoc-gen-upbdefs protoc-gen-upb protoc-gen-upb_minitable)
+ add_executable(upb::protoc-gen-upb ALIAS protoc-gen-upb)
+ add_executable(upb::protoc-gen-upbdefs ALIAS protoc-gen-upbdefs)
+ add_executable(upb::protoc-gen-upb_minitable ALIAS protoc-gen-upb_minitable)
+else()
+ find_package(upb CONFIG REQUIRED)
+endif()
+
+set(descriptor_sources
+ "${CMAKE_CURRENT_BINARY_DIR}/generated/google/protobuf/descriptor.upb.c"
+ "${CMAKE_CURRENT_BINARY_DIR}/generated/google/protobuf/descriptor.upbdefs.c"
+ "${CMAKE_CURRENT_BINARY_DIR}/generated/google/protobuf/descriptor.upb_minitable.c")
+
+set(descriptor_proto "${CMAKE_CURRENT_SOURCE_DIR}/../../src/google/protobuf/descriptor.proto")
+file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated")
+add_custom_command(
+ OUTPUT ${descriptor_sources}
+ DEPENDS "${descriptor_proto}"
+ COMMAND
+ protobuf::protoc "-I${CMAKE_CURRENT_SOURCE_DIR}/../../src/"
+ "--plugin=protoc-gen-upb=$<TARGET_FILE:upb::protoc-gen-upb>"
+ "--plugin=protoc-gen-upbdefs=$<TARGET_FILE:upb::protoc-gen-upbdefs>"
+ "--plugin=protoc-gen-upb_minitable=$<TARGET_FILE:upb::protoc-gen-upb_minitable>"
+ "--upb_out=${CMAKE_CURRENT_BINARY_DIR}/generated" "--upbdefs_out=${CMAKE_CURRENT_BINARY_DIR}/generated"
+ "--upb_minitable_out=${CMAKE_CURRENT_BINARY_DIR}/generated"
+ "${descriptor_proto}")
+
+add_library(upb ${source_files} ${descriptor_sources})
+target_include_directories(upb PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..> $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/generated>)
+target_link_libraries(upb PRIVATE utf8_range::utf8_range)
+
+include(GNUInstallDirs)
+
+target_include_directories(upb PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/reflection/stage0>)
+
+install(EXPORT ${PROJECT_NAME}-targets
+ DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}"
+ NAMESPACE ${PROJECT_NAME}::
+)
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
+ "include(CMakeFindDependencyMacro)\nfind_dependency(utf8_range)\ninclude(\"\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}-targets.cmake\")")
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}")
+
+install(TARGETS upb ${_upb_codegen_targets} EXPORT ${PROJECT_NAME}-targets
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+)
+
+install(FILES
+ ../generated_code_support.h
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
+)
+foreach(_dir base collections hash io json lex mem message mini_descriptor mini_table port reflection text wire)
+ install(DIRECTORY "../${_dir}"
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
+ FILES_MATCHING
+ PATTERN "*.hpp"
+ PATTERN "*.h"
+ PATTERN "*.inc"
+ )
+endforeach()
diff --git a/upb/cmake/CMakeLists.txt b/upb/cmake/CMakeLists.txt
index 513d34041..6c70526ed 100644
--- a/upb/cmake/CMakeLists.txt
+++ b/upb/cmake/CMakeLists.txt
@@ -4,6 +4,7 @@ cmake_minimum_required(VERSION 3.10...3.24)

project(upb)
set(CMAKE_C_STANDARD 99)
+set(CMAKE_CXX_STANDARD 11)

# Prevent CMake from setting -rdynamic on Linux (!!).
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
@@ -39,6 +40,7 @@ if(UPB_ENABLE_UBSAN)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
endif()

+find_package(utf8_range REQUIRED CONFIG)
if(NOT TARGET utf8_range)
if(EXISTS ../../third_party/utf8_range)
# utf8_range is already installed
@@ -58,6 +60,11 @@ if(NOT TARGET utf8_range)
endif()
endif()

+if (VCPKG_UPB_BUILD_CODEGEN)
+ find_package(absl CONFIG REQUIRED)
+ find_package(protobuf CONFIG REQUIRED)
+endif()
+
if(APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup -flat_namespace")
elseif(UNIX)
@@ -94,3 +101,136 @@ target_include_directories(generated_cpp_support__only_for_generated_code_do_not
)


+file(GLOB_RECURSE source_files RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/../" "${CMAKE_CURRENT_SOURCE_DIR}/../*.c")
+list(FILTER source_files EXCLUDE REGEX ".*(_test|upb_so|util|cmake|conformance|stage0).*")
+list(TRANSFORM source_files PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/../")
+
+add_library(upb_stage0 OBJECT ${source_files} "${CMAKE_CURRENT_SOURCE_DIR}/../reflection/stage0/google/protobuf/descriptor.upb.c")
+target_include_directories(upb_stage0 PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../reflection/stage0>)
+target_link_libraries(upb_stage0 PRIVATE utf8_range::utf8_range)
+target_compile_definitions(upb_stage0 PUBLIC UPB_BOOTSTRAP_STAGE0)
+
+if (VCPKG_UPB_BUILD_CODEGEN)
+ add_library(common OBJECT
+ ../util/def_to_proto.c
+ ../../upb_generator/common.cc
+ ../../upb_generator/file_layout.cc
+ ../../upb_generator/names.cc
+ ../../upb_generator/stage0/google/protobuf/compiler/plugin.upb.c
+ )
+ target_link_libraries(common PUBLIC
+ upb_stage0
+ absl::flat_hash_map
+ absl::flat_hash_set
+ )
+ target_include_directories(common PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../upb_generator/stage0>)
+
+ add_executable(protoc-gen-upbdefs
+ ../../upb_generator/protoc-gen-upbdefs.cc
+ )
+ target_link_libraries(protoc-gen-upbdefs PRIVATE
+ common
+ upb_stage0
+ absl::absl_log
+ absl::strings
+ protobuf::libprotobuf
+ protobuf::libprotoc
+ )
+
+ add_executable(protoc-gen-upb
+ ../../upb_generator/protoc-gen-upb.cc
+ )
+ target_link_libraries(protoc-gen-upb PRIVATE
+ common
+ upb_stage0
+ absl::absl_check
+ absl::absl_log
+ absl::strings
+ protobuf::libprotobuf
+ protobuf::libprotoc
+ )
+
+ add_executable(protoc-gen-upb_minitable
+ ../../upb_generator/protoc-gen-upb_minitable.cc
+ ../../upb_generator/protoc-gen-upb_minitable-main.cc
+ )
+ target_link_libraries(protoc-gen-upb_minitable PRIVATE
+ common
+ upb_stage0
+ absl::absl_check
+ absl::absl_log
+ absl::strings
+ protobuf::libprotobuf
+ protobuf::libprotoc
+ )
+
+ list(APPEND _upb_codegen_targets protoc-gen-upbdefs protoc-gen-upb protoc-gen-upb_minitable)
+ set(protoc_program "\$<TARGET_FILE:protobuf::protoc>")
+ set(protoc_gen_upb_program "\$<TARGET_FILE:protoc-gen-upb>")
+ set(protoc_gen_upbdefs_program "\$<TARGET_FILE:protoc-gen-upbdefs>")
+ set(protoc_gen_upb_minitable_program "\$<TARGET_FILE:protoc-gen-upb_minitable>")
+else()
+ find_program(protoc_program protoc)
+ find_program(protoc_gen_upb_program protoc-gen-upb)
+ find_program(protoc_gen_upbdefs_program protoc-gen-upbdefs)
+ find_program(protoc_gen_upb_minitable_program protoc-gen-upb_minitable)
+endif()
+
+set(descriptor_sources
+ "${CMAKE_CURRENT_BINARY_DIR}/generated/google/protobuf/descriptor.upb.c"
+ "${CMAKE_CURRENT_BINARY_DIR}/generated/google/protobuf/descriptor.upbdefs.c"
+ "${CMAKE_CURRENT_BINARY_DIR}/generated/google/protobuf/descriptor.upb_minitable.c")
+
+set(descriptor_proto "${CMAKE_CURRENT_SOURCE_DIR}/../../src/google/protobuf/descriptor.proto")
+set(descriptor_binary_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
+file(MAKE_DIRECTORY "${descriptor_binary_dir}")
+add_custom_command(
+ OUTPUT ${descriptor_sources}
+ DEPENDS "${descriptor_proto}"
+ COMMAND
+ "${protoc_program}"
+ "-I${CMAKE_CURRENT_SOURCE_DIR}/../../src/"
+ "--plugin=protoc-gen-upb=${protoc_gen_upb_program}"
+ "--plugin=protoc-gen-upbdefs=${protoc_gen_upbdefs_program}"
+ "--plugin=protoc-gen-upb_minitable=${protoc_gen_upb_minitable_program}"
+ "--upb_out=${descriptor_binary_dir}"
+ "--upbdefs_out=${descriptor_binary_dir}"
+ "--upb_minitable_out=${descriptor_binary_dir}"
+ "${descriptor_proto}")
+
+add_library(upb ${source_files} ${descriptor_sources})
+target_include_directories(upb PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../..> $<BUILD_INTERFACE:${descriptor_binary_dir}>)
+target_link_libraries(upb PRIVATE utf8_range::utf8_range)
+
+include(GNUInstallDirs)
+
+target_include_directories(upb PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/reflection/stage0>)
+
+install(EXPORT ${PROJECT_NAME}-targets
+ DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}"
+ NAMESPACE ${PROJECT_NAME}::
+)
+file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
+ "include(CMakeFindDependencyMacro)\nfind_dependency(utf8_range)\ninclude(\"\${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}-targets.cmake\")")
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}")
+
+install(TARGETS upb ${_upb_codegen_targets} EXPORT ${PROJECT_NAME}-targets
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
+ INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
+)
+
+install(FILES
+ ../generated_code_support.h
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
+)
+foreach(_dir base collections hash io json lex mem message mini_descriptor mini_table port reflection text wire)
+ install(DIRECTORY "../${_dir}"
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}"
+ FILES_MATCHING
+ PATTERN "*.hpp"
+ PATTERN "*.h"
+ PATTERN "*.inc"
+ )
+endforeach()
2 changes: 1 addition & 1 deletion ports/upb/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if (VCPKG_UPB_BUILD_CODEGEN)
protoc-gen-upb_minitable
)
else()
configure_file("${CMAKE_CURRENT_LIST_DIR}/upb-config-vcpkg-tools.cmake" "${CURRENT_PACKAGES_DIR}/share/upb/upb-config-vcpkg-tools.cmake" @ONLY)
configure_file("${CMAKE_CURRENT_LIST_DIR}/upb-targets-vcpkg-tools.cmake" "${CURRENT_PACKAGES_DIR}/share/upb/upb-targets-vcpkg-tools.cmake" @ONLY)
endif()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share" "${CURRENT_PACKAGES_DIR}/debug/include")
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion versions/u-/upb.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"versions": [
{
"git-tree": "7c7148f2d6790fdb92952b501d84bf5d753ceb93",
"git-tree": "c48ab0ba0ff5337da5012b7bf8378404a0dedd20",
"version": "5.26.1",
"port-version": 0
},
Expand Down

0 comments on commit 3e13edc

Please sign in to comment.