Skip to content

fix build against protobuf v34+#223

Open
r-burns wants to merge 1 commit into
pybind:mainfrom
r-burns:protobuf34
Open

fix build against protobuf v34+#223
r-burns wants to merge 1 commit into
pybind:mainfrom
r-burns:protobuf34

Conversation

@r-burns
Copy link
Copy Markdown

@r-burns r-burns commented May 21, 2026

Upstream protobuf changed StringViewArg from const std::string& to absl::string_view: protocolbuffers/protobuf@aeb5f2d

By using the same StringViewArg alias they use in their declarations, we can fix the build against protobuf v34+ without losing support for older versions.

We get new warnings, because this alias is deprecated, but I think that's better than bumping the required protobuf version unnecessarily. This approach can always be revisited if they fully drop StringViewArg in the future.

Tested against protobuf v32.1 and v34.1.

Upstream protobuf changed StringViewArg from const std::string& to absl::string_view:
protocolbuffers/protobuf@aeb5f2d

By using the same StringViewArg alias they use in their declarations, we can
fix the build against protobuf v34+ without losing support for older versions.

We get new warnings, because this alias is deprecated, but I think that's
better than bumping the required protobuf version unnecessarily. This approach
can always be revisited if they fully drop StringViewArg in the future.

Tested against protobuf v32.1 and v34.1.
@Mizux Mizux self-assigned this May 21, 2026
@Mizux Mizux added bug Something isn't working dependencies Pull requests that update a dependency file labels May 21, 2026
@Mizux
Copy link
Copy Markdown
Collaborator

Mizux commented May 21, 2026

missing include header to get the definition of StringViewArg

aka #include "google/protobuf/descriptor_database.h"
(which seems part of the public api since it is installed by dev package
e.g. https://pkgs.alpinelinux.org/contents?name=protobuf-dev&repo=main&branch=edge&arch=x86)

/home/runner/work/pybind11_protobuf/pybind11_protobuf/pybind11_protobuf/proto_cast_util.cc:364:9: error: ‘StringViewArg’ has not been declared
  364 |         StringViewArg filename
      |         ^~~~~~~~~~~~~

EDIT: seems more complicated since header is already included above...
https://github.com/r-burns/pybind11_protobuf/blob/ca65374f0e6caf8c4f2e34df8c9745103c8894d8/pybind11_protobuf/proto_cast_util.cc#L28

Please also note the using is protected: so you can't use DescriptorDatabase::StringViewArg outside...

@r-burns
Copy link
Copy Markdown
Author

r-burns commented May 22, 2026

Weird, builds OK on my setup, are you on a slightly different protobuf version than me? The header is included above as you noted so I don't think it's that.

Please also note the using is protected: so you can't use DescriptorDatabase::StringViewArg outside...

I think the public inheritance on DescriptorDatabase here is what makes the StringViewArg using still available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants