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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions .kokoro/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ CACHE_CMDLINE="--remote_cache=https://storage.googleapis.com/${CACHE_BUCKET} --g
#
# Run build and tests
#
echo "Building and Testing using WORKSPACE dependencies"
${BAZELISK_BIN} --output_user_root=${BAZEL_ROOT} build ${CACHE_CMDLINE} --keep_going //...
${BAZELISK_BIN} --output_user_root=${BAZEL_ROOT} test ${CACHE_CMDLINE} --flaky_test_attempts=3 --keep_going //...

# Restart the Bazel server to prevent sandbox issues.
echo "Building and Testing using Bzlmod dependencies"
${BAZELISK_BIN} shutdown
${BAZELISK_BIN} --output_user_root=${BAZEL_ROOT} build ${CACHE_CMDLINE} --keep_going --enable_bzlmod //...
16 changes: 16 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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.

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

version = "0.0.0",
)

bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")

switched_rules = use_extension("//:extensions.bzl", "switched_rules")
switched_rules.use_languages(
cc = True,
tyler-french marked this conversation as resolved.
Show resolved Hide resolved
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.

)
use_repo(switched_rules, "com_google_googleapis_imports")
2 changes: 2 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# When Bzlmod is enabled, this file replaces the content of the original WORKSPACE
# and makes sure no WORKSPACE prefix or suffix are added when Bzlmod is enabled.
59 changes: 59 additions & 0 deletions extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
load(":repository_rules.bzl", "switched_rules_by_language")

_use_languages_tag = tag_class(
attrs = {
"cc": attr.bool(default = False),
"csharp": attr.bool(default = False),
"gapic": attr.bool(default = False),
"go": attr.bool(default = False),
"go_test": attr.bool(default = False),
"grpc": attr.bool(default = False),
"java": attr.bool(default = False),
"nodejs": attr.bool(default = False),
"php": attr.bool(default = False),
"python": attr.bool(default = False),
"ruby": attr.bool(default = False),
},
)

def _switched_rules_impl(ctx):
attrs = {}
for module in ctx.modules:
if not module.is_root:
continue

is_tag_set = False
set_tag_name = ""

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))


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


attrs = {
tyler-french marked this conversation as resolved.
Show resolved Hide resolved
"cc": t.cc,
"csharp": t.csharp,
"gapic": t.gapic,
"go": t.go,
"go_test": t.go_test,
"grpc": t.grpc,
"java": t.java,
"nodejs": t.nodejs,
"php": t.php,
"python": t.python,
"ruby": t.ruby,
}

switched_rules_by_language(
name = "com_google_googleapis_imports",
**attrs
)

switched_rules = module_extension(
implementation = _switched_rules_impl,
tag_classes = {
"use_languages": _use_languages_tag,
},
)