Skip to content

Commit

Permalink
Improve use_languages extension tag
Browse files Browse the repository at this point in the history
This obeys requested bindings from any module.
  • Loading branch information
mering committed Dec 17, 2024
1 parent 08b05bb commit 5bda46c
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 1 deletion.
28 changes: 28 additions & 0 deletions modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module(
name = "googleapis",
version = "0.0.0-20240819-fe8ba054a.bcr.1",
repo_name = "com_google_googleapis",
)

bazel_dep(name = "grpc", version = "1.66.0.bcr.2", repo_name = "com_github_grpc_grpc")
bazel_dep(name = "grpc-java", version = "1.66.0", repo_name = "io_grpc_grpc_java")
bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_go", version = "0.46.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
bazel_dep(name = "rules_python", version = "0.31.0")

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,
dev_dependency = True,
)
use_repo(switched_rules, "com_google_googleapis_imports")
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
diff --git a/MODULE.bazel b/MODULE.bazel
new file mode 100644
index 000000000..7456c0cc5
--- /dev/null
+++ b/MODULE.bazel
@@ -0,0 +1,28 @@
+module(
+ name = "googleapis",
+ version = "0.0.0-20240819-fe8ba054a.bcr.1",
+ repo_name = "com_google_googleapis",
+)
+
+bazel_dep(name = "grpc", version = "1.66.0.bcr.2", repo_name = "com_github_grpc_grpc")
+bazel_dep(name = "grpc-java", version = "1.66.0", repo_name = "io_grpc_grpc_java")
+bazel_dep(name = "protobuf", version = "21.7", repo_name = "com_google_protobuf")
+bazel_dep(name = "rules_go", version = "0.46.0", repo_name = "io_bazel_rules_go")
+bazel_dep(name = "rules_proto", version = "5.3.0-21.7")
+bazel_dep(name = "rules_python", version = "0.31.0")
+
+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,
+ dev_dependency = True,
+)
+use_repo(switched_rules, "com_google_googleapis_imports")
diff --git a/extensions.bzl b/extensions.bzl
new file mode 100644
index 000000000..fbf3936cb
--- /dev/null
+++ b/extensions.bzl
@@ -0,0 +1,48 @@
+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),
+ "dev_dependency": attr.bool(default = False),
+ },
+)
+
+def _switched_rules_impl(ctx):
+ attrs = {}
+ for module in ctx.modules:
+ for t in module.tags.use_languages:
+ if t.dev_dependency and not module.is_root:
+ continue
+ attrs["cc"] = attrs.get("cc", False) or t.cc
+ attrs["csharp"] = attrs.get("csharp", False) or t.csharp
+ attrs["gapic"] = attrs.get("gapic", False) or t.gapic
+ attrs["go"] = attrs.get("go", False) or t.go
+ attrs["go_test"] = attrs.get("go_test", False) or t.go_test
+ attrs["grpc"] = attrs.get("grpc", False) or t.grpc
+ attrs["java"] = attrs.get("java", False) or t.java
+ attrs["nodejs"] = attrs.get("nodejs", False) or t.nodejs
+ attrs["php"] = attrs.get("php", False) or t.php
+ attrs["python"] = attrs.get("python", False) or t.python
+ attrs["ruby"] = attrs.get("ruby", False) or 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,
+ },
+)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
matrix:
platform: ["debian10", "macos", "ubuntu2004", "windows"]
bazel: ["7.x", "8.x"]
tasks:
verify_targets:
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
- '@googleapis//google/devtools/source/v1:source_proto'
9 changes: 9 additions & 0 deletions modules/googleapis/0.0.0-20240819-fe8ba054a.bcr.1/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"integrity": "sha256-BRPw9Ar2O9Bdx4nKzDNKts7CfMidtZZVfLLf6JGUY+Q=",
"strip_prefix": "googleapis-fe8ba054ad4f7eca946c2d14a63c3f07c0b586a0",
"url": "https://github.com/googleapis/googleapis/archive/fe8ba054ad4f7eca946c2d14a63c3f07c0b586a0.tar.gz",
"patch_strip": 1,
"patches": {
"add_module_bazel.patch": "sha256-F5aJnkwjhnlSqq5CBiRMucjAGkNXzf2R59F2hbupLrQ="
}
}
3 changes: 2 additions & 1 deletion modules/googleapis/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
],
"versions": [
"0.0.0-20240326-1c8d509c5",
"0.0.0-20240819-fe8ba054a"
"0.0.0-20240819-fe8ba054a",
"0.0.0-20240819-fe8ba054a.bcr.1"
],
"yanked_versions": {}
}

0 comments on commit 5bda46c

Please sign in to comment.