chore: import upstream snapshot with attribution
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:14:16 +08:00
commit 8a852e4b4e
36502 changed files with 9277225 additions and 0 deletions
View File
View File
+6
View File
@@ -0,0 +1,6 @@
licenses(["notice"]) # Apache 2.0
filegroup(
name = "LICENSE",
visibility = ["//visibility:public"],
)
+7
View File
@@ -0,0 +1,7 @@
licenses(["notice"]) # Apache 2.0
package(default_visibility = ["//visibility:public"])
py_library(
name = "app",
)
+11
View File
@@ -0,0 +1,11 @@
licenses(["notice"]) # Apache 2.0
package(default_visibility = ["//visibility:public"])
py_library(
name = "flags",
)
py_library(
name = "argparse_flags",
)
+7
View File
@@ -0,0 +1,7 @@
licenses(["notice"]) # Apache 2.0
package(default_visibility = ["//visibility:public"])
py_library(
name = "logging",
)
+16
View File
@@ -0,0 +1,16 @@
licenses(["notice"]) # Apache 2.0
py_library(
name = "parameterized",
visibility = ["//visibility:public"],
)
py_library(
name = "absltest",
visibility = ["//visibility:public"],
)
py_library(
name = "flagsaver",
visibility = ["//visibility:public"],
)
+21
View File
@@ -0,0 +1,21 @@
licenses(["notice"])
filegroup(
name = "LICENSE",
visibility = ["//visibility:public"],
)
cc_library(
name = "crypto",
linkopts = ["-lcrypto"],
visibility = ["//visibility:public"],
)
cc_library(
name = "ssl",
linkopts = ["-lssl"],
visibility = ["//visibility:public"],
deps = [
":crypto",
],
)
+32
View File
@@ -0,0 +1,32 @@
# -*- Python -*-
"""Skylark macros for system libraries.
"""
SYSTEM_LIBS_ENABLED = %{syslibs_enabled}
SYSTEM_LIBS_LIST = [
%{syslibs_list}
]
def if_any_system_libs(a, b=[]):
"""Conditional which evaluates to 'a' if any system libraries are configured."""
if SYSTEM_LIBS_ENABLED:
return a
else:
return b
def if_system_lib(lib, a, b=[]):
"""Conditional which evaluates to 'a' if we're using the system version of lib"""
if SYSTEM_LIBS_ENABLED and lib in SYSTEM_LIBS_LIST:
return a
else:
return b
def if_not_system_lib(lib, a, b=[]):
"""Conditional which evaluates to 'a' if we're using the system version of lib"""
return if_system_lib(lib, b, a)
+12
View File
@@ -0,0 +1,12 @@
licenses(["notice"]) # MIT/X derivative license
filegroup(
name = "COPYING",
visibility = ["//visibility:public"],
)
cc_library(
name = "curl",
linkopts = ["-lcurl"],
visibility = ["//visibility:public"],
)
+13
View File
@@ -0,0 +1,13 @@
licenses(["notice"]) # Apache-2.0
genrule(
name = "lncython",
outs = ["cython"],
cmd = "ln -s $$(which cython) $@",
)
sh_binary(
name = "cython_binary",
srcs = ["cython"],
visibility = ["//visibility:public"],
)
+12
View File
@@ -0,0 +1,12 @@
licenses(["notice"]) # MIT
filegroup(
name = "COPYING",
visibility = ["//visibility:public"],
)
cc_library(
name = "gif",
linkopts = ["-lgif"],
visibility = ["//visibility:public"],
)
+6
View File
@@ -0,0 +1,6 @@
licenses(["notice"]) # Apache 2.0
filegroup(
name = "LICENSE",
visibility = ["//visibility:public"],
)
@@ -0,0 +1,7 @@
licenses(["notice"]) # Apache 2.0
cc_library(
name = "bigtable_client",
linkopts = ["-lbigtable_client"],
visibility = ["//visibility:public"],
)
+71
View File
@@ -0,0 +1,71 @@
licenses(["notice"]) # Apache v2
filegroup(
name = "LICENSE",
visibility = ["//visibility:public"],
)
cc_library(
name = "grpc",
linkopts = [
"-lgrpc",
"-lgpr",
],
visibility = ["//visibility:public"],
)
cc_library(
name = "grpc++",
linkopts = [
"-lgrpc++",
"-lgpr",
],
visibility = ["//visibility:public"],
)
cc_library(
name = "grpc++_codegen_proto",
visibility = ["//visibility:public"],
)
cc_library(
name = "grpc_unsecure",
linkopts = [
"-lgrpc_unsecure",
"-lgpr",
],
visibility = ["//visibility:public"],
)
cc_library(
name = "grpc++_unsecure",
linkopts = [
"-lgrpc++_unsecure",
"-lgpr",
],
visibility = ["//visibility:public"],
)
genrule(
name = "ln_grpc_cpp_plugin",
outs = ["grpc_cpp_plugin.bin"],
cmd = "ln -s $$(which grpc_cpp_plugin) $@",
)
sh_binary(
name = "grpc_cpp_plugin",
srcs = ["grpc_cpp_plugin.bin"],
visibility = ["//visibility:public"],
)
genrule(
name = "ln_grpc_python_plugin",
outs = ["grpc_python_plugin.bin"],
cmd = "ln -s $$(which grpc_python_plugin) $@",
)
sh_binary(
name = "grpc_python_plugin",
srcs = ["grpc_python_plugin.bin"],
visibility = ["//visibility:public"],
)
+105
View File
@@ -0,0 +1,105 @@
"""Generates and compiles C++ grpc stubs from proto_library rules."""
load("@com_github_grpc_grpc//bazel:generate_cc.bzl", "generate_cc")
load("@com_github_grpc_grpc//bazel:protobuf.bzl", "well_known_proto_libs")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
def cc_grpc_library(
name,
srcs,
deps,
proto_only = False,
well_known_protos = False,
generate_mocks = False,
use_external = False,
grpc_only = False,
**kwargs):
"""Generates C++ grpc classes for services defined in a proto file.
If grpc_only is True, this rule is compatible with proto_library and
cc_proto_library native rules such that it expects proto_library target
as srcs argument and generates only grpc library classes, expecting
protobuf messages classes library (cc_proto_library target) to be passed in
deps argument. By default grpc_only is False which makes this rule to behave
in a backwards-compatible mode (trying to generate both proto and grpc
classes).
Assumes the generated classes will be used in cc_api_version = 2.
Args:
name (str): Name of rule.
srcs (list): A single .proto file which contains services definitions,
or if grpc_only parameter is True, a single proto_library which
contains services descriptors.
deps (list): A list of C++ proto_library (or cc_proto_library) which
provides the compiled code of any message that the services depend on.
proto_only (bool): If True, create only C++ proto classes library,
avoid creating C++ grpc classes library (expect it in deps).
Deprecated, use native cc_proto_library instead. False by default.
well_known_protos (bool): Should this library additionally depend on
well known protos. Deprecated, the well known protos should be
specified as explicit dependencies of the proto_library target
(passed in srcs parameter) instead. False by default.
generate_mocks (bool): when True, Google Mock code for client stub is
generated. False by default.
use_external (bool): Not used.
grpc_only (bool): if True, generate only grpc library, expecting
protobuf messages library (cc_proto_library target) to be passed as
deps. False by default (will become True by default eventually).
**kwargs: rest of arguments, e.g., compatible_with and visibility
"""
if len(srcs) > 1:
fail("Only one srcs value supported", "srcs")
if grpc_only and proto_only:
fail("A mutualy exclusive configuration is specified: grpc_only = True and proto_only = True")
extra_deps = []
proto_targets = []
if not grpc_only:
proto_target = "_" + name + "_only"
cc_proto_target = name if proto_only else "_" + name + "_cc_proto"
proto_deps = ["_" + dep + "_only" for dep in deps if dep.find(":") == -1]
proto_deps += [dep.split(":")[0] + ":" + "_" + dep.split(":")[1] + "_only" for dep in deps if dep.find(":") != -1]
if well_known_protos:
proto_deps += well_known_proto_libs()
native.proto_library(
name = proto_target,
srcs = srcs,
deps = proto_deps,
**kwargs
)
native.cc_proto_library(
name = cc_proto_target,
deps = [":" + proto_target],
**kwargs
)
extra_deps.append(":" + cc_proto_target)
proto_targets.append(proto_target)
else:
if not srcs:
fail("srcs cannot be empty", "srcs")
proto_targets += srcs
if not proto_only:
codegen_grpc_target = "_" + name + "_grpc_codegen"
generate_cc(
name = codegen_grpc_target,
srcs = proto_targets,
plugin = "@com_github_grpc_grpc//src/compiler:grpc_cpp_plugin",
well_known_protos = well_known_protos,
generate_mocks = generate_mocks,
**kwargs
)
cc_library(
name = name,
srcs = [":" + codegen_grpc_target],
hdrs = [":" + codegen_grpc_target],
deps = deps +
extra_deps +
["@com_github_grpc_grpc//:grpc++_codegen_proto"],
**kwargs
)
+187
View File
@@ -0,0 +1,187 @@
"""Generates C++ grpc stubs from proto_library rules.
This is an internal rule used by cc_grpc_library, and shouldn't be used
directly.
"""
load(
"@com_github_grpc_grpc//bazel:protobuf.bzl",
"get_include_directory",
"get_plugin_args",
"get_proto_root",
"proto_path_to_generated_filename",
)
load("@rules_proto//proto:defs.bzl", "ProtoInfo")
_GRPC_PROTO_HEADER_FMT = "{}.grpc.pb.h"
_GRPC_PROTO_SRC_FMT = "{}.grpc.pb.cc"
_GRPC_PROTO_MOCK_HEADER_FMT = "{}_mock.grpc.pb.h"
_PROTO_HEADER_FMT = "{}.pb.h"
_PROTO_SRC_FMT = "{}.pb.cc"
def _strip_package_from_path(label_package, file):
prefix_len = 0
if not file.is_source and file.path.startswith(file.root.path):
prefix_len = len(file.root.path) + 1
path = file.path
if len(label_package) == 0:
return path
if not path.startswith(label_package + "/", prefix_len):
fail("'{}' does not lie within '{}'.".format(path, label_package))
return path[prefix_len + len(label_package + "/"):]
def _get_srcs_file_path(file):
if not file.is_source and file.path.startswith(file.root.path):
return file.path[len(file.root.path) + 1:]
return file.path
def _join_directories(directories):
massaged_directories = [directory for directory in directories if len(directory) != 0]
return "/".join(massaged_directories)
def generate_cc_impl(ctx):
"""Implementation of the generate_cc rule."""
protos = [f for src in ctx.attr.srcs for f in src[ProtoInfo].check_deps_sources.to_list()]
includes = [
f
for src in ctx.attr.srcs
for f in src[ProtoInfo].transitive_sources.to_list()
]
outs = []
proto_root = get_proto_root(
ctx.label.workspace_root,
)
label_package = _join_directories([ctx.label.workspace_root, ctx.label.package])
if ctx.executable.plugin:
outs += [
proto_path_to_generated_filename(
_strip_package_from_path(label_package, proto),
_GRPC_PROTO_HEADER_FMT,
)
for proto in protos
]
outs += [
proto_path_to_generated_filename(
_strip_package_from_path(label_package, proto),
_GRPC_PROTO_SRC_FMT,
)
for proto in protos
]
if ctx.attr.generate_mocks:
outs += [
proto_path_to_generated_filename(
_strip_package_from_path(label_package, proto),
_GRPC_PROTO_MOCK_HEADER_FMT,
)
for proto in protos
]
else:
outs += [
proto_path_to_generated_filename(
_strip_package_from_path(label_package, proto),
_PROTO_HEADER_FMT,
)
for proto in protos
]
outs += [
proto_path_to_generated_filename(
_strip_package_from_path(label_package, proto),
_PROTO_SRC_FMT,
)
for proto in protos
]
out_files = [ctx.actions.declare_file(out) for out in outs]
dir_out = str(ctx.genfiles_dir.path + proto_root)
arguments = []
if ctx.executable.plugin:
arguments += get_plugin_args(
ctx.executable.plugin,
ctx.attr.flags,
dir_out,
ctx.attr.generate_mocks,
)
tools = [ctx.executable.plugin]
else:
arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out]
tools = []
arguments += [
"--proto_path={}".format(get_include_directory(i))
for i in includes
]
# Include the output directory so that protoc puts the generated code in the
# right directory.
arguments += ["--proto_path={0}{1}".format(dir_out, proto_root)]
arguments += [_get_srcs_file_path(proto) for proto in protos]
# create a list of well known proto files if the argument is non-None
well_known_proto_files = []
if ctx.attr.well_known_protos:
f = ctx.attr.well_known_protos.files.to_list()[0].dirname
if f != "external/com_google_protobuf/src/google/protobuf":
print(
"Error: Only @com_google_protobuf//:well_known_protos is supported",
)
else:
# f points to "external/com_google_protobuf/src/google/protobuf"
# add -I argument to protoc so it knows where to look for the proto files.
arguments += ["-I{0}".format(f + "/../..")]
well_known_proto_files = [
f
for f in ctx.attr.well_known_protos.files.to_list()
]
ctx.actions.run(
mnemonic = "GenerateCc",
inputs = protos + includes + well_known_proto_files,
tools = tools,
outputs = out_files,
executable = ctx.executable._protoc,
arguments = arguments,
use_default_shell_env = True,
)
return struct(files = depset(out_files))
_generate_cc = rule(
attrs = {
"srcs": attr.label_list(
mandatory = True,
allow_empty = False,
providers = [ProtoInfo],
),
"plugin": attr.label(
executable = True,
providers = ["files_to_run"],
cfg = "exec",
),
"flags": attr.string_list(
mandatory = False,
allow_empty = True,
),
"well_known_protos": attr.label(mandatory = False),
"generate_mocks": attr.bool(
default = False,
mandatory = False,
),
"_protoc": attr.label(
default = Label("@com_google_protobuf//:protoc"),
executable = True,
cfg = "exec",
),
},
implementation = generate_cc_impl,
)
def generate_cc(well_known_protos, **kwargs):
if well_known_protos:
_generate_cc(
well_known_protos = "@com_google_protobuf//:well_known_protos",
**kwargs
)
else:
_generate_cc(**kwargs)
+6
View File
@@ -0,0 +1,6 @@
"""Load dependencies needed to compile and test the grpc library as a 3rd-party consumer."""
def grpc_deps():
"""Loads dependencies need to compile and test the grpc library."""
pass
+4
View File
@@ -0,0 +1,4 @@
"""Stub version of @com_github_grpc_grpc//bazel:grpc_extra_deps.bzl necessary for TF system libs"""
def grpc_extra_deps():
pass
+246
View File
@@ -0,0 +1,246 @@
"""Utility functions for generating protobuf code."""
load("@rules_proto//proto:defs.bzl", "ProtoInfo")
_PROTO_EXTENSION = ".proto"
_VIRTUAL_IMPORTS = "/_virtual_imports/"
def well_known_proto_libs():
return [
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:api_proto",
"@com_google_protobuf//:compiler_plugin_proto",
"@com_google_protobuf//:descriptor_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:empty_proto",
"@com_google_protobuf//:field_mask_proto",
"@com_google_protobuf//:source_context_proto",
"@com_google_protobuf//:struct_proto",
"@com_google_protobuf//:timestamp_proto",
"@com_google_protobuf//:type_proto",
"@com_google_protobuf//:wrappers_proto",
]
def get_proto_root(workspace_root):
"""Gets the root protobuf directory.
Args:
workspace_root: context.label.workspace_root
Returns:
The directory relative to which generated include paths should be.
"""
if workspace_root:
return "/{}".format(workspace_root)
else:
return ""
def _strip_proto_extension(proto_filename):
if not proto_filename.endswith(_PROTO_EXTENSION):
fail('"{}" does not end with "{}"'.format(
proto_filename,
_PROTO_EXTENSION,
))
return proto_filename[:-len(_PROTO_EXTENSION)]
def proto_path_to_generated_filename(proto_path, fmt_str):
"""Calculates the name of a generated file for a protobuf path.
For example, "examples/protos/helloworld.proto" might map to
"helloworld.pb.h".
Args:
proto_path: The path to the .proto file.
fmt_str: A format string used to calculate the generated filename. For
example, "{}.pb.h" might be used to calculate a C++ header filename.
Returns:
The generated filename.
"""
return fmt_str.format(_strip_proto_extension(proto_path))
def get_include_directory(source_file):
"""Returns the include directory path for the source_file.
I.e. all of the include statements within the given source_file
are calculated relative to the directory returned by this method.
The returned directory path can be used as the "--proto_path=" argument
value.
Args:
source_file: A proto file.
Returns:
The include directory path for the source_file.
"""
directory = source_file.path
prefix_len = 0
if is_in_virtual_imports(source_file):
root, relative = source_file.path.split(_VIRTUAL_IMPORTS, 2)
result = root + _VIRTUAL_IMPORTS + relative.split("/", 1)[0]
return result
if not source_file.is_source and directory.startswith(source_file.root.path):
prefix_len = len(source_file.root.path) + 1
if directory.startswith("external", prefix_len):
external_separator = directory.find("/", prefix_len)
repository_separator = directory.find("/", external_separator + 1)
return directory[:repository_separator]
else:
return source_file.root.path if source_file.root.path else "."
def get_plugin_args(
plugin,
flags,
dir_out,
generate_mocks,
plugin_name = "PLUGIN"):
"""Returns arguments configuring protoc to use a plugin for a language.
Args:
plugin: An executable file to run as the protoc plugin.
flags: The plugin flags to be passed to protoc.
dir_out: The output directory for the plugin.
generate_mocks: A bool indicating whether to generate mocks.
plugin_name: A name of the plugin, it is required to be unique when there
are more than one plugin used in a single protoc command.
Returns:
A list of protoc arguments configuring the plugin.
"""
augmented_flags = list(flags)
if generate_mocks:
augmented_flags.append("generate_mock_code=true")
augmented_dir_out = dir_out
if augmented_flags:
augmented_dir_out = ",".join(augmented_flags) + ":" + dir_out
return [
"--plugin=protoc-gen-{plugin_name}={plugin_path}".format(
plugin_name = plugin_name,
plugin_path = plugin.path,
),
"--{plugin_name}_out={dir_out}".format(
plugin_name = plugin_name,
dir_out = augmented_dir_out,
),
]
def _get_staged_proto_file(context, source_file):
if (source_file.dirname == context.label.package or
is_in_virtual_imports(source_file)):
return source_file
else:
copied_proto = context.actions.declare_file(source_file.basename)
context.actions.run_shell(
inputs = [source_file],
outputs = [copied_proto],
command = "cp {} {}".format(source_file.path, copied_proto.path),
mnemonic = "CopySourceProto",
)
return copied_proto
def protos_from_context(context):
"""Copies proto files to the appropriate location.
Args:
context: The ctx object for the rule.
Returns:
A list of the protos.
"""
protos = []
for src in context.attr.deps:
for file in src[ProtoInfo].direct_sources:
protos.append(_get_staged_proto_file(context, file))
return protos
def includes_from_deps(deps):
"""Get includes from rule dependencies."""
return [
file
for src in deps
for file in src[ProtoInfo].transitive_sources.to_list()
]
def get_proto_arguments(protos, genfiles_dir_path):
"""Get the protoc arguments specifying which protos to compile."""
arguments = []
for proto in protos:
strip_prefix_len = 0
if is_in_virtual_imports(proto):
incl_directory = get_include_directory(proto)
if proto.path.startswith(incl_directory):
strip_prefix_len = len(incl_directory) + 1
elif proto.path.startswith(genfiles_dir_path):
strip_prefix_len = len(genfiles_dir_path) + 1
arguments.append(proto.path[strip_prefix_len:])
return arguments
def declare_out_files(protos, context, generated_file_format):
"""Declares and returns the files to be generated."""
out_file_paths = []
for proto in protos:
if not is_in_virtual_imports(proto):
out_file_paths.append(proto.basename)
else:
path = proto.path[proto.path.index(_VIRTUAL_IMPORTS) + 1:]
out_file_paths.append(path)
return [
context.actions.declare_file(
proto_path_to_generated_filename(
out_file_path,
generated_file_format,
),
)
for out_file_path in out_file_paths
]
def get_out_dir(protos, context):
""" Returns the calculated value for --<lang>_out= protoc argument based on
the input source proto files and current context.
Args:
protos: A list of protos to be used as source files in protoc command
context: A ctx object for the rule.
Returns:
The value of --<lang>_out= argument.
"""
at_least_one_virtual = 0
for proto in protos:
if is_in_virtual_imports(proto):
at_least_one_virtual = True
elif at_least_one_virtual:
fail("Proto sources must be either all virtual imports or all real")
if at_least_one_virtual:
out_dir = get_include_directory(protos[0])
ws_root = protos[0].owner.workspace_root
if ws_root and out_dir.find(ws_root) >= 0:
out_dir = "".join(out_dir.rsplit(ws_root, 1))
return struct(
path = out_dir,
import_path = out_dir[out_dir.find(_VIRTUAL_IMPORTS) + 1:],
)
return struct(path = context.genfiles_dir.path, import_path = None)
def is_in_virtual_imports(source_file, virtual_folder = _VIRTUAL_IMPORTS):
"""Determines if source_file is virtual (is placed in _virtual_imports
subdirectory). The output of all proto_library targets which use
import_prefix and/or strip_import_prefix arguments is placed under
_virtual_imports directory.
Args:
source_file: A proto file.
virtual_folder: The virtual folder name (is set to "_virtual_imports"
by default)
Returns:
True if source_file is located under _virtual_imports, False otherwise.
"""
return not source_file.is_source and virtual_folder in source_file.path
+12
View File
@@ -0,0 +1,12 @@
licenses(["unencumbered"]) # Public Domain or MIT
filegroup(
name = "LICENSE",
visibility = ["//visibility:public"],
)
cc_library(
name = "jsoncpp",
linkopts = ["-ljsoncpp"],
visibility = ["//visibility:public"],
)
+12
View File
@@ -0,0 +1,12 @@
licenses(["notice"]) # OpenLDAP Public License
filegroup(
name = "LICENSE",
visibility = ["//visibility:public"],
)
cc_library(
name = "lmdb",
linkopts = ["-llmdb"],
visibility = ["//visibility:public"],
)
+12
View File
@@ -0,0 +1,12 @@
licenses(["notice"]) # BSD/MIT-like license
filegroup(
name = "LICENSE",
visibility = ["//visibility:public"],
)
cc_library(
name = "png",
linkopts = ["-lpng"],
visibility = ["//visibility:public"],
)
+113
View File
@@ -0,0 +1,113 @@
load(
"@com_google_protobuf//:protobuf.bzl",
"cc_proto_library",
"proto_gen",
"py_proto_library",
)
load("@rules_proto//proto:defs.bzl", "proto_library")
licenses(["notice"])
filegroup(
name = "LICENSE",
visibility = ["//visibility:public"],
)
# Map of all well known protos.
# name => (include path, imports)
WELL_KNOWN_PROTO_MAP = {
"any": ("google/protobuf/any.proto", []),
"api": (
"google/protobuf/api.proto",
[
"source_context",
"type",
],
),
"compiler_plugin": (
"google/protobuf/compiler/plugin.proto",
["descriptor"],
),
"descriptor": ("google/protobuf/descriptor.proto", []),
"duration": ("google/protobuf/duration.proto", []),
"empty": ("google/protobuf/empty.proto", []),
"field_mask": ("google/protobuf/field_mask.proto", []),
"source_context": ("google/protobuf/source_context.proto", []),
"struct": ("google/protobuf/struct.proto", []),
"timestamp": ("google/protobuf/timestamp.proto", []),
"type": (
"google/protobuf/type.proto",
[
"any",
"source_context",
],
),
"wrappers": ("google/protobuf/wrappers.proto", []),
}
RELATIVE_WELL_KNOWN_PROTOS = [proto[1][0] for proto in WELL_KNOWN_PROTO_MAP.items()]
genrule(
name = "link_proto_files",
outs = RELATIVE_WELL_KNOWN_PROTOS,
cmd = """
for i in $(OUTS); do
f=$${i#$(@D)/}
mkdir -p $(@D)/$${f%/*}
ln -sf $(PROTOBUF_INCLUDE_PATH)/$$f $(@D)/$$f
done
""",
)
cc_library(
name = "protobuf",
linkopts = ["-lprotobuf"],
visibility = ["//visibility:public"],
)
cc_library(
name = "protobuf_headers",
linkopts = ["-lprotobuf"],
visibility = ["//visibility:public"],
)
cc_library(
name = "protoc_lib",
linkopts = ["-lprotoc"],
visibility = ["//visibility:public"],
)
genrule(
name = "protoc",
outs = ["protoc.bin"],
cmd = "ln -s $$(which protoc) $@",
executable = 1,
visibility = ["//visibility:public"],
)
cc_proto_library(
name = "cc_wkt_protos",
internal_bootstrap_hack = 1,
protoc = ":protoc",
visibility = ["//visibility:public"],
)
proto_gen(
name = "protobuf_python_genproto",
includes = ["."],
protoc = "@com_google_protobuf//:protoc",
visibility = ["//visibility:public"],
)
py_library(
name = "protobuf_python",
srcs_version = "PY3",
visibility = ["//visibility:public"],
)
[proto_library(
name = proto[0] + "_proto",
srcs = [proto[1][0]],
visibility = ["//visibility:public"],
deps = [dep + "_proto" for dep in proto[1][1]],
) for proto in WELL_KNOWN_PROTO_MAP.items()]
+434
View File
@@ -0,0 +1,434 @@
""
load("@rules_python//python:py_library.bzl", "py_library")
load("@rules_python//python:py_test.bzl", "py_test")
def _GetPath(ctx, path):
if ctx.label.workspace_root:
return ctx.label.workspace_root + "/" + path
else:
return path
def _IsNewExternal(ctx):
# Bazel 0.4.4 and older have genfiles paths that look like:
# bazel-out/local-fastbuild/genfiles/external/repo/foo
# After the exec root rearrangement, they look like:
# ../repo/bazel-out/local-fastbuild/genfiles/foo
return ctx.label.workspace_root.startswith("../")
def _GenDir(ctx):
if _IsNewExternal(ctx):
# We are using the fact that Bazel 0.4.4+ provides repository-relative paths
# for ctx.genfiles_dir.
return ctx.genfiles_dir.path + (
"/" + ctx.attr.includes[0] if ctx.attr.includes and ctx.attr.includes[0] else ""
)
# This means that we're either in the old version OR the new version in the local repo.
# Either way, appending the source path to the genfiles dir works.
return ctx.var["GENDIR"] + "/" + _SourceDir(ctx)
def _SourceDir(ctx):
if not ctx.attr.includes:
return ctx.label.workspace_root
if not ctx.attr.includes[0]:
return _GetPath(ctx, ctx.label.package)
if not ctx.label.package:
return _GetPath(ctx, ctx.attr.includes[0])
return _GetPath(ctx, ctx.label.package + "/" + ctx.attr.includes[0])
def _CcHdrs(srcs, use_grpc_plugin = False):
ret = [s[:-len(".proto")] + ".pb.h" for s in srcs]
if use_grpc_plugin:
ret += [s[:-len(".proto")] + ".grpc.pb.h" for s in srcs]
return ret
def _CcSrcs(srcs, use_grpc_plugin = False):
ret = [s[:-len(".proto")] + ".pb.cc" for s in srcs]
if use_grpc_plugin:
ret += [s[:-len(".proto")] + ".grpc.pb.cc" for s in srcs]
return ret
def _CcOuts(srcs, use_grpc_plugin = False):
return _CcHdrs(srcs, use_grpc_plugin) + _CcSrcs(srcs, use_grpc_plugin)
def _PyOuts(srcs, use_grpc_plugin = False):
ret = [s[:-len(".proto")] + "_pb2.py" for s in srcs]
if use_grpc_plugin:
ret += [s[:-len(".proto")] + "_pb2_grpc.py" for s in srcs]
return ret
def _RelativeOutputPath(path, include, dest = ""):
if include == None:
return path
if not path.startswith(include):
fail("Include path %s isn't part of the path %s." % (include, path))
if include and include[-1] != "/":
include = include + "/"
if dest and dest[-1] != "/":
dest = dest + "/"
path = path[len(include):]
return dest + path
def _proto_gen_impl(ctx):
"""General implementation for generating protos"""
srcs = ctx.files.srcs
deps = []
deps += ctx.files.srcs
source_dir = _SourceDir(ctx)
gen_dir = _GenDir(ctx)
if source_dir:
import_flags = ["-I" + source_dir, "-I" + gen_dir]
else:
import_flags = ["-I."]
for dep in ctx.attr.deps:
import_flags += dep.proto.import_flags
deps += dep.proto.deps
import_flags = depset(import_flags).to_list()
deps = depset(deps).to_list()
args = []
if ctx.attr.gen_cc:
args += ["--cpp_out=" + gen_dir]
if ctx.attr.gen_py:
args += ["--python_out=" + gen_dir]
inputs = srcs + deps
tools = [ctx.executable.protoc]
if ctx.executable.plugin:
plugin = ctx.executable.plugin
lang = ctx.attr.plugin_language
if not lang and plugin.basename.startswith("protoc-gen-"):
lang = plugin.basename[len("protoc-gen-"):]
if not lang:
fail("cannot infer the target language of plugin", "plugin_language")
outdir = gen_dir
if ctx.attr.plugin_options:
outdir = ",".join(ctx.attr.plugin_options) + ":" + outdir
args += ["--plugin=protoc-gen-%s=%s" % (lang, plugin.path)]
args += ["--%s_out=%s" % (lang, outdir)]
tools.append(plugin)
if args:
ctx.actions.run(
inputs = inputs,
outputs = ctx.outputs.outs,
arguments = args + import_flags + [s.path for s in srcs],
executable = ctx.executable.protoc,
mnemonic = "ProtoCompile",
tools = tools,
use_default_shell_env = True,
)
return struct(
proto = struct(
srcs = srcs,
import_flags = import_flags,
deps = deps,
),
)
proto_gen = rule(
attrs = {
"srcs": attr.label_list(allow_files = True),
"deps": attr.label_list(providers = ["proto"]),
"includes": attr.string_list(),
"protoc": attr.label(
cfg = "host",
executable = True,
allow_single_file = True,
mandatory = True,
),
"plugin": attr.label(
cfg = "host",
allow_files = True,
executable = True,
),
"plugin_language": attr.string(),
"plugin_options": attr.string_list(),
"gen_cc": attr.bool(),
"gen_py": attr.bool(),
"outs": attr.output_list(),
},
implementation = _proto_gen_impl,
)
"""Generates codes from Protocol Buffers definitions.
This rule helps you to implement Skylark macros specific to the target
language. You should prefer more specific `cc_proto_library `,
`py_proto_library` and others unless you are adding such wrapper macros.
Args:
srcs: Protocol Buffers definition files (.proto) to run the protocol compiler
against.
deps: a list of dependency labels; must be other proto libraries.
includes: a list of include paths to .proto files.
protoc: the label of the protocol compiler to generate the sources.
plugin: the label of the protocol compiler plugin to be passed to the protocol
compiler.
plugin_language: the language of the generated sources
plugin_options: a list of options to be passed to the plugin
gen_cc: generates C++ sources in addition to the ones from the plugin.
gen_py: generates Python sources in addition to the ones from the plugin.
outs: a list of labels of the expected outputs from the protocol compiler.
"""
def cc_proto_library(
name,
srcs = [],
deps = [],
cc_libs = [],
include = None,
protoc = "@com_google_protobuf//:protoc",
internal_bootstrap_hack = False,
use_grpc_plugin = False,
default_runtime = "@com_google_protobuf//:protobuf",
**kwargs):
"""Bazel rule to create a C++ protobuf library from proto source files
NOTE: the rule is only an internal workaround to generate protos. The
interface may change and the rule may be removed when bazel has introduced
the native rule.
Args:
name: the name of the cc_proto_library.
srcs: the .proto files of the cc_proto_library.
deps: a list of dependency labels; must be cc_proto_library.
cc_libs: a list of other cc_library targets depended by the generated
cc_library.
include: a string indicating the include path of the .proto files.
protoc: the label of the protocol compiler to generate the sources.
internal_bootstrap_hack: a flag indicating if the cc_proto_library is used only
for bootstrapping. When it is set to True, no files will be generated.
The rule will simply be a provider for .proto files, so that other
cc_proto_library can depend on it.
use_grpc_plugin: a flag to indicate whether to call the grpc C++ plugin
when processing the proto files.
default_runtime: the implicitly default runtime which will be depended on by
the generated cc_library target.
**kwargs: other keyword arguments that are passed to cc_library.
"""
includes = []
if include != None:
includes = [include]
if internal_bootstrap_hack:
# For pre-checked-in generated files, we add the internal_bootstrap_hack
# which will skip the codegen action.
proto_gen(
name = name + "_genproto",
srcs = srcs,
deps = [s + "_genproto" for s in deps],
includes = includes,
protoc = protoc,
visibility = ["//visibility:public"],
)
# An empty cc_library to make rule dependency consistent.
native.cc_library(
name = name,
**kwargs
)
return
grpc_cpp_plugin = None
if use_grpc_plugin:
grpc_cpp_plugin = "//external:grpc_cpp_plugin"
gen_srcs = _CcSrcs(srcs, use_grpc_plugin)
gen_hdrs = _CcHdrs(srcs, use_grpc_plugin)
outs = gen_srcs + gen_hdrs
proto_gen(
name = name + "_genproto",
srcs = srcs,
deps = [s + "_genproto" for s in deps],
includes = includes,
protoc = protoc,
plugin = grpc_cpp_plugin,
plugin_language = "grpc",
gen_cc = 1,
outs = outs,
visibility = ["//visibility:public"],
)
if default_runtime and not default_runtime in cc_libs:
cc_libs = cc_libs + [default_runtime]
if use_grpc_plugin:
cc_libs = cc_libs + ["//external:grpc_lib"]
native.cc_library(
name = name,
srcs = gen_srcs,
hdrs = gen_hdrs,
deps = cc_libs + deps,
includes = includes,
alwayslink = 1,
**kwargs
)
def internal_gen_well_known_protos_java(srcs):
"""Bazel rule to generate the gen_well_known_protos_java genrule
Args:
srcs: the well known protos
"""
root = Label("%s//protobuf_java" % (native.repository_name())).workspace_root
pkg = native.package_name() + "/" if native.package_name() else ""
if root == "":
include = " -I%ssrc " % pkg
else:
include = " -I%s/%ssrc " % (root, pkg)
native.genrule(
name = "gen_well_known_protos_java",
srcs = srcs,
outs = [
"wellknown.srcjar",
],
cmd = "$(location :protoc) --java_out=$(@D)/wellknown.jar" +
" %s $(SRCS) " % include +
" && mv $(@D)/wellknown.jar $(@D)/wellknown.srcjar",
tools = [":protoc"],
)
def internal_copied_filegroup(name, srcs, strip_prefix, dest, **kwargs):
"""Macro to copy files to a different directory and then create a filegroup.
This is used by the //:protobuf_python py_proto_library target to work around
an issue caused by Python source files that are part of the same Python
package being in separate directories.
Args:
srcs: The source files to copy and add to the filegroup.
strip_prefix: Path to the root of the files to copy.
dest: The directory to copy the source files into.
**kwargs: extra arguments that will be passesd to the filegroup.
"""
outs = [_RelativeOutputPath(s, strip_prefix, dest) for s in srcs]
native.genrule(
name = name + "_genrule",
srcs = srcs,
outs = outs,
cmd = " && ".join(
["cp $(location %s) $(location %s)" %
(s, _RelativeOutputPath(s, strip_prefix, dest)) for s in srcs],
),
)
native.filegroup(
name = name,
srcs = outs,
**kwargs
)
def py_proto_library(
name,
srcs = [],
deps = [],
py_libs = [],
py_extra_srcs = [],
include = None,
default_runtime = "@com_google_protobuf//:protobuf_python",
protoc = "@com_google_protobuf//:protoc",
use_grpc_plugin = False,
**kwargs):
"""Bazel rule to create a Python protobuf library from proto source files
NOTE: the rule is only an internal workaround to generate protos. The
interface may change and the rule may be removed when bazel has introduced
the native rule.
Args:
name: the name of the py_proto_library.
srcs: the .proto files of the py_proto_library.
deps: a list of dependency labels; must be py_proto_library.
py_libs: a list of other py_library targets depended by the generated
py_library.
py_extra_srcs: extra source files that will be added to the output
py_library. This attribute is used for internal bootstrapping.
include: a string indicating the include path of the .proto files.
default_runtime: the implicitly default runtime which will be depended on by
the generated py_library target.
protoc: the label of the protocol compiler to generate the sources.
use_grpc_plugin: a flag to indicate whether to call the Python C++ plugin
when processing the proto files.
**kwargs: other keyword arguments that are passed to py_library.
"""
outs = _PyOuts(srcs, use_grpc_plugin)
includes = []
if include != None:
includes = [include]
grpc_python_plugin = None
if use_grpc_plugin:
grpc_python_plugin = "//external:grpc_python_plugin"
# Note: Generated grpc code depends on Python grpc module. This dependency
# is not explicitly listed in py_libs. Instead, host system is assumed to
# have grpc installed.
proto_gen(
name = name + "_genproto",
srcs = srcs,
deps = [s + "_genproto" for s in deps],
includes = includes,
protoc = protoc,
gen_py = 1,
outs = outs,
visibility = ["//visibility:public"],
plugin = grpc_python_plugin,
plugin_language = "grpc",
)
if default_runtime and not default_runtime in py_libs + deps:
py_libs = py_libs + [default_runtime]
py_library(
name = name,
srcs = outs + py_extra_srcs,
deps = py_libs + deps,
imports = includes,
**kwargs
)
def internal_protobuf_py_tests(
name,
modules = [],
**kwargs):
"""Bazel rules to create batch tests for protobuf internal.
Args:
name: the name of the rule.
modules: a list of modules for tests. The macro will create a py_test for
each of the parameter with the source "google/protobuf/%s.py"
**kwargs: extra parameters that will be passed into the py_test.
"""
for m in modules:
s = "python/google/protobuf/internal/%s.py" % m
py_test(
name = "py_%s" % m,
srcs = [s],
main = s,
**kwargs
)
def check_protobuf_required_bazel_version():
"""For WORKSPACE files, to check the installed version of bazel.
This ensures bazel supports our approach to proto_library() depending on a
copied filegroup. (Fixed in bazel 0.5.4)
"""
expected = apple_common.dotted_version("0.5.4")
current = apple_common.dotted_version(native.bazel_version)
if current.compare_to(expected) < 0:
fail("Bazel must be newer than 0.5.4")
+2
View File
@@ -0,0 +1,2 @@
def protobuf_deps():
pass
+8
View File
@@ -0,0 +1,8 @@
package(default_visibility = ["//visibility:public"])
cc_library(
name = "pybind11",
deps = [
"@xla@xla//third_party/python_runtime:headers",
],
)
+12
View File
@@ -0,0 +1,12 @@
licenses(["notice"]) # BSD/MIT-like license
filegroup(
name = "LICENSE",
visibility = ["//visibility:public"],
)
cc_library(
name = "re2",
linkopts = ["-lre2"],
visibility = ["//visibility:public"],
)
+11
View File
@@ -0,0 +1,11 @@
licenses(["notice"]) # MIT
filegroup(
name = "LICENSE",
visibility = ["//visibility:public"],
)
py_library(
name = "six",
visibility = ["//visibility:public"],
)
+12
View File
@@ -0,0 +1,12 @@
licenses(["notice"]) # BSD 3-Clause
filegroup(
name = "COPYING",
visibility = ["//visibility:public"],
)
cc_library(
name = "snappy",
linkopts = ["-lsnappy"],
visibility = ["//visibility:public"],
)
+15
View File
@@ -0,0 +1,15 @@
licenses(["unencumbered"]) # Public Domain
# Production build of SQLite library that's baked into TensorFlow.
cc_library(
name = "org_sqlite",
linkopts = ["-lsqlite3"],
visibility = ["//visibility:public"],
)
# This is a Copybara sync helper for Google.
py_library(
name = "python",
srcs_version = "PY3",
visibility = ["//visibility:public"],
)
+168
View File
@@ -0,0 +1,168 @@
"""Repository rule for system library autoconfiguration.
`syslibs_configure` depends on the following environment variables:
* `TF_SYSTEM_LIBS`: list of third party dependencies that should use
the system version instead
"""
_TF_SYSTEM_LIBS = "TF_SYSTEM_LIBS"
VALID_LIBS = [
"absl_py",
"astor_archive",
"astunparse_archive",
"boringssl",
"com_github_googlecloudplatform_google_cloud_cpp",
"com_github_grpc_grpc",
"com_google_absl",
"com_google_protobuf",
"com_googlesource_code_re2",
"curl",
"cython",
"dill_archive",
"flatbuffers",
"functools32_archive",
"gast_archive",
"gif",
"hwloc",
"icu",
"jsoncpp_git",
"libjpeg_turbo",
"nasm",
"org_sqlite",
"pasta",
"png",
"pybind11",
"six_archive",
"snappy",
"tblib_archive",
"termcolor_archive",
"typing_extensions_archive",
"wrapt",
"zlib",
]
def auto_configure_fail(msg):
"""Output failure message when syslibs configuration fails."""
red = "\033[0;31m"
no_color = "\033[0m"
fail("\n%sSystem Library Configuration Error:%s %s\n" % (red, no_color, msg))
def _is_windows(repository_ctx):
"""Returns true if the host operating system is windows."""
os_name = repository_ctx.os.name.lower()
if os_name.find("windows") != -1:
return True
return False
def _enable_syslibs(repository_ctx):
s = repository_ctx.os.environ.get(_TF_SYSTEM_LIBS, "").strip()
if not _is_windows(repository_ctx) and s != None and s != "":
return True
return False
def _get_system_lib_list(repository_ctx):
"""Gets the list of deps that should use the system lib.
Args:
repository_ctx: The repository context.
Returns:
A string version of a python list
"""
if _TF_SYSTEM_LIBS not in repository_ctx.os.environ:
return []
libenv = repository_ctx.os.environ[_TF_SYSTEM_LIBS].strip()
libs = []
for lib in list(libenv.split(",")):
lib = lib.strip()
if lib == "":
continue
if lib not in VALID_LIBS:
auto_configure_fail("Invalid system lib set: %s" % lib)
return []
libs.append(lib)
return libs
def _format_system_lib_list(repository_ctx):
"""Formats the list of deps that should use the system lib.
Args:
repository_ctx: The repository context.
Returns:
A list of the names of deps that should use the system lib.
"""
libs = _get_system_lib_list(repository_ctx)
ret = ""
for lib in libs:
ret += "'%s',\n" % lib
return ret
def _tpl(repository_ctx, tpl, substitutions = {}, out = None):
if not out:
out = tpl.replace(":", "")
repository_ctx.template(
out,
Label("//third_party/systemlibs%s.tpl" % tpl),
substitutions,
False,
)
def _create_dummy_repository(repository_ctx):
"""Creates the dummy repository to build with all bundled libraries."""
_tpl(repository_ctx, ":BUILD")
_tpl(
repository_ctx,
":build_defs.bzl",
{
"%{syslibs_enabled}": "False",
"%{syslibs_list}": "",
},
)
def _create_local_repository(repository_ctx):
"""Creates the repository to build with system libraries."""
_tpl(repository_ctx, ":BUILD")
_tpl(
repository_ctx,
":build_defs.bzl",
{
"%{syslibs_enabled}": "True",
"%{syslibs_list}": _format_system_lib_list(repository_ctx),
},
)
def _syslibs_autoconf_impl(repository_ctx):
"""Implementation of the syslibs_configure repository rule."""
if not _enable_syslibs(repository_ctx):
_create_dummy_repository(repository_ctx)
else:
_create_local_repository(repository_ctx)
syslibs_configure = repository_rule(
implementation = _syslibs_autoconf_impl,
environ = [
_TF_SYSTEM_LIBS,
],
)
"""Configures the build to link to system libraries
instead of using bundled versions.
Add the following to your WORKSPACE FILE:
```python
syslibs_configure(name = "local_config_syslibs")
```
Args:
name: A unique name for this workspace rule.
"""
+12
View File
@@ -0,0 +1,12 @@
licenses(["notice"]) # BSD 3-clause
filegroup(
name = "LICENSE",
visibility = ["//visibility:public"],
)
py_library(
name = "tblib",
srcs_version = "PY3",
visibility = ["//visibility:public"],
)
+16
View File
@@ -0,0 +1,16 @@
# Description:
# Backports for the typing module to older Python versions. See
# https://github.com/python/typing/blob/master/typing_extensions/README.rst
licenses(["notice"]) # PSF
py_library(
name = "typing_extensions",
srcs_version = "PY3",
visibility = ["//visibility:public"],
)
filegroup(
name = "LICENSE",
visibility = ["//visibility:public"],
)
+4
View File
@@ -0,0 +1,4 @@
py_library(
name = "wrapt",
visibility = ["//visibility:public"],
)
+12
View File
@@ -0,0 +1,12 @@
licenses(["notice"]) # BSD/MIT-like license (for zlib)
filegroup(
name = "zlib.h",
visibility = ["//visibility:public"],
)
cc_library(
name = "zlib",
linkopts = ["-lz"],
visibility = ["//visibility:public"],
)