Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Upgrade to protobuf 27.0 and remove py_proto_library #1933

Merged
merged 20 commits into from
Jun 5, 2024

Conversation

comius
Copy link
Contributor

@comius comius commented May 31, 2024

Protobuf team is taking ownership of py_proto_library and the implementation was moved to protobuf repository.

Remove py_proto_library from rules_python, to prevent divergent implementations.

Make a redirect with a deprecation warning, so that this doesn't break any users.

Expected side effect of this change is also that the protobuf version is sufficiently updated that there is no more use of legacy struct providers.

Closes #1935
Closes #1924
Closes #1925
Closes #1703
Closes #1707
Closes #1597
Closes #1293
Closes #1080
Fixes #1438

@comius comius marked this pull request as ready for review May 31, 2024 14:20
@comius comius requested a review from rickeylev as a code owner May 31, 2024 14:20
Copy link
Contributor

@rickeylev rickeylev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add an entry to CHANGELOG.md to note that the rules_python proto rules are deprecated and will be removed in a future release.

CI has a failure when compiling protos. My guess would be the those builds don't have the additional compiler flags that were added. But, this would imply that all users also have to add those flags? That doesn't seem feasible. Can protobuf add those compile flags instead itself?

load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_python//python:proto.bzl", "py_proto_library")
load("@com_google_protobuf//bazel:proto_library.bzl", "proto_library")
load("@com_google_protobuf//bazel:py_proto_library.bzl", "py_proto_library")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The python rules are in the protobuf repo directly, not in a python-specific repo? I thought I remember seeing a BCR PR where they were adding various proto_{java,python,etc} repos so e.g. java wasn't pulled in when only python was used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The python rules are in the protobuf repo directly, not in a python-specific repo?
Yes.

BCR PR where they were adding various proto_{java,python,etc} repos

Hm, do you mean rules_proto_grpc_*? I imagine those support gRPC, but I wasn't part of that effort.

@@ -35,9 +34,6 @@ def rules_python_internal_setup():

bazel_skylib_workspace()

rules_proto_dependencies()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For workspace builds, shouldn't there be some sort of proto-setup call still? Did I miss where it is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a protobuf_deps call just after. We only need to setup protobuf, now that the rules are moving there.

@aignas
Copy link
Collaborator

aignas commented Jun 2, 2024

I've referenced a lot of issues that have to do with proto library rule, feel free to disagree and alter the list if some of them are out of place.

@comius
Copy link
Contributor Author

comius commented Jun 3, 2024

Please also add an entry to CHANGELOG.md to note that the rules_python proto rules are deprecated and will be removed in a future release.

Done.

CI has a failure when compiling protos. My guess would be the those builds don't have the additional compiler flags that were added. But, this would imply that all users also have to add those flags? That doesn't seem feasible. Can protobuf add those compile flags instead itself?

I see 3 possible options:

  • adding the flags
  • fixing the code so that there are no problems
  • using precompiled binaries

The last option is something that will be done in protobuf. It was done previously in rules_proto, but in an awkward and unmaintained way.

@aignas
Copy link
Collaborator

aignas commented Jun 4, 2024

@comius, when are you going to work on using the precompiled binaries? I wonder if we should merge this PR after that part is fixed.

@comius
Copy link
Contributor Author

comius commented Jun 5, 2024

@comius, when are you going to work on using the precompiled binaries? I wonder if we should merge this PR after that part is fixed.

I hope we don't have to wait, because this PR also removes dependency on extra old protobuf that uses legacy struct providers. I'd like to disable that support in Bazel and that would then break rules_python.

Old py_proto_library is getting precompiled protoc from a really old version of rules_proto, which was never properly maintained.

@aignas aignas added this pull request to the merge queue Jun 5, 2024
Merged via the queue into bazelbuild:main with commit d0e25cf Jun 5, 2024
4 checks passed
@alexeagle
Copy link
Collaborator

Note that due to protocolbuffers/protobuf#17075 this caused a regression - the latest rules_python release has a py_proto_library that can be used with a prebuilt toolchain to avoid compiling protoc, but the one in protocolbuffers/protobuf does not. Thus users with a non-functional cc toolchain will be stuck on the last rules_python release.

aignas added a commit to aignas/rules_python that referenced this pull request Jun 11, 2024
…ild#1933)

This reverts commit d0e25cf.

We have the following concerns with the associated change:

- `sphinxdocs` is excluded entirely. Because protobuf fails to compile?
  But why? Protos are needed as part of our docgen, but it is unclear
  how the docgen is still working. Maybe we can get some clarification
  here?
- The `py_proto_library` tests in the `bzlmod` example are excluded from
  CI. Because protos also fail to compile? But why? It's an example and
  should Just Work.
- Adding the `copts` needs to be done by all downstream users now. But
  fixing that in protobuf blocks removing legacy struct providers? I
  don't understand the connection.

