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

[DRAFT] googleapis & grpc #2507

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions modules/googleapis/0.0.0-20240326-1c8d509c5.bcr.1/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module(
name = "googleapis",
version = "0.0.0-20240326-1c8d509c5.bcr.1",
compatibility_level = 1,
repo_name = "com_google_googleapis",
)

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

injections = use_extension("//:injections.bzl", "injections")
use_repo(injections, "com_google_googleapis_imports")
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
"""Contains forwarding declarations to rules that should only ever be used by
`googleapis` itself (i.e. these rules come from dev-dependencies).

Do NOT directly load from this file. Always use `@com_google_googleapis_imports//:imports.bzl`
instead!
"""

load(
"@rules_gapic//:gapic.bzl",
_proto_library_with_info = "proto_library_with_info",
_moved_proto_library = "moved_proto_library",
)
load(
"@gapic_generator_java//rules_java_gapic:java_gapic.bzl",
_java_gapic_library = "java_gapic_library",
_java_gapic_test = "java_gapic_test",
)
load(
"@gapic_generator_java//rules_java_gapic:java_gapic_pkg.bzl",
_java_gapic_assembly_gradle_pkg = "java_gapic_assembly_gradle_pkg",
)
load(
"@gapic_generator_python//rules_python_gapic:py_gapic.bzl",
_py_gapic_library = "py_gapic_library",
)
load(
"@gapic_generator_python//rules_python_gapic:py_gapic_pkg.bzl",
_py_gapic_assembly_pkg = "py_gapic_assembly_pkg",
)
load(
"@com_googleapis_gapic_generator_go//rules_go_gapic:go_gapic.bzl",
_go_gapic_library = "go_gapic_library",
)
load(
"@com_googleapis_gapic_generator_go//rules_go_gapic:go_gapic_pkg.bzl",
_go_gapic_assembly_pkg = "go_gapic_assembly_pkg",
)
load(
"@gapic_generator_php//rules_php_gapic:php_gapic.bzl",
_php_proto_library = "php_proto_library",
_php_grpc_library = "php_grpc_library",
_php_gapic_library = "php_gapic_library",
)
load(
"@gapic_generator_php//rules_php_gapic:php_gapic_pkg.bzl",
_php_gapic_assembly_pkg = "php_gapic_assembly_pkg",
)
load(
"@gapic_generator_typescript//rules_typescript_gapic:typescript_gapic.bzl",
_typescript_gapic_library = "typescript_gapic_library",
)
load(
"@gapic_generator_typescript//rules_typescript_gapic:typescript_gapic_pkg.bzl",
_typescript_gapic_assembly_pkg = "typescript_gapic_assembly_pkg",
)
load(
"@gapic_generator_ruby//rules_ruby_gapic:ruby_gapic.bzl",
_ruby_proto_library = "ruby_proto_library",
_ruby_grpc_library = "ruby_grpc_library",
_ruby_ads_gapic_library = "ruby_ads_gapic_library",
_ruby_cloud_gapic_library = "ruby_cloud_gapic_library",
)
load(
"@gapic_generator_ruby//rules_ruby_gapic:ruby_gapic_pkg.bzl",
_ruby_gapic_assembly_pkg = "ruby_gapic_assembly_pkg",
)
load(
"@rules_gapic//csharp:csharp_gapic.bzl",
_csharp_proto_library = "csharp_proto_library",
_csharp_grpc_library = "csharp_grpc_library",
)
load(
"@gapic_generator_csharp//rules_csharp_gapic:csharp_gapic.bzl",
_csharp_gapic_library = "csharp_gapic_library",
)
load(
"@gapic_generator_csharp//rules_csharp_gapic:csharp_gapic_pkg.bzl",
_csharp_gapic_assembly_pkg = "csharp_gapic_assembly_pkg",
)

# Common
proto_library_with_info = _proto_library_with_info
moved_proto_library = _moved_proto_library

# Java
java_gapic_library = _java_gapic_library
java_gapic_test = _java_gapic_test
java_gapic_assembly_gradle_pkg = _java_gapic_assembly_gradle_pkg

