Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions rs_bindings_from_cc/bazel_support/compile_rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _get_cc_info(providers):
return provider
fail("Couldn't find a CcInfo in the list of providers")

def compile_rust(ctx, attr, src, extra_srcs, deps, crate_name, include_coverage, force_all_deps_direct, allow_lto = True):
def compile_rust(ctx, attr, src, extra_srcs, deps, crate_name, include_coverage, force_all_deps_direct, allow_lto = True, aliases = {}):
"""Compiles a Rust source file.

Args:
Expand All @@ -57,6 +57,7 @@ def compile_rust(ctx, attr, src, extra_srcs, deps, crate_name, include_coverage,
include_coverage: (bool) Whether or not coverage information should be generated.
force_all_deps_direct: (bool) Whether or not to force all deps to be direct.
allow_lto: (bool, optional) Whether to allow LTO
aliases: (dict, optional) A dict of aliases to be passed to the rustc_compile_action.

Returns:
A DepVariantInfo provider.
Expand Down Expand Up @@ -103,7 +104,7 @@ def compile_rust(ctx, attr, src, extra_srcs, deps, crate_name, include_coverage,
srcs = srcs,
deps = deps.to_list(),
proc_macro_deps = [],
aliases = {},
aliases = aliases,
output = lib,
metadata = rmeta,
edition = "2018",
Expand Down
19 changes: 7 additions & 12 deletions rs_bindings_from_cc/bazel_support/rust_bindings_from_cc_aspect.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ load(
"generate_and_compile_bindings",
)
load("@protobuf//rust:aspects.bzl", "RustProtoInfo", "rust_cc_proto_library_aspect")
load(
"@protobuf//rust/bazel:encode_raw_string_as_crate_name.bzl",
"encode_raw_string_as_crate_name",
)

# <internal link>/127#naming-header-files-h-and-inc recommends declaring textual headers either in the
# `textual_hdrs` attribute of the Bazel C++ rules, or using the `.inc` file extension. Therefore
Expand Down Expand Up @@ -281,6 +285,7 @@ def _rust_bindings_from_cc_aspect_impl(target, ctx):

extra_rs_srcs = []
extra_deps = []
aliases = {}

# Headers for which we will produce bindings.
public_hdrs = []
Expand All @@ -292,18 +297,6 @@ def _rust_bindings_from_cc_aspect_impl(target, ctx):
elif ctx.rule.kind == "cc_embed_data" or ctx.rule.kind == "upb_proto_library":
public_hdrs = target[CcInfo].compilation_context.direct_public_headers

elif ctx.rule.kind == "cc_stubby_library":
public_hdrs = target[CcInfo].compilation_context.direct_public_headers
extra_rule_specific_deps = ctx.rule.attr.implicit_cc_deps

if not AdditionalRustSrcsProviderInfo in target:
fail("cc_stubby_library must provide AdditionalRustSrcsProviderInfo")

additional_provider = target[AdditionalRustSrcsProviderInfo]

extra_rs_srcs.extend(_get_additional_rust_srcs_from_provider(additional_provider))
extra_deps.extend(_get_additional_rust_deps_from_provider(additional_provider))

has_public_headers = len(public_hdrs) > 0
if not has_public_headers:
# This target doesn't have public headers, so there are no bindings to generate. However we
Expand Down Expand Up @@ -388,6 +381,7 @@ def _rust_bindings_from_cc_aspect_impl(target, ctx):
should_generate_bindings = (
has_public_headers or extra_rs_srcs
) and not _is_cc_proto_library(target),
aliases = aliases,
)

rust_bindings_from_cc_aspect = aspect(
Expand All @@ -399,6 +393,7 @@ rust_bindings_from_cc_aspect = aspect(
"_cc_lib",
# for cc_stubby_library implicit deps
"implicit_cc_deps",
"implicit_rust_deps",
],
requires = [rust_cc_proto_library_aspect],
required_aspect_providers = [CcInfo],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def generate_and_compile_bindings(
deps_for_rs_file,
extra_cc_compilation_action_inputs = [],
extra_rs_bindings_from_cc_cli_flags = [],
should_generate_bindings = True):
should_generate_bindings = True,
aliases = {}):
"""Runs the bindings generator.

Args:
Expand All @@ -66,6 +67,7 @@ def generate_and_compile_bindings(
should_generate_bindings: Whether this target should get actual bindings generated
(for example because it has public headers), or it should only propagate its metadata
(for example when the bindings are generated by protoc).
aliases: (dict, optional) A dict of aliases to be passed to the rustc_compile_action.
Returns:
A RustBindingsFromCcInfo containing the result of the compilation of the generated source
files, as well a GeneratedBindingsInfo provider containing the generated source files.
Expand Down Expand Up @@ -165,6 +167,7 @@ def generate_and_compile_bindings(
include_coverage = False,
force_all_deps_direct = True,
allow_lto = False,
aliases = aliases,
)

return [
Expand Down