Also @alexeagle noted extra
[regression](bazelbuild#1933 (comment))
being caused by the associated PR.

Reverting in order to unblock a new release of `rules_python` and then
we can work together with @comius on reverting the revert.
@rickeylev
Copy link
Contributor

@comius FYI we're going to revert this PR for now.

The main reason is what @alexeagle is reporting -- that users will be stuck on a release without a way to upgrade. Breaking changes are OK, but have to allow a graceful upgrade path; see https://rules-python.readthedocs.io/en/latest/contributing.html#breaking-changes

From the issue Alex filed, it sounds like part of the problem here is sequencing of releases? That this PR to be released after something else in proto-something is available?

That said, there are several other changes in this PR I have questions about:

  • It looks like building of doc-related protos was disabled in CI, with a comment saying protobuf compilation fails? Our docgen relies on protos, though.
  • The py_proto_library bzlmod example was also disabled -- this is partially a test that it works under bzlmod. If its broken, then something seems very wrong.
  • You said fixing the need to add the copt flags would block removing legacy struct providers? I don't see the connection.

github-merge-queue bot pushed a commit that referenced this pull request Jun 11, 2024
…1948)

This reverts commit d0e25cf.

We have the following concerns with the associated change:

- `sphinxdocs` is excluded entirely. Because protobuf fails to compile?
  But why? Protos are needed as part of our docgen, but it is unclear
  how the docgen is still working. Maybe we can get some clarification
  here?
- The `py_proto_library` tests in the `bzlmod` example are excluded from
  CI. Because protos also fail to compile? But why? It's an example and
  should Just Work.
- Adding the `copts` needs to be done by all downstream users now. But
  fixing that in protobuf blocks removing legacy struct providers? I
  don't understand the connection.

Also @alexeagle noted extra

[regression](#1933 (comment))
being caused by the associated PR.

Reverting in order to unblock a new release of `rules_python` and then
we can work together with @comius on reverting the revert.

Reverts #1933
@comius
Copy link
Contributor Author

comius commented Jun 11, 2024

@comius FYI we're going to revert this PR for now.

The main reason is what @alexeagle is reporting -- that users will be stuck on a release without a way to upgrade. Breaking changes are OK, but have to allow a graceful upgrade path; see https://rules-python.readthedocs.io/en/latest/contributing.html#breaking-changes

From the issue Alex filed, it sounds like part of the problem here is sequencing of releases? That this PR to be released after something else in proto-something is available?

That said, there are several other changes in this PR I have questions about:

  • It looks like building of doc-related protos was disabled in CI, with a comment saying protobuf compilation fails? Our docgen relies on protos, though.

It was disabled only on some platforms with GCC. Not on all of them.

  • The py_proto_library bzlmod example was also disabled -- this is partially a test that it works under bzlmod. If its broken, then something seems very wrong.

Same here.

  • You said fixing the need to add the copt flags would block removing legacy struct providers? I don't see the connection.

Try running rules_python build with --incompatible_disallow_struct_provider_syntax and the connection will become clear. Struct providers are used in an extra old protoc, that's coming from rules_proto.

@alexeagle
Copy link
Collaborator

I'll try to clarify:
I've been working on the rollout of Ivo's "toolchainization" of proto tools (the protoc and any language-specific plugins. We have to work through a large number of hard-coded @com_google_protobuf//:protoc references (to a cc_binary) which are listed here bazelbuild/rules_proto#213

We announced that Python is working, but the fork of py_proto_library to the protobuf repo occurred at an earlier commit and lost the fix. My fix for that has just landed: protocolbuffers/protobuf#17078

With my devrel hat on, I'd like to see that fix released by protobuf before rules_python drops the rule so this feature doesn't temporarily regress - it's hard to explain to users "yeah it was fixed, but then it was unfixed, and you're on this one release of rules_python in that range, sorry footgun..."

@rickeylev
Copy link
Contributor

Thanks @alexeagle, @comius

So if I understand correctly, we just have to wait for the next protobuf release, and then can re-merge this change?

Will the protobuf fix also address having to add the copt flag and the various CI config changes that were necessary?

Is that it, or should something also be done in the meantime? (opt-in env var? bump rules_proto or protobuf version past 21 but before 27? idk).

@alexeagle
Copy link
Collaborator

aspect-build/toolchains_protoc#13 demonstrates the breakage caused by the PR, for users who don't have cc toolchain.

just have to wait for the next protobuf release, and then can re-merge this change

Yes, next protobuf release fixes the py_proto_library rule so I that's what I would prefer. I know @comius is now blocked on some other changes downstream of this one, so I wont object to a roll-forward as soon as you like.

having to add the copt flag and the various CI config changes

I don't have context on that, and don't care about their compiler options for building protoc from source since I don't do that. It seems like they break it as often as they fix it.

aignas added a commit that referenced this pull request Jun 12, 2024
Reintroduce the changes in #1933, which got reverted in
commit 8b0eaed (#1948).
@aignas
Copy link
Collaborator

aignas commented Jun 12, 2024

Created a new PR and added all of you as reviewers: #1951.

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