# Python
py_gapic_library = _py_gapic_library
py_test = native.py_test
py_gapic_assembly_pkg = _py_gapic_assembly_pkg

# Go
def go_test(**kwargs): pass
go_gapic_library = _go_gapic_library
go_gapic_assembly_pkg = _go_gapic_assembly_pkg

# C++
def cc_gapic_library(**kwargs): pass

# PHP
php_proto_library = _php_proto_library
php_grpc_library = _php_grpc_library
php_gapic_library = _php_gapic_library
php_gapic_assembly_pkg = _php_gapic_assembly_pkg

# Node.js
nodejs_gapic_library = _typescript_gapic_library
nodejs_gapic_assembly_pkg = _typescript_gapic_assembly_pkg

# Ruby
ruby_proto_library = _ruby_proto_library
ruby_grpc_library = _ruby_grpc_library
ruby_ads_gapic_library = _ruby_ads_gapic_library
ruby_cloud_gapic_library = _ruby_cloud_gapic_library
ruby_gapic_assembly_pkg = _ruby_gapic_assembly_pkg

# C#
csharp_proto_library = _csharp_proto_library
csharp_grpc_library = _csharp_grpc_library
csharp_gapic_library = _csharp_gapic_library
csharp_gapic_assembly_pkg = _csharp_gapic_assembly_pkg

Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
_INJECT_ATTRS = {
"rules_cc": attr.label(),
"rules_java": attr.label(),
"rules_python": attr.label(),
"rules_go": attr.label(),
"grpc": attr.label(),
"grpc_java": attr.label(),
}

_NATIVE = "native"
_DEV_DEP = "dev_dep"

_INJECTABLE_RULES = {
# Common
"proto_library_with_info": _DEV_DEP,
"moved_proto_library": _DEV_DEP,
# Java
"java_proto_library": _NATIVE,
"java_grpc_library": ("grpc_java", "//:java_grpc_library.bzl"),
"java_gapic_library": _DEV_DEP,
"java_gapic_test": _DEV_DEP,
"java_gapic_assembly_gradle_pkg": _DEV_DEP,
# Python
"py_proto_library": ("grpc", "//bazel:python_rules.bzl"),
"py_grpc_library": ("grpc", "//bazel:python_rules.bzl"),
"py_gapic_library": _DEV_DEP,
"py_test": _DEV_DEP,
"py_gapic_assembly_pkg": _DEV_DEP,
"py_import": ("rules_python", "//python:defs.bzl"),
# Go
"go_proto_library": ("rules_go", "//proto:def.bzl"),
"go_grpc_library": ("rules_go", "//proto:def.bzl"),
"go_library": ("rules_go", "//go:def.bzl"),
"go_test": _DEV_DEP,
"go_gapic_library": _DEV_DEP,
"go_gapic_assembly_pkg": _DEV_DEP,
# C++
"cc_proto_library": _NATIVE,
"cc_grpc_library": ("grpc", "//bazel:cc_grpc_library.bzl"),
"cc_gapic_library": _DEV_DEP,
# PHP
"php_proto_library": _DEV_DEP,
"php_grpc_library": _DEV_DEP,
"php_gapic_library": _DEV_DEP,
"php_gapic_assembly_pkg": _DEV_DEP,
# Node.js
"nodejs_gapic_library": _DEV_DEP,
"nodejs_gapic_assembly_pkg": _DEV_DEP,
# Ruby
"ruby_proto_library": _DEV_DEP,
"ruby_grpc_library": _DEV_DEP,
"ruby_ads_gapic_library": _DEV_DEP,
"ruby_cloud_gapic_library": _DEV_DEP,
"ruby_gapic_assembly_pkg": _DEV_DEP,
# C#
"csharp_proto_library": _DEV_DEP,
"csharp_grpc_library": _DEV_DEP,
"csharp_gapic_library": _DEV_DEP,
"csharp_gapic_assembly_pkg": _DEV_DEP,
}

def _imports_repo_impl(rctx):
loads = []
rules = []

