From 10b50f0f4976939969855941476249b5b78a300d Mon Sep 17 00:00:00 2001 From: Corentin Le Molgat Date: Thu, 16 Jan 2025 13:02:55 -0800 Subject: [PATCH] Deep CI rework with few fix ## CI * Add few more CI workflows * Add CMake and Bazel workflows to get badges * Add MacOS (amd64 and M1) and Windows (amd64) jobs * Add C++ 14, 17 and 20 setup bor bazel jobs ## Code * Fix C++14 build: * using `absl::optional` and `absl::variant` (#184) * use of `absl::string_view` (fix cl/715199813 #185 regression) * Add pybind_abseil deps for tests/ note: Protobuf v29 (as well as abseil-cpp 20240722) still support C++14 and will drop it in v30 * Fix Windows MSVC compilation ## Dependencies * Bump protobuf to v29.2 everywhere * previously: 23.1 (bazel module), 25.3 (bazel workspace), 23.3 (cmake) ## Bazel * bazelrc: Fix windows (MSVC) default build flags * bazelrc: support user configuration override * Fix the workspace mode when using bazel 8 ## CMake * declare `pybind_extension` as `MODULE` to fix macOS XCode build jobs * fix Python3 usage note: on manylinux images, Python Libraries are NOT available, only headers since python native modules are loaded by the python interpreter and must not be linked to python. ref: https://peps.python.org/pep-0513/#libpythonx-y-so-1 PiperOrigin-RevId: 716347968 --- .bazelignore | 1 + .bazelrc | 11 +- .github/workflows/amd64_linux_bazel.yml | 73 ++++++++ .github/workflows/amd64_linux_cmake.yml | 74 ++++++++ .github/workflows/amd64_macos_bazel.yml | 75 ++++++++ .github/workflows/amd64_macos_cmake.yml | 71 ++++++++ .github/workflows/amd64_windows_bazel.yml | 76 +++++++++ .github/workflows/amd64_windows_cmake.yml | 69 ++++++++ .github/workflows/arm64_macos_bazel.yml | 75 ++++++++ .github/workflows/arm64_macos_cmake.yml | 71 ++++++++ .github/workflows/pre-commit.yml | 4 +- .github/workflows/ubuntu-build.yml | 82 +++++---- .gitignore | 6 + CMakeLists.txt | 161 ++---------------- MODULE.bazel | 109 +++++------- README.md | 28 +++ WORKSPACE | 105 +++++++----- cmake/dependencies/CMakeLists.txt | 82 +++++++++ pybind11_protobuf/BUILD | 1 + pybind11_protobuf/CMakeLists.txt | 89 ++++++++++ pybind11_protobuf/check_unknown_fields.cc | 8 +- pybind11_protobuf/check_unknown_fields.h | 4 +- pybind11_protobuf/proto_cast_util.cc | 5 + .../requirements/requirements.in | 3 +- .../requirements/requirements_lock_3_10.txt | 13 ++ .../requirements/requirements_lock_3_11.txt | 13 ++ .../requirements/requirements_lock_3_12.txt | 13 ++ .../requirements/requirements_lock_3_8.txt | 13 ++ .../requirements/requirements_lock_3_9.txt | 13 ++ pybind11_protobuf/tests/BUILD | 4 + pybind11_protobuf/tests/CMakeLists.txt | 14 +- pybind11_protobuf/tests/pass_by_module.cc | 26 ++- pybind11_protobuf/tests/thread_module.cc | 1 + pybind11_protobuf/wrapped_proto_caster.h | 2 +- 34 files changed, 1082 insertions(+), 313 deletions(-) create mode 100644 .bazelignore create mode 100644 .github/workflows/amd64_linux_bazel.yml create mode 100644 .github/workflows/amd64_linux_cmake.yml create mode 100644 .github/workflows/amd64_macos_bazel.yml create mode 100644 .github/workflows/amd64_macos_cmake.yml create mode 100644 .github/workflows/amd64_windows_bazel.yml create mode 100644 .github/workflows/amd64_windows_cmake.yml create mode 100644 .github/workflows/arm64_macos_bazel.yml create mode 100644 .github/workflows/arm64_macos_cmake.yml create mode 100644 .gitignore create mode 100644 cmake/dependencies/CMakeLists.txt create mode 100644 pybind11_protobuf/CMakeLists.txt diff --git a/.bazelignore b/.bazelignore new file mode 100644 index 0000000..378eac2 --- /dev/null +++ b/.bazelignore @@ -0,0 +1 @@ +build diff --git a/.bazelrc b/.bazelrc index 326b0ec..531fc92 100644 --- a/.bazelrc +++ b/.bazelrc @@ -4,10 +4,15 @@ common --announce_rc # Enable verbose failures for testing only. build --verbose_failures -# Compiler options. -build --cxxopt=-std=c++17 -build --host_cxxopt=-std=c++17 +# Abseil requires C++14 at minimum. +build --enable_platform_specific_config +build:linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 +build:macos --cxxopt=-std=c++17 --host_cxxopt=-std=c++17 +build:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 # Enable logging error output. test --test_output=errors test --test_summary=detailed + +# https://bazel.build/configure/best-practices#bazelrc-file +try-import %workspace%/user.bazelrc diff --git a/.github/workflows/amd64_linux_bazel.yml b/.github/workflows/amd64_linux_bazel.yml new file mode 100644 index 0000000..0020c52 --- /dev/null +++ b/.github/workflows/amd64_linux_bazel.yml @@ -0,0 +1,73 @@ +# ref: https://github.com/actions/runner-images +name: amd64 Linux Bazel + +on: [push, pull_request, workflow_dispatch] + +# Building using the github runner environement directly. +jobs: + native: + strategy: + matrix: + bazel: [ + {compilation_mode: opt}, + {compilation_mode: dbg}, + ] + cpp: [ + {version: 14, flags: "-std=c++14"}, + {version: 17, flags: "-std=c++17"}, + {version: 20, flags: "-std=c++20"}, + ] + python: [ + #{version: '3.11'}, + {version: '3.12'}, + ] + exclude: + # only test `-c dbg` build with C++17 + - cpp: {version: 14} + bazel: {compilation_mode: dbg} + - cpp: {version: 20} + bazel: {compilation_mode: dbg} + fail-fast: false + name: Linux•Bazel(${{ matrix.bazel.compilation_mode }})•C++${{ matrix.cpp.version }}•Python${{ matrix.python.version }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check Java + run: java -version + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python.version }} + - name: Check Python + run: | + python --version + python -m platform + - uses: bazel-contrib/setup-bazel@0.8.4 + with: + bazelisk-cache: true + disk-cache: ${{ github.workflow }} + repository-cache: true + - name: Check Bazel + run: bazel version + - name: Build + run: > + bazel build + -c ${{ matrix.bazel.compilation_mode }} + --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --subcommands=pretty_print + --enable_bzlmod + //... + - name: Test + run: > + bazel test + -c ${{ matrix.bazel.compilation_mode }} + --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --subcommands=pretty_print + --enable_bzlmod + //... + + amd64_linux_bazel: + runs-on: ubuntu-latest + needs: native + steps: + - uses: actions/checkout@v4 diff --git a/.github/workflows/amd64_linux_cmake.yml b/.github/workflows/amd64_linux_cmake.yml new file mode 100644 index 0000000..7b28af3 --- /dev/null +++ b/.github/workflows/amd64_linux_cmake.yml @@ -0,0 +1,74 @@ +# ref: https://github.com/actions/runner-images +name: amd64 Linux CMake + +on: [push, pull_request, workflow_dispatch] + +# Building using the github runner environement directly. +jobs: + native: + strategy: + matrix: + python: [ + {version: '3.9'}, + {version: '3.10'}, + {version: '3.11'}, + {version: '3.12'}, + #{version: '3.13'}, + ] + cmake: [ + {generator: "Unix Makefiles", config: "Release"}, + {generator: "Ninja", config: "Release"}, + #{generator: "Ninja Multi-Config", config: "Release"}, + ] + fail-fast: false + name: Linux•CMake(${{ matrix.cmake.generator }})•Python${{ matrix.python.version }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python.version }} + - name: Check Python + run: | + python --version + python -m platform + - name: Install Python requirements + run: python -m pip install --upgrade -r $(python -c 'import sys; print("./pybind11_protobuf/requirements/requirements_lock_%d_%d.txt" % (sys.version_info[:2]))') + - name: Install Ninja + run: | + sudo apt-get update + sudo apt-get install ninja-build + - name: Check CMake + run: cmake --version + - name: Configure + run: > + cmake -S. -Bbuild + -G "${{ matrix.cmake.generator }}" + -DCMAKE_BUILD_TYPE=${{ matrix.cmake.config }} + -DCMAKE_INSTALL_PREFIX=install + - name: Build + run: > + cmake --build build + --config ${{ matrix.cmake.config }} + --target all + -v -j2 + - name: Test + run: > + CTEST_OUTPUT_ON_FAILURE=1 + cmake --build build + --config ${{ matrix.cmake.config }} + --target test + -v + - name: Install + run: > + cmake --build build + --config ${{ matrix.cmake.config }} + --target install + -v + + amd64_linux_cmake: + runs-on: ubuntu-latest + needs: native + steps: + - uses: actions/checkout@v4 diff --git a/.github/workflows/amd64_macos_bazel.yml b/.github/workflows/amd64_macos_bazel.yml new file mode 100644 index 0000000..6c623b0 --- /dev/null +++ b/.github/workflows/amd64_macos_bazel.yml @@ -0,0 +1,75 @@ +# ref: https://github.com/actions/runner-images +name: amd64 MacOS Bazel + +on: [push, pull_request, workflow_dispatch] + +# Building using the github runner environement directly. +jobs: + native: + strategy: + matrix: + bazel: [ + {compilation_mode: opt}, + {compilation_mode: dbg}, + ] + cpp: [ + #{version: 14, flags: "-std=c++14"}, + {version: 17, flags: "-std=c++17"}, + #{version: 20, flags: "-std=c++20"}, + ] + python: [ + #{version: '3.11'}, + {version: '3.12'}, + ] + exclude: + # only test `-c dbg` build with C++17 + - cpp: {version: 14} + bazel: {compilation_mode: dbg} + - cpp: {version: 20} + bazel: {compilation_mode: dbg} + fail-fast: false + name: MacOS•Bazel(${{ matrix.bazel.compilation_mode }})•C++${{ matrix.cpp.version }}•Python${{ matrix.python.version }} + runs-on: macos-13 # last macos intel based runner + steps: + - uses: actions/checkout@v4 + - name: Set Java to OpenJDK 17 (Temurin) + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python.version }} + - name: Check Python + run: | + python --version + python -m platform + - name: Check Bazel + run: bazel version + - name: Change Python in MODULE.bazel + run: | + sed -i '' -e 's/\(DEFAULT_PYTHON =\) "3.[0-9]*"/\1 "${{ matrix.python.version }}"/g' MODULE.bazel + cat MODULE.bazel + - name: Build + run: > + bazel build + -c ${{ matrix.bazel.compilation_mode }} + --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --subcommands=pretty_print + --enable_bzlmod + //... + - name: Test + run: > + bazel test + -c ${{ matrix.bazel.compilation_mode }} + --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --subcommands=pretty_print + --enable_bzlmod + //... + + amd64_macos_bazel: + runs-on: ubuntu-latest + needs: native + steps: + - uses: actions/checkout@v4 diff --git a/.github/workflows/amd64_macos_cmake.yml b/.github/workflows/amd64_macos_cmake.yml new file mode 100644 index 0000000..59b25b8 --- /dev/null +++ b/.github/workflows/amd64_macos_cmake.yml @@ -0,0 +1,71 @@ +# ref: https://github.com/actions/runner-images +name: amd64 MacOS CMake + +on: [push, pull_request, workflow_dispatch] + +# Building using the github runner environement directly. +jobs: + native: + strategy: + matrix: + python: [ + {version: '3.9'}, + {version: '3.10'}, + {version: '3.11'}, + {version: '3.12'}, + #{version: '3.13'}, + ] + cmake: [ + {generator: "Xcode", config: Release, build_target: ALL_BUILD, test_target: RUN_TESTS, install_target: install}, + {generator: "Unix Makefiles", config: Release, build_target: all, test_target: test, install_target: install}, + ] + fail-fast: false + name: MacOS•CMake(${{ matrix.cmake.generator }})•Python${{ matrix.python.version }} + runs-on: macos-13 # last macos intel based runner + steps: + - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python.version }} + - name: Update Path + run: | + echo "$HOME/Library/Python/${{ matrix.python.version }}/bin" >> $GITHUB_PATH + echo "$HOME/.local/bin" >> $GITHUB_PATH + - name: Check Python + run: python --version + - name: Install Python requirements + run: python -m pip install --upgrade -r $(python -c 'import sys; print("./pybind11_protobuf/requirements/requirements_lock_%d_%d.txt" % (sys.version_info[:2]))') + - name: Check CMake + run: cmake --version + - name: Configure + run: > + cmake -S. -Bbuild + -G "${{ matrix.cmake.generator }}" + -DCMAKE_BUILD_TYPE=${{ matrix.cmake.config }} + -DCMAKE_INSTALL_PREFIX=install + - name: Build + run: > + cmake --build build + --config ${{ matrix.cmake.config }} + --target ${{ matrix.cmake.build_target }} + -v -j2 + - name: Test + run: > + CTEST_OUTPUT_ON_FAILURE=1 + cmake --build build + --config ${{ matrix.cmake.config }} + --target ${{ matrix.cmake.test_target }} + -v + - name: Install + run: > + cmake --build build + --config ${{ matrix.cmake.config }} + --target ${{ matrix.cmake.install_target }} + -v + + amd64_macos_cmake: + runs-on: ubuntu-latest + needs: native + steps: + - uses: actions/checkout@v4 diff --git a/.github/workflows/amd64_windows_bazel.yml b/.github/workflows/amd64_windows_bazel.yml new file mode 100644 index 0000000..3648eda --- /dev/null +++ b/.github/workflows/amd64_windows_bazel.yml @@ -0,0 +1,76 @@ +# ref: https://github.com/actions/runner-images +name: amd64 Windows Bazel + +on: [push, pull_request, workflow_dispatch] + +# Building using the github runner environement directly. +jobs: + native: + strategy: + matrix: + runner: [ + windows-2022, + #windows-2019, + ] + bazel: [ + {compilation_mode: opt}, + {compilation_mode: dbg}, + ] + cpp: [ + #{version: 14, flags: "/std:c++14"}, + {version: 17, flags: "/std:c++17"}, + #{version: 20, flags: "/std:c++20"}, + ] + python: [ + #{version: '3.11'}, + {version: '3.12'}, + ] + exclude: + - runner: windows-2019 + cpp: {version: 20} + # only test -c dbg with VS 2022 version 17 to save compute time + - runner: windows-2019 + bazel: {compilation_mode: dbg} + - cpp: {version: 14} + bazel: {compilation_mode: dbg} + - cpp: {version: 20} + bazel: {compilation_mode: dbg} + fail-fast: false # Don't cancel all jobs if one fails. + name: ${{ matrix.runner }}•Bazel(${{ matrix.bazel.compilation_mode }})•C++${{ matrix.cpp.version }}•Python${{ matrix.python.version }} + runs-on: ${{ matrix.runner }} + steps: + - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python.version }} + - name: Check Python + run: | + python --version + python -m platform + - name: Install Bazel + run: choco install bazel + - name: Check Bazel + run: bazel version + - name: Build + run: > + bazel build + -c ${{ matrix.bazel.compilation_mode }} + --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --subcommands=pretty_print + --enable_bzlmod + //... + - name: Test + run: > + bazel test + -c ${{ matrix.bazel.compilation_mode }} + --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --subcommands=pretty_print + --enable_bzlmod + //... + + amd64_windows_bazel: + runs-on: ubuntu-latest + needs: native + steps: + - uses: actions/checkout@v4 diff --git a/.github/workflows/amd64_windows_cmake.yml b/.github/workflows/amd64_windows_cmake.yml new file mode 100644 index 0000000..8181750 --- /dev/null +++ b/.github/workflows/amd64_windows_cmake.yml @@ -0,0 +1,69 @@ +# ref: https://github.com/actions/runner-images +name: amd64 Windows CMake + +on: [push, pull_request, workflow_dispatch] + +# Building using the github runner environement directly. +jobs: + native: + strategy: + matrix: + python: [ + #{version: '3.11'}, + {version: '3.12'}, + #{version: '3.13'}, + ] + cmake: [ + {generator: "Visual Studio 17 2022", config: Release, build_target: ALL_BUILD, test_target: RUN_TESTS, install_target: INSTALL}, + ] + fail-fast: false + name: Windows•CMake(${{ matrix.cmake.generator }})•Python${{ matrix.python.version }} + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python.version }} + - name: Check Python + run: | + python --version + python -m platform + - name: Install Python requirements + run: python -m pip install --upgrade -r $(python -c 'import sys; print("./pybind11_protobuf/requirements/requirements_lock_%d_%d.txt" % (sys.version_info[:2]))') + - name: Check CMake + run: | + cmake --version + cmake -G || true + - name: Configure + run: > + cmake -S. -Bbuild + -G "${{ matrix.cmake.generator }}" + -DCMAKE_CONFIGURATION_TYPES=${{ matrix.cmake.config }} + -DCMAKE_INSTALL_PREFIX=install + - name: Build + run: > + cmake --build build + --config ${{ matrix.cmake.config }} + --target ${{ matrix.cmake.build_target }} + -v -j2 + - name: Test + shell: bash + run: > + CTEST_OUTPUT_ON_FAILURE=1 + cmake --build build + --config ${{ matrix.cmake.config }} + --target ${{ matrix.cmake.test_target }} + -v + - name: Install + run: > + cmake --build build + --config ${{ matrix.cmake.config }} + --target ${{ matrix.cmake.install_target }} + -v + + amd64_windows_cmake: + runs-on: ubuntu-latest + needs: native + steps: + - uses: actions/checkout@v4 diff --git a/.github/workflows/arm64_macos_bazel.yml b/.github/workflows/arm64_macos_bazel.yml new file mode 100644 index 0000000..5f40658 --- /dev/null +++ b/.github/workflows/arm64_macos_bazel.yml @@ -0,0 +1,75 @@ +# ref: https://github.com/actions/runner-images +name: arm64 MacOS Bazel + +on: [push, pull_request, workflow_dispatch] + +# Building using the github runner environement directly. +jobs: + native: + strategy: + matrix: + bazel: [ + {compilation_mode: opt}, + {compilation_mode: dbg}, + ] + cpp: [ + #{version: 14, flags: "-std=c++14"}, + {version: 17, flags: "-std=c++17"}, + #{version: 20, flags: "-std=c++20"}, + ] + python: [ + #{version: '3.11'}, + {version: '3.12'}, + ] + exclude: + # only test `-c dbg` build with C++17 + - cpp: {version: 14} + bazel: {compilation_mode: dbg} + - cpp: {version: 20} + bazel: {compilation_mode: dbg} + fail-fast: false + name: MacOS•Bazel(${{ matrix.bazel.compilation_mode }})•C++${{ matrix.cpp.version }}•Python${{ matrix.python.version }} + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Set Java to OpenJDK 17 (Temurin) + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python.version }} + - name: Check Python + run: | + python --version + python -m platform + - name: Check Bazel + run: bazel version + - name: Change Python in MODULE.bazel + run: | + sed -i '' -e 's/\(DEFAULT_PYTHON =\) "3.[0-9]*"/\1 "${{ matrix.python.version }}"/g' MODULE.bazel + cat MODULE.bazel + - name: Build + run: > + bazel build + -c ${{ matrix.bazel.compilation_mode }} + --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --subcommands=pretty_print + --enable_bzlmod + //... + - name: Test + run: > + bazel test + -c ${{ matrix.bazel.compilation_mode }} + --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --subcommands=pretty_print + --enable_bzlmod + //... + + arm64_macos_bazel: + runs-on: ubuntu-latest + needs: native + steps: + - uses: actions/checkout@v4 diff --git a/.github/workflows/arm64_macos_cmake.yml b/.github/workflows/arm64_macos_cmake.yml new file mode 100644 index 0000000..182c788 --- /dev/null +++ b/.github/workflows/arm64_macos_cmake.yml @@ -0,0 +1,71 @@ +# ref: https://github.com/actions/runner-images +name: arm64 MacOS CMake + +on: [push, pull_request, workflow_dispatch] + +# Building using the github runner environement directly. +jobs: + native: + strategy: + matrix: + python: [ + {version: '3.9'}, + {version: '3.10'}, + {version: '3.11'}, + {version: '3.12'}, + #{version: '3.13'}, + ] + cmake: [ + {generator: "Xcode", config: Release, build_target: ALL_BUILD, test_target: RUN_TESTS, install_target: install}, + {generator: "Unix Makefiles", config: Release, build_target: all, test_target: test, install_target: install}, + ] + fail-fast: false + name: MacOS•CMake(${{ matrix.cmake.generator }})•Python${{ matrix.python.version }} + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python.version }} + - name: Update Path + run: | + echo "$HOME/Library/Python/${{ matrix.python.version }}/bin" >> $GITHUB_PATH + echo "$HOME/.local/bin" >> $GITHUB_PATH + - name: Check Python + run: python --version + - name: Install Python requirements + run: python -m pip install --upgrade -r $(python -c 'import sys; print("./pybind11_protobuf/requirements/requirements_lock_%d_%d.txt" % (sys.version_info[:2]))') + - name: Check CMake + run: cmake --version + - name: Configure + run: > + cmake -S. -Bbuild + -G "${{ matrix.cmake.generator }}" + -DCMAKE_BUILD_TYPE=${{ matrix.cmake.config }} + -DCMAKE_INSTALL_PREFIX=install + - name: Build + run: > + cmake --build build + --config ${{ matrix.cmake.config }} + --target ${{ matrix.cmake.build_target }} + -v -j2 + - name: Test + run: > + CTEST_OUTPUT_ON_FAILURE=1 + cmake --build build + --config ${{ matrix.cmake.config }} + --target ${{ matrix.cmake.test_target }} + -v + - name: Install + run: > + cmake --build build + --config ${{ matrix.cmake.config }} + --target ${{ matrix.cmake.install_target }} + -v + + arm64_macos_cmake: + runs-on: ubuntu-latest + needs: native + steps: + - uses: actions/checkout@v4 diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index b02653e..f557024 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -11,8 +11,8 @@ jobs: pre-commit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 - uses: pre-commit/action@v3.0.0 with: # Slow hooks are marked with manual - slow is okay here, run them too diff --git a/.github/workflows/ubuntu-build.yml b/.github/workflows/ubuntu-build.yml index 5c2d8a5..fefc1b6 100644 --- a/.github/workflows/ubuntu-build.yml +++ b/.github/workflows/ubuntu-build.yml @@ -1,11 +1,7 @@ +# ref: https://github.com/actions/runner-images name: ubuntu-build -on: - workflow_dispatch: - pull_request: - push: - branches: - - main +on: [push, pull_request, workflow_dispatch] concurrency: group: ci-${{github.workflow}}-${{ github.ref }} @@ -13,47 +9,75 @@ concurrency: jobs: cmake: + name: cmake runs-on: ubuntu-22.04 steps: - name: Show env run: env - - - name: Checkout - uses: actions/checkout@v3 - + - uses: actions/checkout@v4 - name: Install Build Dependencies - shell: bash - run: | - sudo apt update && sudo apt install --no-install-recommends -y \ - cmake \ - make - + run: > + sudo apt update && + sudo apt install --no-install-recommends -y + cmake make - name: Show Python version and platform info run: | python --version python -m platform - - name: Show CMake version run: cmake --version - - name: CMake Configure - shell: bash - run: | - cmake -S . -B build -DCMAKE_VERBOSE_MAKEFILE=ON - + run: cmake -S. -Bbuild -DCMAKE_VERBOSE_MAKEFILE=ON - name: CMake Build - shell: bash - run: | - cmake --build build -j$(nproc) + run: cmake --build build -j$(nproc) - bazel: + bazel_inner: + strategy: + matrix: + options: [ + {version: 14, flags: "-std=c++14"}, + {version: 17, flags: "-std=c++17"}, + {version: 20, flags: "-std=c++20"}, + ] + fail-fast: false # Don't cancel all jobs if one fails. + name: bazel c++${{ matrix.options.version }} runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v5 + with: + python-version: 3.12 # Current default version in MODULE.bazel + - name: Show Python version and platform info + run: | + python --version + python -m platform - uses: bazel-contrib/setup-bazel@0.8.4 with: bazelisk-cache: true disk-cache: ${{ github.workflow }} repository-cache: true - - run: BAZEL_CXXOPTS="-std=c++17" bazel test //... - - run: BAZEL_CXXOPTS="-std=c++20" bazel test //... + - name: Show Bazel version + run: bazel --version + - name: Bazel Build + shell: bash + run: > + bazel build + --cxxopt=${{ matrix.options.flags }} --host_cxxopt=${{ matrix.options.flags }} + --subcommands=pretty_print + --enable_bzlmod + //... + - name: Bazel Test + shell: bash + run: > + bazel test + --cxxopt=${{ matrix.options.flags }} --host_cxxopt=${{ matrix.options.flags }} + --subcommands=pretty_print + --enable_bzlmod + //... + + bazel: + runs-on: ubuntu-latest + needs: bazel_inner + steps: + - uses: actions/checkout@v4 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9e731ea --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/bazel-* +/build +/tmp_build + +user.bazelrc +.*.swp diff --git a/CMakeLists.txt b/CMakeLists.txt index 2139dc0..0e722d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,14 @@ cmake_minimum_required(VERSION 3.18) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -project(pybind11_protobuf) - -if(MSVC) - set(CMAKE_CXX_STANDARD 20) -else() - set(CMAKE_CXX_STANDARD 17) +project(pybind11_protobuf LANGUAGES CXX) + +if(NOT DEFINED CMAKE_CXX_STANDARD) + if(MSVC) + set(CMAKE_CXX_STANDARD 20) + else() + set(CMAKE_CXX_STANDARD 17) + endif() endif() set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) @@ -23,151 +25,16 @@ option(USE_SYSTEM_PYBIND "Force usage of system provided pybind11" OFF) # ============================================================================ # Testing include(CTest) +option(PYBIND11_PROTOBUF_BUILD_TESTING "If ON, build all of pybind11_protobuf's own tests." ${BUILD_TESTING}) # ============================================================================ # Find Python - -find_package(Python COMPONENTS Interpreter Development) +find_package(Python3 REQUIRED COMPONENTS Interpreter Development.Module) # ============================================================================ # Build dependencies +add_subdirectory(cmake/dependencies dependencies) -if(USE_SYSTEM_ABSEIL) - # Version omitted, as absl only allows EXACT version matches - set(_absl_package_args REQUIRED) -else() - set(_absl_package_args 20230125) -endif() -if(USE_SYSTEM_PROTOBUF) - set(_protobuf_package_args 4.23.3 REQUIRED) -else() - set(_protobuf_package_args 4.23.3) -endif() -if(USE_SYSTEM_PYBIND) - set(_pybind11_package_args 2.11.1 REQUIRED) -else() - set(_pybind11_package_args 2.11.1) -endif() - -set(ABSL_PROPAGATE_CXX_STD ON) -set(ABSL_ENABLE_INSTALL ON) - -include(FetchContent) -FetchContent_Declare( - absl - GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git" - GIT_TAG 20230125.3 - FIND_PACKAGE_ARGS ${_absl_package_args} NAMES absl) - -# cmake-format: off -FetchContent_Declare( - Protobuf - GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git" - GIT_TAG v23.3 - GIT_SUBMODULES "" - FIND_PACKAGE_ARGS ${_protobuf_package_args} NAMES protobuf) -set(protobuf_BUILD_TESTS OFF CACHE INTERNAL "") -# cmake-format: on - -FetchContent_Declare( - pybind11 - GIT_REPOSITORY "https://github.com/pybind/pybind11.git" - GIT_TAG v2.11.1 - FIND_PACKAGE_ARGS ${_pybind11_package_args} NAMES pybind11) - -message(CHECK_START "Checking for external dependencies") -list(APPEND CMAKE_MESSAGE_INDENT " ") -FetchContent_MakeAvailable(absl Protobuf pybind11) -list(POP_BACK CMAKE_MESSAGE_INDENT) - -# ============================================================================ -# pybind11_proto_utils pybind11 extension module -pybind11_add_module( - pybind11_proto_utils MODULE pybind11_protobuf/proto_utils.cc - pybind11_protobuf/proto_utils.h) - -target_link_libraries( - pybind11_proto_utils PRIVATE absl::strings protobuf::libprotobuf - ${Python_LIBRARIES}) - -target_include_directories( - pybind11_proto_utils PRIVATE ${PROJECT_SOURCE_DIR} ${protobuf_INCLUDE_DIRS} - ${protobuf_SOURCE_DIR} ${pybind11_INCLUDE_DIRS}) - -# ============================================================================ -# pybind11_native_proto_caster shared library -add_library( - pybind11_native_proto_caster STATIC - # bazel: pybind_library: native_proto_caster - pybind11_protobuf/native_proto_caster.h - # bazel: pybind_library: enum_type_caster - pybind11_protobuf/enum_type_caster.h - # bazel: pybind_library: proto_cast_util - pybind11_protobuf/proto_cast_util.cc - pybind11_protobuf/proto_cast_util.h - pybind11_protobuf/proto_caster_impl.h) - -target_link_libraries( - pybind11_native_proto_caster - absl::flat_hash_map - absl::flat_hash_set - absl::hash - absl::strings - absl::optional - protobuf::libprotobuf - pybind11::pybind11 - ${Python_LIBRARIES}) - -target_include_directories( - pybind11_native_proto_caster - PRIVATE ${PROJECT_SOURCE_DIR} ${protobuf_INCLUDE_DIRS} ${protobuf_SOURCE_DIR} - ${pybind11_INCLUDE_DIRS}) - -# ============================================================================ -# pybind11_wrapped_proto_caster shared library -add_library( - pybind11_wrapped_proto_caster STATIC - # bazel: pybind_library: wrapped_proto_caster - pybind11_protobuf/wrapped_proto_caster.h - # bazel: pybind_library: proto_cast_util - pybind11_protobuf/proto_cast_util.cc - pybind11_protobuf/proto_cast_util.h - pybind11_protobuf/proto_caster_impl.h) - -target_link_libraries( - pybind11_wrapped_proto_caster - absl::flat_hash_map - absl::flat_hash_set - absl::hash - absl::strings - absl::optional - protobuf::libprotobuf - pybind11::pybind11 - ${Python_LIBRARIES}) - -target_include_directories( - pybind11_wrapped_proto_caster - PRIVATE ${PROJECT_SOURCE_DIR} ${protobuf_INCLUDE_DIRS} ${protobuf_SOURCE_DIR} - ${pybind11_INCLUDE_DIRS}) - -if(BUILD_TESTING) - add_subdirectory(pybind11_protobuf/tests) -endif() - -# bazel equivs. checklist -# -# bazel: pybind_library: enum_type_caster - enum_type_caster.h -# -# bazel: pybind_library: native_proto_caster - native_proto_caster.h -# -# check_unknown_fields enum_type_caster proto_cast_util -# -# bazel: pybind_library: proto_cast_util - proto_cast_util.cc - -# proto_cast_util.h - proto_caster_impl.h -# -# check_unknown_fields -# -# bazel: pybind_library: wrapped_proto_caster - wrapped_proto_caster.h -# -# proto_cast_util -# +set(TOP_LEVEL_DIR ${CMAKE_CURRENT_LIST_DIR}) +include_directories(${TOP_LEVEL_DIR} ${pybind11_INCLUDE_DIRS}) +add_subdirectory(pybind11_protobuf) diff --git a/MODULE.bazel b/MODULE.bazel index f0b1190..b87ee06 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -1,87 +1,54 @@ module( - name = "pybind11_protobuf", - version = "head", -) - -bazel_dep( - name = "bazel_skylib", - version = "1.5.0", -) - -bazel_dep( - name = "abseil-cpp", - version = "20230802.0.bcr.1", - repo_name = "com_google_absl", -) - -bazel_dep( - name = "abseil-py", - version = "2.1.0", - repo_name = "com_google_absl_py", -) - -bazel_dep( - name = "platforms", - version = "0.0.8" -) - -bazel_dep( - name = "pybind11_bazel", - version = "2.11.1.bzl.2", -) - -bazel_dep( - name = "protobuf", - version = "23.1", - repo_name = "com_google_protobuf" -) - -bazel_dep( - name = "grpc", - version = "1.56.3.bcr.1", - repo_name = "com_github_grpc_grpc", -) - -bazel_dep( - name = "rules_python", - version = "0.31.0", -) + name = "pybind11_protobuf", + version = "head", +) + +# Only direct dependencies need to be listed below. +# Please keep the versions in sync with the versions in the WORKSPACE file. +# see https://registry.bazel.build/ +bazel_dep(name = "bazel_skylib", version = "1.7.1") +bazel_dep(name = "abseil-cpp", version = "20240722.0.bcr.2", repo_name = "com_google_absl") +bazel_dep(name = "abseil-py", version = "2.1.0", repo_name = "com_google_absl_py") +bazel_dep(name = "platforms", version = "0.0.10") +bazel_dep(name = "rules_cc", version = "0.0.15") +bazel_dep(name = "rules_python", version = "0.40.0") +bazel_dep(name = "pybind11_bazel", version = "2.13.6") +bazel_dep(name = "pybind11_abseil", version = "202402.0") +bazel_dep(name = "protobuf", version = "29.2", repo_name = "com_google_protobuf") +bazel_dep(name = "grpc", version = "1.56.3.bcr.1", repo_name = "com_github_grpc_grpc") SUPPORTED_PYTHON_VERSIONS = [ - "3.12", - "3.11", - "3.10", - "3.9", - "3.8" + "3.12", + "3.11", + "3.10", + "3.9", ] -DEFAULT_PYTHON = "3.11" +DEFAULT_PYTHON = "3.12" python = use_extension("@rules_python//python/extensions:python.bzl", "python") + [ - python.toolchain( - python_version = version, - is_default = version == DEFAULT_PYTHON, - ) - for version in SUPPORTED_PYTHON_VERSIONS + python.toolchain( + is_default = version == DEFAULT_PYTHON, + python_version = version, + ) + for version in SUPPORTED_PYTHON_VERSIONS ] -use_repo( - python, - python = "python_versions", -) +use_repo(python, python = "python_versions") #### DEV ONLY DEPENDENCIES BELOW HERE #### -pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip", dev_dependency=True) -[ - pip.parse( - hub_name = "pypi", - python_version = version, - requirements_lock = "//pybind11_protobuf/requirements:requirements_lock_" + version.replace('.','_') + ".txt", - ) - for version in SUPPORTED_PYTHON_VERSIONS +pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip", dev_dependency = True) +[ + pip.parse( + hub_name = "pypi_protobuf", + python_version = version, + requirements_lock = "//pybind11_protobuf/requirements:requirements_lock_" + version.replace(".", "_") + ".txt", + ) + for version in SUPPORTED_PYTHON_VERSIONS ] -use_repo(pip, "pypi") +use_repo(pip, pypi = "pypi_protobuf") diff --git a/README.md b/README.md index b84b35b..c42b478 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,33 @@ # Pybind11 bindings for Google's Protocol Buffers +Github-CI: +| OS \ Build system | Bazel | CMake | +|:------- | :---: | :---: | +| Linux (`amd64`) | [![Build Status][amd64_linux_bazel_status]][amd64_linux_bazel_link] | [![Build Status][amd64_linux_cmake_status]][amd64_linux_cmake_link] | +| MacOS (`amd64`) | [![Build Status][amd64_macos_bazel_status]][amd64_macos_bazel_link] | [![Build Status][amd64_macos_cmake_status]][amd64_macos_cmake_link] | +| MacOS (`arm64`) | [![Build Status][arm64_macos_bazel_status]][arm64_macos_bazel_link] | [![Build Status][arm64_macos_cmake_status]][arm64_macos_cmake_link] | +| Windows (`amd64`) | [![Build Status][amd64_windows_bazel_status]][amd64_windows_bazel_link] | [![Build Status][amd64_windows_cmake_status]][amd64_windows_cmake_link] | + +[amd64_linux_bazel_status]: ./../../actions/workflows/amd64_linux_bazel.yml/badge.svg +[amd64_linux_bazel_link]: ./../../actions/workflows/amd64_linux_bazel.yml +[amd64_macos_bazel_status]: ./../../actions/workflows/amd64_macos_bazel.yml/badge.svg +[amd64_macos_bazel_link]: ./../../actions/workflows/amd64_macos_bazel.yml +[arm64_macos_bazel_status]: ./../../actions/workflows/arm64_macos_bazel.yml/badge.svg +[arm64_macos_bazel_link]: ./../../actions/workflows/arm64_macos_bazel.yml +[amd64_windows_bazel_status]: ./../../actions/workflows/amd64_windows_bazel.yml/badge.svg +[amd64_windows_bazel_link]: ./../../actions/workflows/amd64_windows_bazel.yml + +[amd64_linux_cmake_status]: ./../../actions/workflows/amd64_linux_cmake.yml/badge.svg +[amd64_linux_cmake_link]: ./../../actions/workflows/amd64_linux_cmake.yml +[amd64_macos_cmake_status]: ./../../actions/workflows/amd64_macos_cmake.yml/badge.svg +[amd64_macos_cmake_link]: ./../../actions/workflows/amd64_macos_cmake.yml +[arm64_macos_cmake_status]: ./../../actions/workflows/arm64_macos_cmake.yml/badge.svg +[arm64_macos_cmake_link]: ./../../actions/workflows/arm64_macos_cmake.yml +[amd64_windows_cmake_status]: ./../../actions/workflows/amd64_windows_cmake.yml/badge.svg +[amd64_windows_cmake_link]: ./../../actions/workflows/amd64_windows_cmake.yml + +[![ubuntu-build](./../../actions/workflows/ubuntu-build.yml/badge.svg)](./../../actions/workflows/ubuntu-build.yml) + [TOC] ## Overview diff --git a/WORKSPACE b/WORKSPACE index 3d5d7ce..d4a925b 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -1,26 +1,41 @@ -workspace(name = "com_google_pybind11_protobuf") - +workspace(name = "pybind11_protobuf") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") - -http_archive( +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository") + +################################################################################ +# +# WORKSPACE is being deprecated in favor of the new Bzlmod dependency system. +# It will be removed at some point in the future. +# +################################################################################ + +## `bazel_skylib` +# Needed for Abseil. +git_repository( name = "bazel_skylib", - urls = [ - "https://github.com/bazelbuild/bazel-skylib/releases/download/1.5.0/bazel-skylib-1.5.0.tar.gz" - ], - sha256 = "cd55a062e763b9349921f0f5db8c3933288dc8ba4f76dd9416aac68acee3cb94", + commit = "27d429d8d036af3d010be837cc5924de1ca8d163", + #tag = "1.7.1", + remote = "https://github.com/bazelbuild/bazel-skylib.git", ) - load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") - bazel_skylib_workspace() -http_archive( +## Bazel rules... +git_repository( + name = "platforms", + commit = "05ec3a3df23fde62471f8288e344cc021dd87bab", + #tag = "0.0.10", + remote = "https://github.com/bazelbuild/platforms.git", +) + +## abseil-cpp +# https://github.com/abseil/abseil-cpp +## Abseil-cpp +git_repository( name = "com_google_absl", - sha256 = "59d2976af9d6ecf001a81a35749a6e551a335b949d34918cfade07737b9d93c5", # SHARED_ABSL_SHA - strip_prefix = "abseil-cpp-20230802.0", - urls = [ - "https://github.com/abseil/abseil-cpp/archive/refs/tags/20230802.0.tar.gz" - ], + commit = "4447c7562e3bc702ade25105912dce503f0c4010", + #tag = "20240722.0", + remote = "https://github.com/abseil/abseil-cpp.git", ) http_archive( @@ -32,17 +47,18 @@ http_archive( ], ) -http_archive( +git_repository( name = "rules_python", - sha256 = "c68bdc4fbec25de5b5493b8819cfc877c4ea299c0dcb15c244c5a00208cde311", - strip_prefix = "rules_python-0.31.0", - url = "https://github.com/bazelbuild/rules_python/releases/download/0.31.0/rules_python-0.31.0.tar.gz", + commit = "1944874f6ba507f70d8c5e70df84622e0c783254", + #tag = "0.40.0", + remote = "https://github.com/bazelbuild/rules_python.git", ) load("@rules_python//python:repositories.bzl", "py_repositories", "python_register_multi_toolchains") - py_repositories() +load("@rules_python//python/pip_install:repositories.bzl", "pip_install_dependencies") +pip_install_dependencies() DEFAULT_PYTHON = "3.11" @@ -58,7 +74,6 @@ python_register_multi_toolchains( ], ) - load("@python//:pip.bzl", "multi_pip_parse") multi_pip_parse( @@ -81,47 +96,47 @@ multi_pip_parse( ) load("@pypi//:requirements.bzl", "install_deps") - install_deps() -## `pybind11_bazel` (PINNED) +## `pybind11_bazel` # https://github.com/pybind/pybind11_bazel -http_archive( - name = "pybind11_bazel", - strip_prefix = "pybind11_bazel-2.11.1.bzl.2", - sha256 = "e2ba5f81f3bf6a3fc0417448d49389cc7950bebe48c42c33dfeb4dd59859b9a4", - urls = ["https://github.com/pybind/pybind11_bazel/releases/download/v2.11.1.bzl.2/pybind11_bazel-2.11.1.bzl.2.tar.gz"], +git_repository( + name = "pybind11_bazel", + commit = "2b6082a4d9d163a52299718113fa41e4b7978db5", + #tag = "v2.13.6", # 2024/10/21 + remote = "https://github.com/pybind/pybind11_bazel.git", ) -## `pybind11` (FLOATING) -http_archive( - name = "pybind11", - build_file = "@pybind11_bazel//:pybind11.BUILD", - strip_prefix = "pybind11-master", - urls = ["https://github.com/pybind/pybind11/archive/refs/heads/master.tar.gz"], +## `pybind11` +# https://github.com/pybind/pybind11 +new_git_repository( + name = "pybind11", + build_file = "@pybind11_bazel//:pybind11-BUILD.bazel", + commit = "a2e59f0e7065404b44dfe92a28aca47ba1378dc4", + #tag = "v2.13.6", + remote = "https://github.com/pybind/pybind11.git", ) # proto_library, cc_proto_library, and java_proto_library rules implicitly # depend on @com_google_protobuf for protoc and proto runtimes. -# This statement defines the @com_google_protobuf repo. -http_archive( +git_repository( name = "com_google_protobuf", - sha256 = "d19643d265b978383352b3143f04c0641eea75a75235c111cc01a1350173180e", - strip_prefix = "protobuf-25.3", - urls = ["https://github.com/protocolbuffers/protobuf/releases/download/v25.3/protobuf-25.3.tar.gz"], + commit = "233098326bc268fc03b28725c941519fc77703e6", + #tag = "v29.2", + remote = "https://github.com/protocolbuffers/protobuf.git", ) load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") protobuf_deps() -# GRPC v1.42, for proto rules. +# GRPC, for proto rules. # For a related discussion of the pro/cons of various open-source py proto rule # repositories, see b/189457935. -http_archive( +git_repository( name = "com_github_grpc_grpc", - sha256 = "84e31a77017911b2f1647ecadb0172671d96049ea9ad5109f02b4717c0f03702", - strip_prefix = "grpc-1.56.3", - urls = ["https://github.com/grpc/grpc/archive/refs/tags/v1.56.3.tar.gz"], + commit = "d3286610f703a339149c3f9be69f0d7d0abb130a", + #tag = "v1.67.1", + remote = "https://github.com/grpc/grpc.git", ) load("@com_github_grpc_grpc//bazel:grpc_deps.bzl", "grpc_deps") diff --git a/cmake/dependencies/CMakeLists.txt b/cmake/dependencies/CMakeLists.txt new file mode 100644 index 0000000..b2fc115 --- /dev/null +++ b/cmake/dependencies/CMakeLists.txt @@ -0,0 +1,82 @@ +include(FetchContent) +set(BUILD_SHARED_LIBS ON) +set(BUILD_TESTING OFF) + +message(CHECK_START "Checking for external dependencies") +list(APPEND CMAKE_MESSAGE_INDENT " ") + +if(NOT TARGET absl::base) + if(USE_SYSTEM_ABSEIL) + # Version omitted, as absl only allows EXACT version matches + find_package(absl REQUIRED) + else() + message(CHECK_START "Fetching Abseil-cpp") + list(APPEND CMAKE_MESSAGE_INDENT " ") + # ensure that abseil also installs itself, since we are using it in our public + # API + set(ABSL_ENABLE_INSTALL ON) + set(ABSL_PROPAGATE_CXX_STD ON) + set(ABSL_USE_SYSTEM_INCLUDES ON) + set(ABSL_BUILD_TESTING OFF) + FetchContent_Declare( + absl + GIT_REPOSITORY "https://github.com/abseil/abseil-cpp.git" + GIT_TAG "20240722.0" + GIT_SHALLOW TRUE) + FetchContent_MakeAvailable(absl) + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "fetched") + endif() +endif() + +if(NOT TARGET protobuf::libprotobuf) + if(USE_SYSTEM_PROTOBUF) + find_package(protobuf 5.29.2 REQUIRED) + else() + message(CHECK_START "Fetching Protobuf") + list(APPEND CMAKE_MESSAGE_INDENT " ") + set(protobuf_BUILD_TESTS OFF) + FetchContent_Declare( + Protobuf + GIT_REPOSITORY "https://github.com/protocolbuffers/protobuf.git" + GIT_TAG "v29.2" + GIT_SHALLOW TRUE) + FetchContent_MakeAvailable(Protobuf) + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "fetched") + endif() +endif() + +if(NOT TARGET pybind11::pybind11_headers) + if(USE_SYSTEM_PYBIND) + find_package(pybind11 2.13.6 REQUIRED) + else() + message(CHECK_START "Fetching pybind11") + list(APPEND CMAKE_MESSAGE_INDENT " ") + FetchContent_Declare( + pybind11 + GIT_REPOSITORY "https://github.com/pybind/pybind11.git" + GIT_TAG "v2.13.6" + GIT_SHALLOW TRUE) + FetchContent_MakeAvailable(pybind11) + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "fetched") + endif() +endif() + +if(PYBIND11_PROTOBUF_BUILD_TESTING AND NOT TARGET pybind11_abseil::absl_casters) + message(CHECK_START "Fetching pybind11_abseil") + list(APPEND CMAKE_MESSAGE_INDENT " ") + FetchContent_Declare( + pybind11_abseil + # TODO: replace by pybind/pybind_abseil once merged upstream + GIT_REPOSITORY "https://github.com/mizux/pybind11_abseil.git" + GIT_TAG "master" + GIT_SHALLOW TRUE) + FetchContent_MakeAvailable(pybind11_abseil) + list(POP_BACK CMAKE_MESSAGE_INDENT) + message(CHECK_PASS "fetched") +endif() + +list(POP_BACK CMAKE_MESSAGE_INDENT) +message(CHECK_PASS "all dependencies found") diff --git a/pybind11_protobuf/BUILD b/pybind11_protobuf/BUILD index 2b7d851..d9abcaa 100644 --- a/pybind11_protobuf/BUILD +++ b/pybind11_protobuf/BUILD @@ -73,6 +73,7 @@ cc_library( "@com_google_absl//absl/container:flat_hash_set", "@com_google_absl//absl/strings", "@com_google_absl//absl/synchronization", + "@com_google_absl//absl/types:optional", "@com_google_protobuf//:protobuf", "@com_google_protobuf//python:proto_api", ], diff --git a/pybind11_protobuf/CMakeLists.txt b/pybind11_protobuf/CMakeLists.txt new file mode 100644 index 0000000..7a9cdc1 --- /dev/null +++ b/pybind11_protobuf/CMakeLists.txt @@ -0,0 +1,89 @@ +# ============================================================================ +# pybind11_proto_utils pybind11 extension module +pybind11_add_module(pybind11_proto_utils MODULE proto_utils.cc proto_utils.h) +add_library(pybind11_protobuf::pybind11_proto_utils ALIAS pybind11_proto_utils) + +# note: macOS is APPLE and also UNIX ! +if(APPLE) + set_target_properties(pybind11_proto_utils PROPERTIES SUFFIX ".so") +endif() + +target_include_directories(pybind11_proto_utils + INTERFACE $) + +target_link_libraries(pybind11_proto_utils PUBLIC absl::strings + protobuf::libprotobuf) + +# ============================================================================ +# pybind11_native_proto_caster shared library +add_library( + pybind11_native_proto_caster STATIC + # bazel: pybind_library: native_proto_caster + native_proto_caster.h + # bazel: pybind_library: enum_type_caster + enum_type_caster.h + # bazel: pybind_library: proto_cast_util + proto_cast_util.cc + proto_cast_util.h + proto_caster_impl.h) +add_library(pybind11_protobuf::pybind11_native_proto_caster ALIAS + pybind11_native_proto_caster) + +target_link_libraries( + pybind11_native_proto_caster + PUBLIC absl::flat_hash_map + absl::flat_hash_set + absl::hash + absl::strings + absl::optional + protobuf::libprotobuf + pybind11::pybind11) + +target_include_directories(pybind11_native_proto_caster + PUBLIC $) + +# ============================================================================ +# pybind11_wrapped_proto_caster shared library +add_library( + pybind11_wrapped_proto_caster STATIC + # bazel: pybind_library: wrapped_proto_caster + wrapped_proto_caster.h + # bazel: pybind_library: proto_cast_util + proto_cast_util.cc proto_cast_util.h proto_caster_impl.h) +add_library(pybind11_protobuf::pybind11_wrapped_proto_caster ALIAS + pybind11_wrapped_proto_caster) + +target_link_libraries( + pybind11_wrapped_proto_caster + PUBLIC absl::flat_hash_map + absl::flat_hash_set + absl::hash + absl::strings + absl::optional + protobuf::libprotobuf + pybind11::pybind11) + +target_include_directories(pybind11_wrapped_proto_caster + PUBLIC $) + +if(BUILD_TESTING) + add_subdirectory(tests) +endif() + +if(CMAKE_INSTALL_PYDIR) + # Copying to two target directories for simplicity. It is currently unknown + # how to determine here which copy is actually being used. + install( + TARGETS status_py_extension_stub ok_status_singleton + EXPORT pybind11_abseilTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_PYDIR}/pybind11_abseil + ARCHIVE DESTINATION ${CMAKE_INSTALL_PYDIR}/pybind11_abseil + RUNTIME DESTINATION ${CMAKE_INSTALL_PYDIR}/pybind11_abseil) + + install( + TARGETS status_py_extension_stub ok_status_singleton + EXPORT pybind11_abseil_cppTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}) +endif() diff --git a/pybind11_protobuf/check_unknown_fields.cc b/pybind11_protobuf/check_unknown_fields.cc index 0e1e9ea..dca0e25 100644 --- a/pybind11_protobuf/check_unknown_fields.cc +++ b/pybind11_protobuf/check_unknown_fields.cc @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -12,6 +11,7 @@ #include "absl/strings/str_join.h" #include "absl/strings/string_view.h" #include "absl/synchronization/mutex.h" +#include "absl/types/optional.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/message.h" #include "google/protobuf/unknown_field_set.h" @@ -181,17 +181,17 @@ void AllowUnknownFieldsFor(absl::string_view top_message_descriptor_full_name, unknown_field_parent_message_fqn)); } -std::optional CheckRecursively( +absl::optional CheckRecursively( const ::google::protobuf::python::PyProto_API* py_proto_api, const ::google::protobuf::Message* message) { const auto* root_descriptor = message->GetDescriptor(); HasUnknownFields search{py_proto_api, root_descriptor}; if (!search.FindUnknownFieldsRecursive(message, 0u)) { - return std::nullopt; + return absl::nullopt; } if (GetAllowList()->count(MakeAllowListKey(root_descriptor->full_name(), search.FieldFQN())) != 0) { - return std::nullopt; + return absl::nullopt; } return search.BuildErrorMessage(); } diff --git a/pybind11_protobuf/check_unknown_fields.h b/pybind11_protobuf/check_unknown_fields.h index a448f83..26ea7ab 100644 --- a/pybind11_protobuf/check_unknown_fields.h +++ b/pybind11_protobuf/check_unknown_fields.h @@ -1,10 +1,10 @@ #ifndef PYBIND11_PROTOBUF_CHECK_UNKNOWN_FIELDS_H_ #define PYBIND11_PROTOBUF_CHECK_UNKNOWN_FIELDS_H_ -#include #include #include "absl/strings/string_view.h" +#include "absl/types/optional.h" #include "google/protobuf/message.h" #include "python/google/protobuf/proto_api.h" @@ -46,7 +46,7 @@ class ExtensionsWithUnknownFieldsPolicy { void AllowUnknownFieldsFor(absl::string_view top_message_descriptor_full_name, absl::string_view unknown_field_parent_message_fqn); -std::optional CheckRecursively( +absl::optional CheckRecursively( const ::google::protobuf::python::PyProto_API* py_proto_api, const ::google::protobuf::Message* top_message); diff --git a/pybind11_protobuf/proto_cast_util.cc b/pybind11_protobuf/proto_cast_util.cc index a098bcb..5ca857b 100644 --- a/pybind11_protobuf/proto_cast_util.cc +++ b/pybind11_protobuf/proto_cast_util.cc @@ -59,8 +59,13 @@ namespace { // Resolves the class name of a descriptor via d->containing_type() py::object ResolveDescriptor(py::object p, const Descriptor* d) { return d->containing_type() ? ResolveDescriptor(p, d->containing_type()) +#if __cplusplus >= 201703L .attr(py::str(std::string_view(d->name()))) : p.attr(py::str(std::string_view(d->name()))); +#else + .attr(py::str(std::string(d->name()))) + : p.attr(py::str(std::string(d->name()))); +#endif } // Returns true if an exception is an import error. diff --git a/pybind11_protobuf/requirements/requirements.in b/pybind11_protobuf/requirements/requirements.in index b998a06..8aca509 100644 --- a/pybind11_protobuf/requirements/requirements.in +++ b/pybind11_protobuf/requirements/requirements.in @@ -1 +1,2 @@ -absl-py +absl-py==2.1.0 +protobuf==5.29.2 diff --git a/pybind11_protobuf/requirements/requirements_lock_3_10.txt b/pybind11_protobuf/requirements/requirements_lock_3_10.txt index 840bb56..2d50e93 100644 --- a/pybind11_protobuf/requirements/requirements_lock_3_10.txt +++ b/pybind11_protobuf/requirements/requirements_lock_3_10.txt @@ -8,3 +8,16 @@ absl-py==2.1.0 \ --hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \ --hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff # via -r pybind11_protobuf/requirements/requirements.in +protobuf==5.29.2 \ + --hash=sha256:13d6d617a2a9e0e82a88113d7191a1baa1e42c2cc6f5f1398d3b054c8e7e714a \ + --hash=sha256:2d2e674c58a06311c8e99e74be43e7f3a8d1e2b2fdf845eaa347fbd866f23355 \ + --hash=sha256:36000f97ea1e76e8398a3f02936aac2a5d2b111aae9920ec1b769fc4a222c4d9 \ + --hash=sha256:494229ecd8c9009dd71eda5fd57528395d1eacdf307dbece6c12ad0dd09e912e \ + --hash=sha256:842de6d9241134a973aab719ab42b008a18a90f9f07f06ba480df268f86432f9 \ + --hash=sha256:a0c53d78383c851bfa97eb42e3703aefdc96d2036a41482ffd55dc5f529466eb \ + --hash=sha256:b2cc8e8bb7c9326996f0e160137b0861f1a82162502658df2951209d0cb0309e \ + --hash=sha256:b6b0d416bbbb9d4fbf9d0561dbfc4e324fd522f61f7af0fe0f282ab67b22477e \ + --hash=sha256:c12ba8249f5624300cf51c3d0bfe5be71a60c63e4dcf51ffe9a68771d958c851 \ + --hash=sha256:e621a98c0201a7c8afe89d9646859859be97cb22b8bf1d8eacfd90d5bda2eb19 \ + --hash=sha256:fde4554c0e578a5a0bcc9a276339594848d1e89f9ea47b4427c80e5d72f90181 + # via -r pybind11_protobuf/requirements/requirements.in diff --git a/pybind11_protobuf/requirements/requirements_lock_3_11.txt b/pybind11_protobuf/requirements/requirements_lock_3_11.txt index 5362764..311c88b 100644 --- a/pybind11_protobuf/requirements/requirements_lock_3_11.txt +++ b/pybind11_protobuf/requirements/requirements_lock_3_11.txt @@ -8,3 +8,16 @@ absl-py==2.1.0 \ --hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \ --hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff # via -r pybind11_protobuf/requirements/requirements.in +protobuf==5.29.2 \ + --hash=sha256:13d6d617a2a9e0e82a88113d7191a1baa1e42c2cc6f5f1398d3b054c8e7e714a \ + --hash=sha256:2d2e674c58a06311c8e99e74be43e7f3a8d1e2b2fdf845eaa347fbd866f23355 \ + --hash=sha256:36000f97ea1e76e8398a3f02936aac2a5d2b111aae9920ec1b769fc4a222c4d9 \ + --hash=sha256:494229ecd8c9009dd71eda5fd57528395d1eacdf307dbece6c12ad0dd09e912e \ + --hash=sha256:842de6d9241134a973aab719ab42b008a18a90f9f07f06ba480df268f86432f9 \ + --hash=sha256:a0c53d78383c851bfa97eb42e3703aefdc96d2036a41482ffd55dc5f529466eb \ + --hash=sha256:b2cc8e8bb7c9326996f0e160137b0861f1a82162502658df2951209d0cb0309e \ + --hash=sha256:b6b0d416bbbb9d4fbf9d0561dbfc4e324fd522f61f7af0fe0f282ab67b22477e \ + --hash=sha256:c12ba8249f5624300cf51c3d0bfe5be71a60c63e4dcf51ffe9a68771d958c851 \ + --hash=sha256:e621a98c0201a7c8afe89d9646859859be97cb22b8bf1d8eacfd90d5bda2eb19 \ + --hash=sha256:fde4554c0e578a5a0bcc9a276339594848d1e89f9ea47b4427c80e5d72f90181 + # via -r pybind11_protobuf/requirements/requirements.in diff --git a/pybind11_protobuf/requirements/requirements_lock_3_12.txt b/pybind11_protobuf/requirements/requirements_lock_3_12.txt index 91fa147..5a9b83f 100644 --- a/pybind11_protobuf/requirements/requirements_lock_3_12.txt +++ b/pybind11_protobuf/requirements/requirements_lock_3_12.txt @@ -8,3 +8,16 @@ absl-py==2.1.0 \ --hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \ --hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff # via -r pybind11_protobuf/requirements/requirements.in +protobuf==5.29.2 \ + --hash=sha256:13d6d617a2a9e0e82a88113d7191a1baa1e42c2cc6f5f1398d3b054c8e7e714a \ + --hash=sha256:2d2e674c58a06311c8e99e74be43e7f3a8d1e2b2fdf845eaa347fbd866f23355 \ + --hash=sha256:36000f97ea1e76e8398a3f02936aac2a5d2b111aae9920ec1b769fc4a222c4d9 \ + --hash=sha256:494229ecd8c9009dd71eda5fd57528395d1eacdf307dbece6c12ad0dd09e912e \ + --hash=sha256:842de6d9241134a973aab719ab42b008a18a90f9f07f06ba480df268f86432f9 \ + --hash=sha256:a0c53d78383c851bfa97eb42e3703aefdc96d2036a41482ffd55dc5f529466eb \ + --hash=sha256:b2cc8e8bb7c9326996f0e160137b0861f1a82162502658df2951209d0cb0309e \ + --hash=sha256:b6b0d416bbbb9d4fbf9d0561dbfc4e324fd522f61f7af0fe0f282ab67b22477e \ + --hash=sha256:c12ba8249f5624300cf51c3d0bfe5be71a60c63e4dcf51ffe9a68771d958c851 \ + --hash=sha256:e621a98c0201a7c8afe89d9646859859be97cb22b8bf1d8eacfd90d5bda2eb19 \ + --hash=sha256:fde4554c0e578a5a0bcc9a276339594848d1e89f9ea47b4427c80e5d72f90181 + # via -r pybind11_protobuf/requirements/requirements.in diff --git a/pybind11_protobuf/requirements/requirements_lock_3_8.txt b/pybind11_protobuf/requirements/requirements_lock_3_8.txt index 9e16dab..2b8fbed 100644 --- a/pybind11_protobuf/requirements/requirements_lock_3_8.txt +++ b/pybind11_protobuf/requirements/requirements_lock_3_8.txt @@ -8,3 +8,16 @@ absl-py==2.1.0 \ --hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \ --hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff # via -r pybind11_protobuf/requirements/requirements.in +protobuf==5.29.2 \ + --hash=sha256:13d6d617a2a9e0e82a88113d7191a1baa1e42c2cc6f5f1398d3b054c8e7e714a \ + --hash=sha256:2d2e674c58a06311c8e99e74be43e7f3a8d1e2b2fdf845eaa347fbd866f23355 \ + --hash=sha256:36000f97ea1e76e8398a3f02936aac2a5d2b111aae9920ec1b769fc4a222c4d9 \ + --hash=sha256:494229ecd8c9009dd71eda5fd57528395d1eacdf307dbece6c12ad0dd09e912e \ + --hash=sha256:842de6d9241134a973aab719ab42b008a18a90f9f07f06ba480df268f86432f9 \ + --hash=sha256:a0c53d78383c851bfa97eb42e3703aefdc96d2036a41482ffd55dc5f529466eb \ + --hash=sha256:b2cc8e8bb7c9326996f0e160137b0861f1a82162502658df2951209d0cb0309e \ + --hash=sha256:b6b0d416bbbb9d4fbf9d0561dbfc4e324fd522f61f7af0fe0f282ab67b22477e \ + --hash=sha256:c12ba8249f5624300cf51c3d0bfe5be71a60c63e4dcf51ffe9a68771d958c851 \ + --hash=sha256:e621a98c0201a7c8afe89d9646859859be97cb22b8bf1d8eacfd90d5bda2eb19 \ + --hash=sha256:fde4554c0e578a5a0bcc9a276339594848d1e89f9ea47b4427c80e5d72f90181 + # via -r pybind11_protobuf/requirements/requirements.in diff --git a/pybind11_protobuf/requirements/requirements_lock_3_9.txt b/pybind11_protobuf/requirements/requirements_lock_3_9.txt index 14e60c3..eaed7c2 100644 --- a/pybind11_protobuf/requirements/requirements_lock_3_9.txt +++ b/pybind11_protobuf/requirements/requirements_lock_3_9.txt @@ -8,3 +8,16 @@ absl-py==2.1.0 \ --hash=sha256:526a04eadab8b4ee719ce68f204172ead1027549089702d99b9059f129ff1308 \ --hash=sha256:7820790efbb316739cde8b4e19357243fc3608a152024288513dd968d7d959ff # via -r pybind11_protobuf/requirements/requirements.in +protobuf==5.29.2 \ + --hash=sha256:13d6d617a2a9e0e82a88113d7191a1baa1e42c2cc6f5f1398d3b054c8e7e714a \ + --hash=sha256:2d2e674c58a06311c8e99e74be43e7f3a8d1e2b2fdf845eaa347fbd866f23355 \ + --hash=sha256:36000f97ea1e76e8398a3f02936aac2a5d2b111aae9920ec1b769fc4a222c4d9 \ + --hash=sha256:494229ecd8c9009dd71eda5fd57528395d1eacdf307dbece6c12ad0dd09e912e \ + --hash=sha256:842de6d9241134a973aab719ab42b008a18a90f9f07f06ba480df268f86432f9 \ + --hash=sha256:a0c53d78383c851bfa97eb42e3703aefdc96d2036a41482ffd55dc5f529466eb \ + --hash=sha256:b2cc8e8bb7c9326996f0e160137b0861f1a82162502658df2951209d0cb0309e \ + --hash=sha256:b6b0d416bbbb9d4fbf9d0561dbfc4e324fd522f61f7af0fe0f282ab67b22477e \ + --hash=sha256:c12ba8249f5624300cf51c3d0bfe5be71a60c63e4dcf51ffe9a68771d958c851 \ + --hash=sha256:e621a98c0201a7c8afe89d9646859859be97cb22b8bf1d8eacfd90d5bda2eb19 \ + --hash=sha256:fde4554c0e578a5a0bcc9a276339594848d1e89f9ea47b4427c80e5d72f90181 + # via -r pybind11_protobuf/requirements/requirements.in diff --git a/pybind11_protobuf/tests/BUILD b/pybind11_protobuf/tests/BUILD index 0fff68a..ee4e658 100644 --- a/pybind11_protobuf/tests/BUILD +++ b/pybind11_protobuf/tests/BUILD @@ -231,7 +231,10 @@ pybind_extension( deps = [ ":test_cc_proto", "//pybind11_protobuf:native_proto_caster", + "@com_google_absl//absl/types:optional", + "@com_google_absl//absl/types:variant", "@com_google_protobuf//:protobuf", + "@pybind11_abseil//pybind11_abseil:absl_casters", ], ) @@ -299,6 +302,7 @@ pybind_extension( "//pybind11_protobuf:native_proto_caster", "@com_google_absl//absl/strings", "@com_google_absl//absl/time", + "@pybind11_abseil//pybind11_abseil:absl_casters", ], ) diff --git a/pybind11_protobuf/tests/CMakeLists.txt b/pybind11_protobuf/tests/CMakeLists.txt index 75060a2..d5591e5 100644 --- a/pybind11_protobuf/tests/CMakeLists.txt +++ b/pybind11_protobuf/tests/CMakeLists.txt @@ -65,14 +65,24 @@ generate_extension( "extension_in_other_file_in_deps_cc_proto;extension_nest_repeated_cc_proto;test_cc_proto;extension_cc_proto;pybind11_native_proto_caster" ) generate_extension(message "test_cc_proto;pybind11_native_proto_caster") -generate_extension(pass_by "test_cc_proto;pybind11_native_proto_caster") +generate_extension(pass_by + "test_cc_proto;pybind11_native_proto_caster;pybind11_abseil::absl_casters") generate_extension(pass_proto2_message "pybind11_native_proto_caster") generate_extension(wrapped_proto "test_cc_proto;pybind11_wrapped_proto_caster") -generate_extension(thread "test_cc_proto;pybind11_native_proto_caster") +generate_extension(thread + "test_cc_proto;pybind11_native_proto_caster;pybind11_abseil::absl_casters") generate_extension(regression_wrappers "pybind11_native_proto_caster") generate_extension(we_love_dashes_cc_only # "we-love-dashes_cc_proto;pybind11_native_proto_caster") +if(NOT DEFINED Python_EXECUTABLE) + if(NOT DEFINED PYBIND11_PYTHON_EXECUTABLE_LAST) + set(Python_EXECUTABLE ${PYTHON_EXECUTABLE}) + else() + set(Python_EXECUTABLE ${PYBIND11_PYTHON_EXECUTABLE_LAST}) + endif() +endif() + function(add_py_test testname) add_test(NAME ${testname}_test COMMAND ${Python_EXECUTABLE} diff --git a/pybind11_protobuf/tests/pass_by_module.cc b/pybind11_protobuf/tests/pass_by_module.cc index 498c0cc..f9a720a 100644 --- a/pybind11_protobuf/tests/pass_by_module.cc +++ b/pybind11_protobuf/tests/pass_by_module.cc @@ -9,18 +9,32 @@ #include #include #include -#include -#include +#include "absl/types/optional.h" +#include "absl/types/variant.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/dynamic_message.h" #include "google/protobuf/message.h" +#include "pybind11_abseil/absl_casters.h" #include "pybind11_protobuf/native_proto_caster.h" #include "pybind11_protobuf/tests/test.pb.h" namespace py = ::pybind11; +// To remove once cl/715754684 is submitted +namespace pybind11 { +namespace detail { +#ifndef ABSL_HAVE_STD_VARIANT +template <> +struct type_caster + : void_caster {}; +#endif + +} // namespace detail +} // namespace pybind11 + + namespace { using ::pybind11::test::IntMessage; @@ -158,9 +172,9 @@ PYBIND11_MODULE(pass_by_module, m) { m.def( "std_variant", - [](std::variant message, int value) { - if (auto* msg = std::get_if(&message)) { - return CheckIntMessage(msg, value); + [](absl::variant message, int value) { + if (absl::holds_alternative(message)) { + return CheckIntMessage(&absl::get(message), value); } return false; }, @@ -168,7 +182,7 @@ PYBIND11_MODULE(pass_by_module, m) { m.def( "std_optional", - [](std::optional message, int value) { + [](absl::optional message, int value) { if (message.has_value()) { return CheckIntMessage(&message.value(), value); } diff --git a/pybind11_protobuf/tests/thread_module.cc b/pybind11_protobuf/tests/thread_module.cc index acc089a..478b8b3 100644 --- a/pybind11_protobuf/tests/thread_module.cc +++ b/pybind11_protobuf/tests/thread_module.cc @@ -12,6 +12,7 @@ #include "absl/strings/string_view.h" #include "absl/time/clock.h" #include "absl/time/time.h" +#include "pybind11_abseil/absl_casters.h" #include "pybind11_protobuf/native_proto_caster.h" #include "pybind11_protobuf/tests/test.pb.h" diff --git a/pybind11_protobuf/wrapped_proto_caster.h b/pybind11_protobuf/wrapped_proto_caster.h index 68a6f92..15f4bb2 100644 --- a/pybind11_protobuf/wrapped_proto_caster.h +++ b/pybind11_protobuf/wrapped_proto_caster.h @@ -277,7 +277,7 @@ struct wrapped_proto_vector_caster { pybind11::return_value_policy policy, pybind11::handle parent) { pybind11::list l(src.protos.size()); - ssize_t index = 0; + Py_ssize_t index = 0; for (auto&& value : src.protos) { auto value_ = pybind11::reinterpret_steal( pybind11_protobuf::native_cast_impl::cast_impl(