From 01bd9bed77e47240c0484c7c3865a040a8697f56 Mon Sep 17 00:00:00 2001 From: MiguelBarro Date: Mon, 11 Sep 2023 00:06:48 +0200 Subject: [PATCH 1/5] Fixing static lib generation on MSVC Signed-off-by: MiguelBarro --- build-cmake/CMakeLists.txt | 142 ++++++++++++++++++++++++++++++++++--- 1 file changed, 132 insertions(+), 10 deletions(-) diff --git a/build-cmake/CMakeLists.txt b/build-cmake/CMakeLists.txt index 6dbf193..1ccd7ee 100644 --- a/build-cmake/CMakeLists.txt +++ b/build-cmake/CMakeLists.txt @@ -5,8 +5,118 @@ SET(PACKAGE_URL https://github.com/protobuf-c/protobuf-c) SET(PACKAGE_DESCRIPTION "Protocol Buffers implementation in C") CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR) +cmake_policy(SET CMP0074 NEW) +cmake_policy(SET CMP0091 NEW) -PROJECT(protobuf-c) +PROJECT(protobuf-c C CXX) + +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}) + +# for static protobuf libraries include the dependencies +if (Protobuf_USE_STATIC_LIBS) + find_package(absl REQUIRED) + + set(protobuf_ABSL_USED_TARGETS + absl::log_severity + absl::raw_logging_internal + absl::spinlock_wait + absl::malloc_internal + absl::base + absl::throw_delegate + absl::scoped_set_env + absl::strerror + absl::hashtablez_sampler + absl::raw_hash_set + absl::crc_cpu_detect + absl::crc_internal + absl::crc32c + absl::crc_cord_state + absl::stacktrace + absl::symbolize + absl::examine_stack + absl::failure_signal_handler + absl::debugging_internal + absl::demangle_internal + absl::leak_check + absl::flags_program_name + absl::flags_config + absl::flags_marshalling + absl::flags_commandlineflag_internal + absl::flags_commandlineflag + absl::flags_private_handle_accessor + absl::flags_reflection + absl::flags_internal + absl::flags + absl::flags_usage_internal + absl::flags_usage + absl::flags_parse + absl::hash + absl::city + absl::low_level_hash + absl::log_internal_check_op + absl::log_internal_conditions + absl::log_internal_format + absl::log_internal_globals + absl::log_internal_proto + absl::log_internal_message + absl::log_internal_log_sink_set + absl::log_internal_nullguard + absl::die_if_null + absl::log_flags + absl::log_globals + absl::log_initialize + absl::log_entry + absl::log_sink + absl::log_internal_fnmatch + absl::int128 + absl::exponential_biased + absl::periodic_sampler + absl::random_distributions + absl::random_seed_gen_exception + absl::random_seed_sequences + absl::random_internal_seed_material + absl::random_internal_pool_urbg + absl::random_internal_platform + absl::random_internal_randen + absl::random_internal_randen_slow + absl::random_internal_randen_hwaes + absl::random_internal_randen_hwaes_impl + absl::random_internal_distribution_test_util + absl::status + absl::statusor + absl::string_view + absl::strings + absl::strings_internal + absl::str_format_internal + absl::cord_internal + absl::cordz_functions + absl::cordz_handle + absl::cordz_info + absl::cordz_sample_token + absl::cord + absl::graphcycles_internal + absl::kernel_timeout_internal + absl::synchronization + absl::time + absl::civil_time + absl::time_zone + absl::bad_any_cast_impl + absl::bad_optional_access + absl::bad_variant_access + ) + + find_package(utf8_range REQUIRED) + + set(protobuf_UTF8_USED_TARGETS + utf8_range::utf8_validity + utf8_range::utf8_range + ) +endif() #options option(BUILD_PROTOC "Build protoc-gen-c" ON) @@ -37,6 +147,12 @@ if(MSVC) # using Visual Studio C++ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4267 /wd4244") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4267 /wd4244") + + # Allow matching protobuf runtime dependency + if(NOT BUILD_SHARED_LIBS) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + endif(NOT BUILD_SHARED_LIBS) + ENDIF() get_filename_component(MAIN_DIR ${CMAKE_CURRENT_SOURCE_DIR} PATH) @@ -58,6 +174,8 @@ target_include_directories(protobuf-c IF (MSVC AND BUILD_SHARED_LIBS) TARGET_COMPILE_DEFINITIONS(protobuf-c PRIVATE -DPROTOBUF_C_EXPORT) ENDIF (MSVC AND BUILD_SHARED_LIBS) +target_link_libraries(protobuf-c ${protobuf_ABSL_USED_TARGETS} ${protobuf_UTF8_USED_TARGETS}) +target_compile_features(protobuf-c PRIVATE cxx_std_17) INCLUDE_DIRECTORIES(${MAIN_DIR}) INCLUDE_DIRECTORIES(${MAIN_DIR}/protobuf-c) @@ -65,13 +183,6 @@ INCLUDE_DIRECTORIES(${MAIN_DIR}/protobuf-c) IF(BUILD_PROTOC) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_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}) - ENDIF() if (MSVC AND NOT BUILD_SHARED_LIBS) @@ -105,7 +216,14 @@ target_include_directories(protoc-gen-c $ $ ) -target_link_libraries(protoc-gen-c protobuf::libprotoc protobuf::libprotobuf) +target_link_libraries(protoc-gen-c + protobuf::libprotoc + protobuf::libprotobuf + ${protobuf_ABSL_USED_TARGETS} + ${protobuf_UTF8_USED_TARGETS} +) + +target_compile_features(protoc-gen-c PRIVATE cxx_std_17) IF (MSVC AND BUILD_SHARED_LIBS) TARGET_COMPILE_DEFINITIONS(protoc-gen-c PRIVATE -DPROTOBUF_USE_DLLS) @@ -138,7 +256,11 @@ ADD_CUSTOM_COMMAND(OUTPUT t/test-full.pb.cc t/test-full.pb.h GENERATE_TEST_SOURCES(${TEST_DIR}/test-full.proto t/test-full.pb-c.c t/test-full.pb-c.h) 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}) +TARGET_LINK_LIBRARIES(cxx-generate-packed-data + ${PROTOBUF_LIBRARY} + ${protobuf_ABSL_USED_TARGETS} + ${protobuf_UTF8_USED_TARGETS} +) IF (MSVC AND BUILD_SHARED_LIBS) TARGET_COMPILE_DEFINITIONS(cxx-generate-packed-data PRIVATE -DPROTOBUF_USE_DLLS) ENDIF (MSVC AND BUILD_SHARED_LIBS) From 61933280db0dfe8db8be13d60f8a903a9166e19d Mon Sep 17 00:00:00 2001 From: MiguelBarro Date: Mon, 11 Sep 2023 00:31:37 +0200 Subject: [PATCH 2/5] Fix tests on windows by adding plugin dir to environment PATH Signed-off-by: MiguelBarro --- build-cmake/CMakeLists.txt | 47 +++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/build-cmake/CMakeLists.txt b/build-cmake/CMakeLists.txt index 1ccd7ee..aed5572 100644 --- a/build-cmake/CMakeLists.txt +++ b/build-cmake/CMakeLists.txt @@ -232,13 +232,33 @@ IF (MSVC AND BUILD_SHARED_LIBS) FILE(COPY ${PROTOBUF_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) ENDIF (MSVC AND BUILD_SHARED_LIBS) -FUNCTION(GENERATE_TEST_SOURCES PROTO_FILE SRC HDR) - ADD_CUSTOM_COMMAND(OUTPUT ${SRC} ${HDR} - COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} - ARGS --plugin=$ -I${MAIN_DIR} ${PROTO_FILE} --c_out=${CMAKE_CURRENT_BINARY_DIR} - DEPENDS protoc-gen-c) -ENDFUNCTION() +if(WIN32) + # modify the environment to hint protoc where the plugin is + string(REGEX MATCHALL "[A-Z]:[^;:]+;" PATH_VARIABLE "$ENV{PATH}" ) + foreach (itvar ${PATH_VARIABLE}) + string(REPLACE ";" "" itvar ${itvar}) + set(WINDOWS_PATH_VARIABLE "${WINDOWS_PATH_VARIABLE}\\;${itvar}" ) + endforeach( itvar ) + + FUNCTION(GENERATE_TEST_SOURCES PROTO_FILE SRC HDR) + ADD_CUSTOM_COMMAND(OUTPUT ${SRC} ${HDR} + COMMAND ${CMAKE_COMMAND} + ARGS -E env PATH="${WINDOWS_PATH_VARIABLE}\\;$" -- ${PROTOBUF_PROTOC_EXECUTABLE} + --plugin=$ -I${MAIN_DIR} ${PROTO_FILE} --c_out=${CMAKE_CURRENT_BINARY_DIR} + DEPENDS protoc-gen-c) + ENDFUNCTION() + +else(WIN32) + + FUNCTION(GENERATE_TEST_SOURCES PROTO_FILE SRC HDR) + ADD_CUSTOM_COMMAND(OUTPUT ${SRC} ${HDR} + COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} + ARGS --plugin=$ -I${MAIN_DIR} ${PROTO_FILE} --c_out=${CMAKE_CURRENT_BINARY_DIR} + DEPENDS protoc-gen-c) + ENDFUNCTION() + +endif(WIN32) IF(BUILD_TESTS) ENABLE_TESTING() @@ -248,7 +268,6 @@ GENERATE_TEST_SOURCES(${TEST_DIR}/test.proto t/test.pb-c.c t/test.pb-c.h) ADD_EXECUTABLE(test-generated-code ${TEST_DIR}/generated-code/test-generated-code.c t/test.pb-c.c t/test.pb-c.h ) TARGET_LINK_LIBRARIES(test-generated-code protobuf-c) - ADD_CUSTOM_COMMAND(OUTPUT t/test-full.pb.cc t/test-full.pb.h COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I${MAIN_DIR} ${TEST_DIR}/test-full.proto) @@ -267,7 +286,7 @@ ENDIF (MSVC AND BUILD_SHARED_LIBS) FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/t/generated-code2) ADD_CUSTOM_COMMAND(OUTPUT t/generated-code2/test-full-cxx-output.inc - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/cxx-generate-packed-data ">t/generated-code2/test-full-cxx-output.inc" + COMMAND cxx-generate-packed-data ">t/generated-code2/test-full-cxx-output.inc" DEPENDS cxx-generate-packed-data ) @@ -361,6 +380,18 @@ ADD_TEST(test-generated-code3 test-generated-code3) ADD_TEST(test-issue220 test-issue220) ADD_TEST(test-issue251 test-issue251) ADD_TEST(test-version test-version) + +if(WIN32) + set_tests_properties( + test-generated-code + test-generated-code2 + test-generated-code3 + test-issue220 + test-issue251 + test-version + PROPERTIES ENVIRONMENT "PATH=${WINDOWS_PATH_VARIABLE}\\;$" ) +endif(WIN32) + ENDIF() From 6ad31f8d4384d417ca8a8b258fdb42cf3329f9b4 Mon Sep 17 00:00:00 2001 From: Guybrush Date: Mon, 11 Sep 2023 12:16:14 +0200 Subject: [PATCH 3/5] Dispatch workflow to generate binaries. Led to some fixes in the CMake too. Signed-off-by: Guybrush --- .github/workflows/build.yml | 49 ++++++--- .github/workflows/msvc_bin.yml | 184 +++++++++++++++++++++++++++++++ build-cmake/CMakeLists.txt | 190 +++++++++++---------------------- 3 files changed, 281 insertions(+), 142 deletions(-) create mode 100644 .github/workflows/msvc_bin.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 396a6d5..9cce309 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -90,16 +90,16 @@ jobs: strategy: matrix: build_type: [Debug, Release] - os: [macos-latest, ubuntu-20.04] + os: [macos-latest, ubuntu-latest] 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 + run: sudo apt-get install -y protobuf-compiler libprotobuf-dev libprotoc-dev libabsl-dev - name: Install Mac dependencies if: startsWith(matrix.os, 'macos') - run: brew install protobuf + run: brew install protobuf abseil - name: Run cmake tests run: | mkdir build-cmake/bin @@ -117,30 +117,55 @@ jobs: name: "MSVC CMake (${{ matrix.build-type }}, DLL: ${{ matrix.shared-lib }})" runs-on: windows-latest env: - PROTOBUF_VERSION: 3.15.6 + PROTOBUF_VERSION: 24.3 + ABSEIL_VERSION: "20230802.0" steps: - uses: actions/checkout@v2 - uses: ilammy/msvc-dev-cmd@v1 + with: + arch: amd64 - uses: actions/cache@v2 - id: cache + id: protobuf-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' + - uses: actions/cache@v2 + id: abseil-cache + with: + path: ~/abseil-bin + key: ${{ env.ABSEIL_VERSION }}-${{ matrix.shared-lib }}-${{ matrix.build-type}} + - name: Build and install abseil + if: steps.abseil-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 - 7z x 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 }} .. + git clone https://github.com/abseil/abseil-cpp.git -b ${{ env.ABSEIL_VERSION }} abseil + cd ~/abseil && mkdir build && cd build + cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_INSTALL_PREFIX=~/abseil-bin -DBUILD_SHARED_LIBS=${{ matrix.shared-lib }} -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded${{ matrix.build-type == 'Debug' && 'Debug' || '' }}${{ matrix.shared-lib == 'ON' && 'DLL' || '' }} -DCMAKE_CXX_STANDARD=17 .. + nmake + nmake install + - name: Build and install utf8 compression algorithm + if: matrix.shared-lib == 'OFF' + run: | + cd ~ + git clone https://github.com/protocolbuffers/utf8_range.git utf8_range + cd ~/utf8_range && mkdir build && cd build + cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_INSTALL_PREFIX=~/utf8_range-bin -DCMAKE_CXX_STANDARD=17 -Dutf8_range_ENABLE_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -Dabsl_ROOT=~/abseil-bin -DCMAKE_POLICY_DEFAULT_CMP0074=NEW -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded${{ matrix.build-type == 'Debug' && 'Debug' || '' }}' .. + nmake + nmake install + - name: Build and install protobuf + if: steps.protobuf-cache.outputs.cache-hit != 'true' + run: | + cd ~ + git clone https://github.com/protocolbuffers/protobuf.git -b v${{ env.PROTOBUF_VERSION }} protobuf + cd ~/protobuf && 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 }} -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_EXAMPLES=OFF -Dprotobuf_ABSL_PROVIDER=package -Dabsl_ROOT=~/abseil-bin -DABSL_PROPAGATE_CXX_STD=ON .. 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 }} .. + cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DBUILD_TESTS=ON -DCMAKE_INSTALL_PREFIX=~/protobuf-c-bin -DBUILD_SHARED_LIBS=${{ matrix.shared-lib }} -DProtobuf_ROOT="~/protobuf-bin" -Dabsl_ROOT="~/abseil-bin" -Dutf8_range_ROOT="~/utf8_range-bin" .. nmake nmake test nmake install diff --git a/.github/workflows/msvc_bin.yml b/.github/workflows/msvc_bin.yml new file mode 100644 index 0000000..7e5bd7a --- /dev/null +++ b/.github/workflows/msvc_bin.yml @@ -0,0 +1,184 @@ +name: Windows/MSVC binary generation + +on: + workflow_dispatch: + inputs: + protobuf_repo: + description: 'repo associated to the protobuf repo' + default: 'https://github.com/MiguelBarro/protobuf.git' + type: string + protobuf_branch: + description: 'branch associated with the protobuf repo' + default: 'main' + type: string + protobuf-c_repo: + description: 'repo associated to the protobuf-c repo' + default: 'https://github.com/MiguelBarro/protobuf-c.git' + type: string + protobuf-c_branch: + description: 'branch associated with the protobuf-c repo' + default: 'master' + type: string + abseil_branch: + description: 'branch associated with the abseil-cpp repo' + default: 'master' + type: string + +defaults: + run: + shell: pwsh + +jobs: + build-binaries: + strategy: + matrix: + config: [Debug, Release] + shared_libs: [ON, OFF] + fail-fast: false + runs-on: windows-latest + steps: + - name: Set up an independent abseil repo + run: | + git clone --branch ${{ inputs.abseil_branch }} https://github.com/abseil/abseil-cpp.git + cd abseil-cpp + $runtime = 'MultiThreaded$<$:Debug>' + if ('${{ matrix.shared_libs }}' -eq 'ON') + { $runtime += 'DLL' } + cmake -DABSL_USE_EXTERNAL_GOOGLETEST=ON -DABSL_FIND_GOOGLETEST=ON ` + -DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} -DABSL_PROPAGATE_CXX_STD=ON ` + -DCMAKE_MSVC_RUNTIME_LIBRARY="$runtime" ` + -DCMAKE_CXX_STANDARD=17 -B build -A x64 -T host=x64 . + cmake --build build --config ${{ matrix.config }} + cmake --install build --config ${{ matrix.config }} --prefix "$Env:TMP/install/absl" + + - name: Set up the utf8 compression algorithm + if: ${{ matrix.shared_libs == 'OFF' }} + run: | + git clone https://github.com/protocolbuffers/utf8_range.git + cd utf8_range + cmake -DCMAKE_CXX_STANDARD=17 -Dutf8_range_ENABLE_TESTS=OFF ` + -DBUILD_SHARED_LIBS=OFF ` + -Dabsl_ROOT="$Env:TMP/install/absl" ` + -DCMAKE_POLICY_DEFAULT_CMP0074=NEW ` + -DCMAKE_POLICY_DEFAULT_CMP0091=NEW ` + -DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded$<$:Debug>' ` + -B build -A x64 -T host=x64 . + cmake --build build --config ${{ matrix.config }} + cmake --install build --config ${{ matrix.config }} --prefix "$Env:TMP/install/utf8_range" + + - name: Set up protobuf repo + run: | + git clone --branch ${{ inputs.protobuf_branch }} --recurse-submodules ${{ inputs.protobuf_repo }} + cd protobuf + cmake -DCMAKE_CXX_STANDARD=17 ` + -DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} ` + -Dprotobuf_BUILD_TESTS=OFF ` + -Dprotobuf_BUILD_EXAMPLES=OFF ` + -Dprotobuf_ABSL_PROVIDER=package ` + -Dabsl_ROOT="$Env:TMP/install/absl" ` + -DABSL_PROPAGATE_CXX_STD=ON ` + -B build -A x64 -T host=x64 . + cmake --build build --config ${{ matrix.config }} + cmake --install build --config ${{ matrix.config }} --prefix "$Env:TMP/install/protobuf" + + - name: Set up protobuf-c repo + id: build + run: | + git clone --branch ${{ inputs.protobuf-c_branch }} --recurse-submodules ${{ inputs.protobuf-c_repo }} + cd protobuf-c + cmake -DCMAKE_CXX_STANDARD=17 ` + -DProtobuf_ROOT="$Env:TMP/install/protobuf" ` + -DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} ` + -DBUILD_TESTS=OFF ` + -Dabsl_ROOT="$Env:TMP/install/absl" ` + -Dutf8_range_ROOT="$Env:TMP/install/utf8_range" ` + -B build-cmake/build -A x64 -T host=x64 build-cmake + cmake --build build-cmake/build --config ${{ matrix.config }} + cmake --install build-cmake/build --config ${{ matrix.config }} --prefix "$Env:TMP/install/protobuf-c" + "BINARYDIR=$Env:TMP/install" | Out-File $Env:GITHUB_OUTPUT + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: protobuf-c-binaries-${{ matrix.config }}-${{ matrix.shared_libs == 'ON' && 'dll' || 'lib'}} + path: ${{ steps.build.outputs.BINARYDIR }} + + build-binaries-nmake: + strategy: + matrix: + config: [Debug, Release] + shared_libs: [ON, OFF] + fail-fast: false + runs-on: windows-latest + steps: + + - name: Enforce a developer console + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: amd64 + + - name: Set up an independent abseil repo + run: | + git clone --branch ${{ inputs.abseil_branch }} https://github.com/abseil/abseil-cpp.git + cd abseil-cpp + $runtime = 'MultiThreaded$<$:Debug>' + if ('${{ matrix.shared_libs }}' -eq 'ON') + { $runtime += 'DLL' } + cmake -DABSL_USE_EXTERNAL_GOOGLETEST=ON -DABSL_FIND_GOOGLETEST=ON ` + -DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} -DABSL_PROPAGATE_CXX_STD=ON ` + -DCMAKE_MSVC_RUNTIME_LIBRARY="$runtime" ` + -B build -DCMAKE_CXX_STANDARD=17 -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.config }} . + cmake --build build + cmake --install build --prefix "$Env:TMP/install/absl" + + - name: Set up the utf8 compression algorithm + if: ${{ matrix.shared_libs == 'OFF' }} + run: | + git clone https://github.com/protocolbuffers/utf8_range.git + cd utf8_range + cmake -DCMAKE_CXX_STANDARD=17 -Dutf8_range_ENABLE_TESTS=OFF ` + -DBUILD_SHARED_LIBS=OFF ` + -Dabsl_ROOT="$Env:TMP/install/absl" ` + -DCMAKE_POLICY_DEFAULT_CMP0074=NEW ` + -DCMAKE_POLICY_DEFAULT_CMP0091=NEW ` + -DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded$<$:Debug>' ` + -B build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.config }} . + cmake --build build + cmake --install build --prefix "$Env:TMP/install/utf8_range" + + - name: Set up protobuf repo + run: | + git clone --branch ${{ inputs.protobuf_branch }} --recurse-submodules ${{ inputs.protobuf_repo }} + cd protobuf + cmake -DCMAKE_CXX_STANDARD=17 ` + -DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} ` + -Dprotobuf_BUILD_TESTS=OFF ` + -Dprotobuf_BUILD_EXAMPLES=OFF ` + -Dprotobuf_ABSL_PROVIDER=package ` + -Dabsl_ROOT="$Env:TMP/install/absl" ` + -DABSL_PROPAGATE_CXX_STD=ON ` + -B build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.config }} . + cmake --build build + cmake --install build --prefix "$Env:TMP/install/protobuf" + + - name: Set up protobuf-c repo + id: build + run: | + git clone --branch ${{ inputs.protobuf-c_branch }} --recurse-submodules ${{ inputs.protobuf-c_repo }} + cd protobuf-c + cmake -DCMAKE_CXX_STANDARD=17 ` + -DProtobuf_ROOT="$Env:TMP/install/protobuf" ` + -DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} ` + -DBUILD_TESTS=OFF ` + -Dabsl_ROOT="$Env:TMP/install/absl" ` + -Dutf8_range_ROOT="$Env:TMP/install/utf8_range" ` + -B build-cmake/build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.config }} build-cmake + cmake --build build-cmake/build + cmake --install build-cmake/build --prefix "$Env:TMP/install/protobuf-c" + "BINARYDIR=$Env:TMP/install" | Out-File $Env:GITHUB_OUTPUT + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: nmake-protobuf-c-binaries-${{ matrix.config }}-${{ matrix.shared_libs == 'ON' && 'dll' || 'lib'}} + path: ${{ steps.build.outputs.BINARYDIR }} diff --git a/build-cmake/CMakeLists.txt b/build-cmake/CMakeLists.txt index aed5572..1719916 100644 --- a/build-cmake/CMakeLists.txt +++ b/build-cmake/CMakeLists.txt @@ -7,6 +7,7 @@ SET(PACKAGE_DESCRIPTION "Protocol Buffers implementation in C") CMAKE_MINIMUM_REQUIRED(VERSION 3.10 FATAL_ERROR) cmake_policy(SET CMP0074 NEW) cmake_policy(SET CMP0091 NEW) +cmake_policy(SET CMP0112 NEW) PROJECT(protobuf-c C CXX) @@ -15,100 +16,15 @@ if (MSVC AND NOT BUILD_SHARED_LIBS) endif (MSVC AND NOT BUILD_SHARED_LIBS) FIND_PACKAGE(Protobuf REQUIRED) +file(REAL_PATH "${PROTOBUF_INCLUDE_DIR}" PROTOBUF_INCLUDE_DIR) INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR}) +find_package(absl REQUIRED) + # for static protobuf libraries include the dependencies if (Protobuf_USE_STATIC_LIBS) - find_package(absl REQUIRED) - - set(protobuf_ABSL_USED_TARGETS - absl::log_severity - absl::raw_logging_internal - absl::spinlock_wait - absl::malloc_internal - absl::base - absl::throw_delegate - absl::scoped_set_env - absl::strerror - absl::hashtablez_sampler - absl::raw_hash_set - absl::crc_cpu_detect - absl::crc_internal - absl::crc32c - absl::crc_cord_state - absl::stacktrace - absl::symbolize - absl::examine_stack - absl::failure_signal_handler - absl::debugging_internal - absl::demangle_internal - absl::leak_check - absl::flags_program_name - absl::flags_config - absl::flags_marshalling - absl::flags_commandlineflag_internal - absl::flags_commandlineflag - absl::flags_private_handle_accessor - absl::flags_reflection - absl::flags_internal - absl::flags - absl::flags_usage_internal - absl::flags_usage - absl::flags_parse - absl::hash - absl::city - absl::low_level_hash - absl::log_internal_check_op - absl::log_internal_conditions - absl::log_internal_format - absl::log_internal_globals - absl::log_internal_proto - absl::log_internal_message - absl::log_internal_log_sink_set - absl::log_internal_nullguard - absl::die_if_null - absl::log_flags - absl::log_globals - absl::log_initialize - absl::log_entry - absl::log_sink - absl::log_internal_fnmatch - absl::int128 - absl::exponential_biased - absl::periodic_sampler - absl::random_distributions - absl::random_seed_gen_exception - absl::random_seed_sequences - absl::random_internal_seed_material - absl::random_internal_pool_urbg - absl::random_internal_platform - absl::random_internal_randen - absl::random_internal_randen_slow - absl::random_internal_randen_hwaes - absl::random_internal_randen_hwaes_impl - absl::random_internal_distribution_test_util - absl::status - absl::statusor - absl::string_view - absl::strings - absl::strings_internal - absl::str_format_internal - absl::cord_internal - absl::cordz_functions - absl::cordz_handle - absl::cordz_info - absl::cordz_sample_token - absl::cord - absl::graphcycles_internal - absl::kernel_timeout_internal - absl::synchronization - absl::time - absl::civil_time - absl::time_zone - absl::bad_any_cast_impl - absl::bad_optional_access - absl::bad_variant_access - ) + get_property(protobuf_ABSL_USED_TARGETS DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" PROPERTY IMPORTED_TARGETS) + list(FILTER protobuf_ABSL_USED_TARGETS INCLUDE REGEX "absl::") find_package(utf8_range REQUIRED) @@ -116,6 +32,8 @@ if (Protobuf_USE_STATIC_LIBS) utf8_range::utf8_validity utf8_range::utf8_range ) +elseif(WIN32) + set(protobuf_ABSL_USED_TARGETS absl::abseil_dll) endif() #options @@ -202,15 +120,46 @@ if (MSVC AND NOT BUILD_SHARED_LIBS) endforeach(flag_var) endif (MSVC AND NOT BUILD_SHARED_LIBS) +if(WIN32) + # Modify the environment to hint protoc where the plugin is + # prepend to PATH because github host runners have abseil dll pre-installed. + # Use %PATH% instead of actually inserting it. On Github runners the PATH is so long + # it makes the NMake generated commands to fail. + set(OS_PATH_VARIABLE "$\\;%PATH%") + + if(BUILD_SHARED_LIBS) + set(OS_PATH_VARIABLE "$\\;${OS_PATH_VARIABLE}") + set(OS_PATH_VARIABLE "$\\;${OS_PATH_VARIABLE}") + endif() + +else(WIN32) + + set(OS_PATH_VARIABLE "$ENV{PATH}" ) + set(OS_PATH_VARIABLE "$:${OS_PATH_VARIABLE}") + +endif(WIN32) + IF(BUILD_PROTOC) SET(CMAKE_CXX_STANDARD 17) SET(CMAKE_CXX_STANDARD_REQUIRED ON) SET(CMAKE_CXX_EXTENSIONS OFF) -ADD_CUSTOM_COMMAND(OUTPUT protobuf-c/protobuf-c.pb.cc protobuf-c/protobuf-c.pb.h - COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} - ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I${PROTOBUF_INCLUDE_DIR} -I${MAIN_DIR} ${MAIN_DIR}/protobuf-c/protobuf-c.proto) -FILE(GLOB PROTOC_GEN_C_SRC ${MAIN_DIR}/protoc-c/*.h ${MAIN_DIR}/protoc-c/*.cc ) -ADD_EXECUTABLE(protoc-gen-c ${PROTOC_GEN_C_SRC} protobuf-c/protobuf-c.pb.cc protobuf-c/protobuf-c.pb.h) + +add_custom_target(protoc-generated-files + COMMAND ${CMAKE_COMMAND} -E env PATH="${OS_PATH_VARIABLE}" -- ${PROTOBUF_PROTOC_EXECUTABLE} + --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I${PROTOBUF_INCLUDE_DIR} + -I${MAIN_DIR} ${MAIN_DIR}/protobuf-c/protobuf-c.proto + COMMENT Running protoc on ${MAIN_DIR}/protobuf-c/protobuf-c.proto + BYPRODUCTS protobuf-c/protobuf-c.pb.cc protobuf-c/protobuf-c.pb.h + SOURCES ${MAIN_DIR}/protobuf-c/protobuf-c.proto +) + +file(GLOB PROTOC_GEN_C_SRC ${MAIN_DIR}/protoc-c/*.h ${MAIN_DIR}/protoc-c/*.cc ) +add_executable(protoc-gen-c + ${PROTOC_GEN_C_SRC} + ${CMAKE_CURRENT_BINARY_DIR}/protobuf-c/protobuf-c.pb.cc + ${CMAKE_CURRENT_BINARY_DIR}/protobuf-c/protobuf-c.pb.h +) +add_dependencies(protoc-gen-c protoc-generated-files) target_include_directories(protoc-gen-c PUBLIC $ @@ -232,33 +181,13 @@ IF (MSVC AND BUILD_SHARED_LIBS) FILE(COPY ${PROTOBUF_DLLS} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) ENDIF (MSVC AND BUILD_SHARED_LIBS) -if(WIN32) - - # modify the environment to hint protoc where the plugin is - string(REGEX MATCHALL "[A-Z]:[^;:]+;" PATH_VARIABLE "$ENV{PATH}" ) - foreach (itvar ${PATH_VARIABLE}) - string(REPLACE ";" "" itvar ${itvar}) - set(WINDOWS_PATH_VARIABLE "${WINDOWS_PATH_VARIABLE}\\;${itvar}" ) - endforeach( itvar ) - - FUNCTION(GENERATE_TEST_SOURCES PROTO_FILE SRC HDR) - ADD_CUSTOM_COMMAND(OUTPUT ${SRC} ${HDR} - COMMAND ${CMAKE_COMMAND} - ARGS -E env PATH="${WINDOWS_PATH_VARIABLE}\\;$" -- ${PROTOBUF_PROTOC_EXECUTABLE} - --plugin=$ -I${MAIN_DIR} ${PROTO_FILE} --c_out=${CMAKE_CURRENT_BINARY_DIR} - DEPENDS protoc-gen-c) - ENDFUNCTION() - -else(WIN32) - - FUNCTION(GENERATE_TEST_SOURCES PROTO_FILE SRC HDR) - ADD_CUSTOM_COMMAND(OUTPUT ${SRC} ${HDR} - COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} - ARGS --plugin=$ -I${MAIN_DIR} ${PROTO_FILE} --c_out=${CMAKE_CURRENT_BINARY_DIR} - DEPENDS protoc-gen-c) - ENDFUNCTION() - -endif(WIN32) +FUNCTION(GENERATE_TEST_SOURCES PROTO_FILE SRC HDR) + ADD_CUSTOM_COMMAND(OUTPUT ${SRC} ${HDR} + COMMAND ${CMAKE_COMMAND} + ARGS -E env PATH="${OS_PATH_VARIABLE}" -- ${PROTOBUF_PROTOC_EXECUTABLE} + --plugin=$ -I${MAIN_DIR} ${PROTO_FILE} --c_out=${CMAKE_CURRENT_BINARY_DIR} + DEPENDS protoc-gen-c) +ENDFUNCTION() IF(BUILD_TESTS) ENABLE_TESTING() @@ -269,8 +198,10 @@ ADD_EXECUTABLE(test-generated-code ${TEST_DIR}/generated-code/test-generated-cod TARGET_LINK_LIBRARIES(test-generated-code protobuf-c) ADD_CUSTOM_COMMAND(OUTPUT t/test-full.pb.cc t/test-full.pb.h - COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} - ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I${MAIN_DIR} ${TEST_DIR}/test-full.proto) + COMMAND ${CMAKE_COMMAND} + ARGS -E env PATH="${OS_PATH_VARIABLE}" -- ${PROTOBUF_PROTOC_EXECUTABLE} + --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I${MAIN_DIR} ${TEST_DIR}/test-full.proto +) GENERATE_TEST_SOURCES(${TEST_DIR}/test-full.proto t/test-full.pb-c.c t/test-full.pb-c.h) @@ -286,17 +217,17 @@ ENDIF (MSVC AND BUILD_SHARED_LIBS) FILE(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/t/generated-code2) ADD_CUSTOM_COMMAND(OUTPUT t/generated-code2/test-full-cxx-output.inc - COMMAND cxx-generate-packed-data ">t/generated-code2/test-full-cxx-output.inc" - DEPENDS cxx-generate-packed-data - ) + COMMAND ${CMAKE_COMMAND} + ARGS -E env PATH="${OS_PATH_VARIABLE}" -- cxx-generate-packed-data + ">t/generated-code2/test-full-cxx-output.inc" + DEPENDS cxx-generate-packed-data +) GENERATE_TEST_SOURCES(${TEST_DIR}/test-optimized.proto t/test-optimized.pb-c.c t/test-optimized.pb-c.h) ADD_EXECUTABLE(test-generated-code2 ${TEST_DIR}/generated-code2/test-generated-code2.c t/generated-code2/test-full-cxx-output.inc t/test-full.pb-c.h t/test-full.pb-c.c t/test-optimized.pb-c.h t/test-optimized.pb-c.c) TARGET_LINK_LIBRARIES(test-generated-code2 protobuf-c) - - GENERATE_TEST_SOURCES(${TEST_DIR}/issue220/issue220.proto t/issue220/issue220.pb-c.c t/issue220/issue220.pb-c.h) ADD_EXECUTABLE(test-issue220 ${TEST_DIR}/issue220/issue220.c t/issue220/issue220.pb-c.c t/issue220/issue220.pb-c.h) TARGET_LINK_LIBRARIES(test-issue220 protobuf-c) @@ -394,5 +325,4 @@ endif(WIN32) ENDIF() - INCLUDE(CPack) From aee40e95691dc332a2837a486a949a5d26a74119 Mon Sep 17 00:00:00 2001 From: Guybrush Date: Fri, 15 Sep 2023 12:12:15 +0200 Subject: [PATCH 4/5] Setting default repos on msvc binary generator Signed-off-by: Guybrush --- .github/workflows/msvc_bin.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/msvc_bin.yml b/.github/workflows/msvc_bin.yml index 7e5bd7a..9ad45d2 100644 --- a/.github/workflows/msvc_bin.yml +++ b/.github/workflows/msvc_bin.yml @@ -5,7 +5,7 @@ on: inputs: protobuf_repo: description: 'repo associated to the protobuf repo' - default: 'https://github.com/MiguelBarro/protobuf.git' + default: 'https://github.com/protocolbuffers/protobuf.git' type: string protobuf_branch: description: 'branch associated with the protobuf repo' @@ -13,7 +13,7 @@ on: type: string protobuf-c_repo: description: 'repo associated to the protobuf-c repo' - default: 'https://github.com/MiguelBarro/protobuf-c.git' + default: 'https://github.com/protobuf-c/protobuf-c.git' type: string protobuf-c_branch: description: 'branch associated with the protobuf-c repo' From 5db0ca5a282630464e0805780c69c779086489d4 Mon Sep 17 00:00:00 2001 From: Guybrush Date: Mon, 18 Sep 2023 17:54:31 +0200 Subject: [PATCH 5/5] enforcing reviewers comments Signed-off-by: Guybrush --- .github/workflows/build.yml | 10 +- .github/workflows/msvc_bin.yml | 184 --------------------------------- build-cmake/CMakeLists.txt | 14 +-- 3 files changed, 13 insertions(+), 195 deletions(-) delete mode 100644 .github/workflows/msvc_bin.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9cce309..7c8c34e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -90,13 +90,13 @@ jobs: strategy: matrix: build_type: [Debug, Release] - os: [macos-latest, ubuntu-latest] + 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 libabsl-dev + 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 abseil @@ -138,7 +138,7 @@ jobs: if: steps.abseil-cache.outputs.cache-hit != 'true' run: | cd ~ - git clone https://github.com/abseil/abseil-cpp.git -b ${{ env.ABSEIL_VERSION }} abseil + git clone --depth=1 https://github.com/abseil/abseil-cpp.git -b ${{ env.ABSEIL_VERSION }} abseil cd ~/abseil && mkdir build && cd build cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_INSTALL_PREFIX=~/abseil-bin -DBUILD_SHARED_LIBS=${{ matrix.shared-lib }} -DABSL_PROPAGATE_CXX_STD=ON -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded${{ matrix.build-type == 'Debug' && 'Debug' || '' }}${{ matrix.shared-lib == 'ON' && 'DLL' || '' }} -DCMAKE_CXX_STANDARD=17 .. nmake @@ -147,7 +147,7 @@ jobs: if: matrix.shared-lib == 'OFF' run: | cd ~ - git clone https://github.com/protocolbuffers/utf8_range.git utf8_range + git clone --depth=1 https://github.com/protocolbuffers/utf8_range.git utf8_range cd ~/utf8_range && mkdir build && cd build cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.build-type }} -DCMAKE_INSTALL_PREFIX=~/utf8_range-bin -DCMAKE_CXX_STANDARD=17 -Dutf8_range_ENABLE_TESTS=OFF -DBUILD_SHARED_LIBS=OFF -Dabsl_ROOT=~/abseil-bin -DCMAKE_POLICY_DEFAULT_CMP0074=NEW -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded${{ matrix.build-type == 'Debug' && 'Debug' || '' }}' .. nmake @@ -156,7 +156,7 @@ jobs: if: steps.protobuf-cache.outputs.cache-hit != 'true' run: | cd ~ - git clone https://github.com/protocolbuffers/protobuf.git -b v${{ env.PROTOBUF_VERSION }} protobuf + git clone --depth=1 https://github.com/protocolbuffers/protobuf.git -b v${{ env.PROTOBUF_VERSION }} protobuf cd ~/protobuf && 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 }} -DCMAKE_CXX_STANDARD=17 -Dprotobuf_BUILD_EXAMPLES=OFF -Dprotobuf_ABSL_PROVIDER=package -Dabsl_ROOT=~/abseil-bin -DABSL_PROPAGATE_CXX_STD=ON .. nmake diff --git a/.github/workflows/msvc_bin.yml b/.github/workflows/msvc_bin.yml deleted file mode 100644 index 9ad45d2..0000000 --- a/.github/workflows/msvc_bin.yml +++ /dev/null @@ -1,184 +0,0 @@ -name: Windows/MSVC binary generation - -on: - workflow_dispatch: - inputs: - protobuf_repo: - description: 'repo associated to the protobuf repo' - default: 'https://github.com/protocolbuffers/protobuf.git' - type: string - protobuf_branch: - description: 'branch associated with the protobuf repo' - default: 'main' - type: string - protobuf-c_repo: - description: 'repo associated to the protobuf-c repo' - default: 'https://github.com/protobuf-c/protobuf-c.git' - type: string - protobuf-c_branch: - description: 'branch associated with the protobuf-c repo' - default: 'master' - type: string - abseil_branch: - description: 'branch associated with the abseil-cpp repo' - default: 'master' - type: string - -defaults: - run: - shell: pwsh - -jobs: - build-binaries: - strategy: - matrix: - config: [Debug, Release] - shared_libs: [ON, OFF] - fail-fast: false - runs-on: windows-latest - steps: - - name: Set up an independent abseil repo - run: | - git clone --branch ${{ inputs.abseil_branch }} https://github.com/abseil/abseil-cpp.git - cd abseil-cpp - $runtime = 'MultiThreaded$<$:Debug>' - if ('${{ matrix.shared_libs }}' -eq 'ON') - { $runtime += 'DLL' } - cmake -DABSL_USE_EXTERNAL_GOOGLETEST=ON -DABSL_FIND_GOOGLETEST=ON ` - -DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} -DABSL_PROPAGATE_CXX_STD=ON ` - -DCMAKE_MSVC_RUNTIME_LIBRARY="$runtime" ` - -DCMAKE_CXX_STANDARD=17 -B build -A x64 -T host=x64 . - cmake --build build --config ${{ matrix.config }} - cmake --install build --config ${{ matrix.config }} --prefix "$Env:TMP/install/absl" - - - name: Set up the utf8 compression algorithm - if: ${{ matrix.shared_libs == 'OFF' }} - run: | - git clone https://github.com/protocolbuffers/utf8_range.git - cd utf8_range - cmake -DCMAKE_CXX_STANDARD=17 -Dutf8_range_ENABLE_TESTS=OFF ` - -DBUILD_SHARED_LIBS=OFF ` - -Dabsl_ROOT="$Env:TMP/install/absl" ` - -DCMAKE_POLICY_DEFAULT_CMP0074=NEW ` - -DCMAKE_POLICY_DEFAULT_CMP0091=NEW ` - -DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded$<$:Debug>' ` - -B build -A x64 -T host=x64 . - cmake --build build --config ${{ matrix.config }} - cmake --install build --config ${{ matrix.config }} --prefix "$Env:TMP/install/utf8_range" - - - name: Set up protobuf repo - run: | - git clone --branch ${{ inputs.protobuf_branch }} --recurse-submodules ${{ inputs.protobuf_repo }} - cd protobuf - cmake -DCMAKE_CXX_STANDARD=17 ` - -DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} ` - -Dprotobuf_BUILD_TESTS=OFF ` - -Dprotobuf_BUILD_EXAMPLES=OFF ` - -Dprotobuf_ABSL_PROVIDER=package ` - -Dabsl_ROOT="$Env:TMP/install/absl" ` - -DABSL_PROPAGATE_CXX_STD=ON ` - -B build -A x64 -T host=x64 . - cmake --build build --config ${{ matrix.config }} - cmake --install build --config ${{ matrix.config }} --prefix "$Env:TMP/install/protobuf" - - - name: Set up protobuf-c repo - id: build - run: | - git clone --branch ${{ inputs.protobuf-c_branch }} --recurse-submodules ${{ inputs.protobuf-c_repo }} - cd protobuf-c - cmake -DCMAKE_CXX_STANDARD=17 ` - -DProtobuf_ROOT="$Env:TMP/install/protobuf" ` - -DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} ` - -DBUILD_TESTS=OFF ` - -Dabsl_ROOT="$Env:TMP/install/absl" ` - -Dutf8_range_ROOT="$Env:TMP/install/utf8_range" ` - -B build-cmake/build -A x64 -T host=x64 build-cmake - cmake --build build-cmake/build --config ${{ matrix.config }} - cmake --install build-cmake/build --config ${{ matrix.config }} --prefix "$Env:TMP/install/protobuf-c" - "BINARYDIR=$Env:TMP/install" | Out-File $Env:GITHUB_OUTPUT - - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - name: protobuf-c-binaries-${{ matrix.config }}-${{ matrix.shared_libs == 'ON' && 'dll' || 'lib'}} - path: ${{ steps.build.outputs.BINARYDIR }} - - build-binaries-nmake: - strategy: - matrix: - config: [Debug, Release] - shared_libs: [ON, OFF] - fail-fast: false - runs-on: windows-latest - steps: - - - name: Enforce a developer console - uses: ilammy/msvc-dev-cmd@v1 - with: - arch: amd64 - - - name: Set up an independent abseil repo - run: | - git clone --branch ${{ inputs.abseil_branch }} https://github.com/abseil/abseil-cpp.git - cd abseil-cpp - $runtime = 'MultiThreaded$<$:Debug>' - if ('${{ matrix.shared_libs }}' -eq 'ON') - { $runtime += 'DLL' } - cmake -DABSL_USE_EXTERNAL_GOOGLETEST=ON -DABSL_FIND_GOOGLETEST=ON ` - -DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} -DABSL_PROPAGATE_CXX_STD=ON ` - -DCMAKE_MSVC_RUNTIME_LIBRARY="$runtime" ` - -B build -DCMAKE_CXX_STANDARD=17 -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.config }} . - cmake --build build - cmake --install build --prefix "$Env:TMP/install/absl" - - - name: Set up the utf8 compression algorithm - if: ${{ matrix.shared_libs == 'OFF' }} - run: | - git clone https://github.com/protocolbuffers/utf8_range.git - cd utf8_range - cmake -DCMAKE_CXX_STANDARD=17 -Dutf8_range_ENABLE_TESTS=OFF ` - -DBUILD_SHARED_LIBS=OFF ` - -Dabsl_ROOT="$Env:TMP/install/absl" ` - -DCMAKE_POLICY_DEFAULT_CMP0074=NEW ` - -DCMAKE_POLICY_DEFAULT_CMP0091=NEW ` - -DCMAKE_MSVC_RUNTIME_LIBRARY='MultiThreaded$<$:Debug>' ` - -B build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.config }} . - cmake --build build - cmake --install build --prefix "$Env:TMP/install/utf8_range" - - - name: Set up protobuf repo - run: | - git clone --branch ${{ inputs.protobuf_branch }} --recurse-submodules ${{ inputs.protobuf_repo }} - cd protobuf - cmake -DCMAKE_CXX_STANDARD=17 ` - -DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} ` - -Dprotobuf_BUILD_TESTS=OFF ` - -Dprotobuf_BUILD_EXAMPLES=OFF ` - -Dprotobuf_ABSL_PROVIDER=package ` - -Dabsl_ROOT="$Env:TMP/install/absl" ` - -DABSL_PROPAGATE_CXX_STD=ON ` - -B build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.config }} . - cmake --build build - cmake --install build --prefix "$Env:TMP/install/protobuf" - - - name: Set up protobuf-c repo - id: build - run: | - git clone --branch ${{ inputs.protobuf-c_branch }} --recurse-submodules ${{ inputs.protobuf-c_repo }} - cd protobuf-c - cmake -DCMAKE_CXX_STANDARD=17 ` - -DProtobuf_ROOT="$Env:TMP/install/protobuf" ` - -DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} ` - -DBUILD_TESTS=OFF ` - -Dabsl_ROOT="$Env:TMP/install/absl" ` - -Dutf8_range_ROOT="$Env:TMP/install/utf8_range" ` - -B build-cmake/build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=${{ matrix.config }} build-cmake - cmake --build build-cmake/build - cmake --install build-cmake/build --prefix "$Env:TMP/install/protobuf-c" - "BINARYDIR=$Env:TMP/install" | Out-File $Env:GITHUB_OUTPUT - - - name: Upload artifacts - uses: actions/upload-artifact@v3 - with: - name: nmake-protobuf-c-binaries-${{ matrix.config }}-${{ matrix.shared_libs == 'ON' && 'dll' || 'lib'}} - path: ${{ steps.build.outputs.BINARYDIR }} diff --git a/build-cmake/CMakeLists.txt b/build-cmake/CMakeLists.txt index 1719916..1e7695c 100644 --- a/build-cmake/CMakeLists.txt +++ b/build-cmake/CMakeLists.txt @@ -19,21 +19,21 @@ FIND_PACKAGE(Protobuf REQUIRED) file(REAL_PATH "${PROTOBUF_INCLUDE_DIR}" PROTOBUF_INCLUDE_DIR) INCLUDE_DIRECTORIES(${PROTOBUF_INCLUDE_DIR}) -find_package(absl REQUIRED) +find_package(absl CONFIG) # for static protobuf libraries include the dependencies if (Protobuf_USE_STATIC_LIBS) get_property(protobuf_ABSL_USED_TARGETS DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" PROPERTY IMPORTED_TARGETS) list(FILTER protobuf_ABSL_USED_TARGETS INCLUDE REGEX "absl::") - find_package(utf8_range REQUIRED) + find_package(utf8_range CONFIG) set(protobuf_UTF8_USED_TARGETS - utf8_range::utf8_validity - utf8_range::utf8_range + $ + $ ) elseif(WIN32) - set(protobuf_ABSL_USED_TARGETS absl::abseil_dll) + set(protobuf_ABSL_USED_TARGETS $) endif() #options @@ -129,7 +129,9 @@ if(WIN32) if(BUILD_SHARED_LIBS) set(OS_PATH_VARIABLE "$\\;${OS_PATH_VARIABLE}") - set(OS_PATH_VARIABLE "$\\;${OS_PATH_VARIABLE}") + if (TARGET absl::abseil_dll) + set(OS_PATH_VARIABLE "$\\;${OS_PATH_VARIABLE}") + endif() endif() else(WIN32)