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(bazel): make googleapis a Bzlmod module #855

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tyler-french
Copy link

@tyler-french tyler-french commented Sep 27, 2023

This PR adds the googleapis repo to the Bazel central registry as a Bazel Module.

@tyler-french tyler-french changed the title make googleapis a Bzlmod module feat(bazel): make googleapis a Bzlmod module Sep 27, 2023
@tyler-french tyler-french marked this pull request as ready for review November 7, 2023 15:26
@tyler-french
Copy link
Author

@fmeum Could you take a look? It's a bit difficult because this package doesn't have versioned releases

MODULE.bazel Outdated
@@ -0,0 +1,22 @@
module(
name = "com_google_googleapis",
version = "0.0.1",
Copy link

Choose a reason for hiding this comment

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

You can leave this at 0.0.0 and rely on the Publish to the BCR plugin to patch in the real version number when a tag is created. Well, if no tags are created we will need to release this manually, e.g. using Go pseudo-versions.

MODULE.bazel Show resolved Hide resolved
extensions.bzl Show resolved Hide resolved
@@ -0,0 +1,22 @@
module(
Copy link

Choose a reason for hiding this comment

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

We should enable a CI run with Bzlmod (only the default in the not yet released Bazel 7).

Copy link
Author

Choose a reason for hiding this comment

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

I am not sure CI is running in this repo. I will try to set up a BCR presubmit also.

@silicon-ninja
Copy link

Hey everyone,

I'm interested in helping with the transition of googleapis to bzlmod support. While reviewing the dependency graph, I noticed a key decision point: should we opt for pure bzlmod support, or consider a partial approach using use_repo?

Adopting a purely bzlmod-based approach means that all gapic dependencies would also need to support bzlmod. This, in turn, hinges on grpc being a bzlmod project. However, it appears that grpc requires a substantial patch file to support bzlmod, which could complicate matters.

What are the team's thoughts on this? Are there any plans already in place for tackling these dependencies?

@alexander-fenster
Copy link
Member

Hi @tyler-french, @fmeum, and @silicon-ninja,

Thank you for your suggestions! We indeed cannot immediately switch to bzlmod: gRPC dependency makes it somewhat complicated, but that's not the only issue. For now, we will keep using Bazel 6 (via Bazelisk) and WORKSPACE for some more time, while we think internally how we can switch. We definitely should figure out how to switch soon because of Bazel's plans to deprecate / remove WORKSPACE support.

Please note that we are unable to merge pull requests here, because all Bazel configuration (and protos) in this repository is auto-synced from the internal code storage. I will leave this PR open for discussions, but the code change will come from the regular sync process, so this PR will not get merged.

Thank you!

@arnehormann
Copy link

Hi @alexander-fenster, isn't it still possible to support both in a soft migration?
See https://bazel.build/external/migration#workspace.bzlmod - a WORKSPACE.bzlmod file that makes Bazel with bzlmod ignore the WORKSPACE file while Bazel without bzlmod will ignore WORKSPACE.bzlmod and MODULE.bazel

@SanjayVas
Copy link

SanjayVas commented Dec 14, 2023

See bazelbuild/bazel-central-registry#1113

Note that the migration of core ecosystem infrastructure such as this blocks downstream migration. I appreciate in this case that it's in fact upstream dependencies that may be blocking this one, e.g. protobuf and grpc.

My project just uses googleapis for proto definitions in the google.type and google.api packages, so I was able to patch in just enough support in my own Bazel registry.

@SanjayVas
Copy link

Perhaps the global common component types should be split out from googleapis.

@alexander-fenster
Copy link
Member

@SanjayVas We actually have https://github.com/googleapis/api-common-protos for this specific purpose, I'll see if we can actually update that one first and see if it helps.

In general, folks, please give us some time and we'll figure this out - I just want to set some expectations that it likely won't happen until the new year. There are a lot of moving parts involved (much more than I would like to have :) ), but we are on it.

@SanjayVas
Copy link

@SanjayVas We actually have https://github.com/googleapis/api-common-protos for this specific purpose, I'll see if we can actually update that one first and see if it helps.

I am aware, but that often lags way behind the main googleapis repo. It's not automatically kept up-to-date. I imagine that's why the AIPs point to googleapis as the canonical location and why lots of core Bazel infra (e.g. rules_go) depends on it.

@ah-edg
Copy link

ah-edg commented Mar 4, 2024

@SanjayVas We actually have https://github.com/googleapis/api-common-protos for this specific purpose, I'll see if we can actually update that one first and see if it helps.

In general, folks, please give us some time and we'll figure this out - I just want to set some expectations that it likely won't happen until the new year. There are a lot of moving parts involved (much more than I would like to have :) ), but we are on it.