for rule_name, source in _INJECTABLE_RULES.items():
if source == _NATIVE:
rules.append("%s = native.%s" % (rule_name, rule_name))
elif source == _DEV_DEP:
if rctx.attr.inject_dev_deps:
loads.append("load('@com_google_googleapis//:dev_dep_imports.bzl', _%s='%s')" % (rule_name, rule_name))
rules.append("%s = _%s" % (rule_name, rule_name))
else:
rules.append("def %s(**kwargs): pass" % rule_name)
else:
repo, label_remainder = source
injected_label = getattr(rctx.attr, repo)
if injected_label == None:
rules.append("def %s(**kwargs): pass" % rule_name)
else:
loads.append("load('@@%s%s', _%s='%s')" % (injected_label.repo_name, label_remainder, rule_name, rule_name))
rules.append("%s = _%s" % (rule_name, rule_name))

rctx.file("BUILD.bazel")
rctx.file("imports.bzl", "\n".join(loads + rules))

imports_repo = repository_rule(
implementation = _imports_repo_impl,
attrs = _INJECT_ATTRS | {
"inject_dev_deps": attr.bool(),
},
)

def _injections_impl(mctx):
attrs = {k: None for k in _INJECT_ATTRS}
inject_dev_deps = False

for module in mctx.modules:
if module.is_root and module.name == "googleapis":
inject_dev_deps = True
if len(module.tags.inject) == 0:
continue
if len(module.tags.inject) > 1:
fail("Multiple `inject` tags set by the module %s@%s. Only one `inject` tag may be set by each module." % (module.name, module.version))
attrs = {k: v or getattr(module.tags.inject[0], k, None) for k, v in attrs.items()}

imports_repo(
name = "com_google_googleapis_imports",
inject_dev_deps = inject_dev_deps,
**attrs,
)

return mctx.extension_metadata(reproducible = True)

injections = module_extension(
implementation = _injections_impl,
tag_classes = {"inject": tag_class(attrs = _INJECT_ATTRS)},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
matrix:
platform: ["debian10", "macos", "ubuntu2004", "windows"]
bazel: ["7.x"]
tasks:
verify_targets:
platform: ${{ platform }}
bazel: ${{ bazel }}
build_targets:
- '@googleapis//google/devtools/source/v1:source_proto'
10 changes: 10 additions & 0 deletions modules/googleapis/0.0.0-20240326-1c8d509c5.bcr.1/source.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"integrity": "sha256-uFSuF925M8JJUw90PbjXjfgJBd+0JoElVWSh0ZId/Dw=",
"strip_prefix": "googleapis-1c8d509c574aeab7478be1bfd4f2e8f0931cfead",
"url": "https://github.com/googleapis/googleapis/archive/1c8d509c574aeab7478be1bfd4f2e8f0931cfead.tar.gz",
"overlay": {
"MODULE.bazel": "sha256-JfstIx1z0DQKpgl0V+W2o+ABEGN73CBvzENVKOQTjsI=",
"dev_dep_imports.bzl": "sha256-oGTkJ4OizMjKiD+gmpJqvTm8WS/3qC/fqU+ZVODoiGk=",
"injections.bzl": "sha256-Z8M/rugI0sy+i8b/ZYB9PJouUCy86hTUiXXlPJKSZp0="
}
}
29 changes: 15 additions & 14 deletions modules/googleapis/metadata.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"homepage": "https://github.com/googleapis/googleapis",
"maintainers": [
{
"email": "[email protected]",
"name": "No Maintainer Specified"
}
],
"repository": [
"github:googleapis/googleapis"
],
"versions": [
"0.0.0-20240326-1c8d509c5"
],
"yanked_versions": {}
"homepage": "https://github.com/googleapis/googleapis",
"maintainers": [
{
"email": "[email protected]",
"name": "No Maintainer Specified"
}
],
"repository": [
"github:googleapis/googleapis"
],
"versions": [
"0.0.0-20240326-1c8d509c5",
"0.0.0-20240326-1c8d509c5.bcr.1"
],
"yanked_versions": {}
}
Loading
Loading