Skip to content

Commit

Permalink
make googleapis a Bzlmod module
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-french committed Sep 27, 2023
1 parent 4f5c742 commit 94b1def
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
22 changes: 22 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module(
name = "com_google_googleapis",
version = "0.0.1",
)

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,
csharp = True,
gapic = True,
go = True,
grpc = True,
java = True,
nodejs = True,
php = True,
python = True,
ruby = True,
)
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.
50 changes: 50 additions & 0 deletions extensions.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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

for t in module.tags.use_languages:
attrs = {
"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,
},
)

0 comments on commit 94b1def

Please sign in to comment.