Hi @alexander-fenster, I hope it's okay to ping you after 2.5 months.
As it's the new year now, I'd love to get an update if you could please provide one. Even if it's just a rough plan. This issue (here and in grpc / grpc-java) blocks migrations to Bazel 7 and locks us into legacy software and into some maintenance heavy workarounds. I'd really love to get rid of them without additional manual patches.

@@ -0,0 +1,16 @@
module(
name = "com_google_googleapis",
Copy link

Choose a reason for hiding this comment

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

Suggested change
name = "com_google_googleapis",
name = "googleapis",

this is what most modules are doing, folks can use the fully qualified name if they need to

Copy link

@keith keith left a comment

Choose a reason for hiding this comment

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

t doesn't have a name, so I assume you meant module here


for t in module.tags.use_languages:
if is_tag_set:
fail("Multiple use_language tags are set in the root module: '{}' and '{}'. Only one is allowed.".format(set_tag_name, t.name))
Copy link

Choose a reason for hiding this comment

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

Suggested change
fail("Multiple use_language tags are set in the root module: '{}' and '{}'. Only one is allowed.".format(set_tag_name, t.name))
fail("Multiple use_language tags are set in the root module: '{}' and '{}'. Only one is allowed.".format(set_tag_name, module.name))

fail("Multiple use_language tags are set in the root module: '{}' and '{}'. Only one is allowed.".format(set_tag_name, t.name))

is_tag_set = True
set_tag_name = t.name
Copy link

Choose a reason for hiding this comment

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

Suggested change
set_tag_name = t.name
set_tag_name = module.name

cc = True,
go = True,
java = True,
python = True,
Copy link

Choose a reason for hiding this comment

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

Suggested change
python = True,
python = True,
grpc = True,

It looks to me if you add this some other deps are missing

Copy link

Choose a reason for hiding this comment

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

@SeeYaaG
Copy link

SeeYaaG commented Mar 26, 2024 via email

@keith
Copy link

keith commented Mar 27, 2024

i stacked some commits on this over here #892

mbland added a commit to EngFlow/example that referenced this pull request Apr 13, 2024
This appears to be a fairly recent development, and isn't yet 100%
officially supported in the googleapis/googleapis repo, but it works:

- googleapis/googleapis#855
- bazelbuild/bazel-central-registry#1699
mbland added a commit to EngFlow/example that referenced this pull request Apr 15, 2024
* Enable bzlmod, update README, fix Swift build

Rather than mess with the WORKSPACE rules, the shortest path to fixing
`blaze build //swift:tests` appeared to be introducing MODULE.bazel.

MODULE.bazel, a.k.a. bzlmod, appears to be the new hotness, so I'll also
try updating the other builds to use it as well.

- https://bazel.build/external/migration
- https://bazel.build/external/overview#workspace-shortcomings
- bazelbuild/bazel#18958

* Convert `bazel build //python/...` to MODULE.bazel

* Convert `bazel build //csharp/...` to MODULE.bazel

* Convert //go/..., gazelle to MODULE.bazel

* Migrate protobuf, rules_proto to MODULE.bazel

Also bumps to:

- protobuf: 23.1
- rules_proto: 6.0.0-rc2

* Add rules_java, rules_jvm_external to MODULE.bazel

rules_java was an implicit dependency before.

Bumps:

- rules_java: 7.4.0 => 7.5.0.
- rules_jvm_external: 4.4.2 => 6.0

The rules_jvm_external docs describe using `maven.install` in
MODULE.bazel as a replacement for `maven_install` in WORKSPACE:

- https://github.com/bazelbuild/rules_jvm_external/blob/master/docs/bzlmod.md

However, our current `maven_install` depends on the definition of
IO_GRPC_GRPC_JAVA_ARTIFACTS from @io_grpc_grpc_java. I'll attempt that
migration next.

* MODULE.bazel: skylib, rules_proto_grpc, protobuf

`bazel build //java/...` and `bazel test //java/...` both work with
these changes.

* Move grpc-java to MODULE.bazel, bump to 1.62.2

grpc-java only got MODULE.bazel support as of this most recent version:

- grpc/grpc-java#11046
- bazelbuild/bazel-central-registry#1699

This grpc-java version bump exposed two issues that are fixed in this
commit:

1. The //java/com/engflow/notificationqueue:client target dependency on
   @maven//:io_netty_netty_handler broke.

   The original WORKSPACE import of io_grpc_grpc_java imported this
   dependency directly by passing IO_GRPC_GRPC_JAVA_ARTIFACTS directly
   to `maven_install`. The `maven.install` call from grpc/grpc-java's
   MODULE.bazel sets `strict_visibility = True`. Somehow the other
   dependencies registered by grpc-java's MODULE.bazel
   are accessible to notificationqueue:client, but netty-handler isn't.

   The solution was to add the `io.netty:netty-handler:4.1.100.Final`
   artifact to the `maven.install` call in this project's MODULE.bazel.
   It doesn't seem an optimal solution, but it works for now.

2. grpc/grpc-java removed `io.grpc.stub.MetadataUtils.attachHeaders()`
   in grpc/grpc-java#10443.

   This caused notificationqueue:client to fail to compile, but that PR
   revealed the replacement for the deprecated `attachHeaders` call.
   This commit applies that replacement.

* Move googleapis to MODULE.bazel

This appears to be a fairly recent development, and isn't yet 100%
officially supported in the googleapis/googleapis repo, but it works:

- googleapis/googleapis#855
- bazelbuild/bazel-central-registry#1699

* Move rules_kotlin to MODULE.bazel, bump to v1.9.5

* Move rules_perl to MODULE.bazel, bump to 0.2.0

There's actually a 0.2.1 release, but it hasn't been pushed to
https://registry.bazel.build/ yet.

* Add rules_scala GitHub issue links

rules_scala hasn't migrated to bzlmod yet, but discussion is underway.
These links will help track its progress.

* Migrate aspect_rules_ts to MODULE.bazel

* Replace deps.bzl with go_deps

This enables `bazel {build,test} //infra/...` to succeed using
MODULE.bazel. See:

- https://github.com/bazelbuild/rules_go/blob/master/docs/go/core/bzlmod.md#specifying-external-dependencies

* Set test sizes to "small" as appropriate

This eliminates warnings that these tests are sized too big, since the
default is "medium".

* Move http_{file,archive} calls to MODULE.bazel

This moves the following http_file calls:

- emacs
- ubuntu_20.04_1.3GB

and the following http_archive calls:

- com_engflow_engflowapis
- io_abseil_py

* Update //platform rules, remove dotnet constraints

The //dotnet/toolchain constraint was causing a Bazel error saying that
the @@rules_dotnet//dontent/toolchain package didn't exist. Removing
this constraint allowed remote execution to succeed anyway.

* Update README, explain swift incompatibility

Most of these changes are cosmetic, with the notable exception of the
explantion behind the inability to build //swift remotely.

Also added a `git` command to ignore python/requirements_lock.txt per:

- https://stackoverflow.com/a/73720550
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
10 participants