diff --git a/rust/private/rust.bzl b/rust/private/rust.bzl index 17131c6b9e..e0088a1092 100644 --- a/rust/private/rust.bzl +++ b/rust/private/rust.bzl @@ -138,6 +138,10 @@ def _shortest_src_with_basename(srcs, basename): def _rust_library_impl(ctx): """The implementation of the `rust_library` rule. + This rule provides CcInfo, so it can be used everywhere Bazel + expects rules_cc, but care must be taken to have the correct + dependencies on an allocator and std implemetation as needed. + Args: ctx (ctx): The rule's context object @@ -149,6 +153,9 @@ def _rust_library_impl(ctx): def _rust_static_library_impl(ctx): """The implementation of the `rust_static_library` rule. + This rule provides CcInfo, so it can be used everywhere Bazel + expects rules_cc. + Args: ctx (ctx): The rule's context object @@ -160,6 +167,9 @@ def _rust_static_library_impl(ctx): def _rust_shared_library_impl(ctx): """The implementation of the `rust_shared_library` rule. + This rule provides CcInfo, so it can be used everywhere Bazel + expects rules_cc. + Args: ctx (ctx): The rule's context object @@ -643,8 +653,8 @@ _rust_test_attrs = { "env": attr.string_dict( mandatory = False, doc = _tidy(""" - Specifies additional environment variables to set when the test is executed by bazel test. - Values are subject to `$(execpath)` and + Specifies additional environment variables to set when the test is executed by bazel test. + Values are subject to `$(execpath)` and ["Make variable"](https://docs.bazel.build/versions/master/be/make-variables.html) substitution. """), ), diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index aa2df0569f..26490cbd6c 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -632,7 +632,7 @@ def rustc_compile_action( ] def establish_cc_info(ctx, crate_info, toolchain, cc_toolchain, feature_configuration): - """If the produced crate is suitable yield a CcInfo to allow for interop with cc rules + """If the produced crate is suitable yield a CcInfo to allow for interop with cc rules Args: ctx (ctx): The rule's context object @@ -645,7 +645,7 @@ def establish_cc_info(ctx, crate_info, toolchain, cc_toolchain, feature_configur list: A list containing the CcInfo provider """ - if crate_info.is_test or crate_info.type not in ("staticlib", "cdylib") or getattr(ctx.attr, "out_binary", False): + if crate_info.is_test or crate_info.type not in ("staticlib", "cdylib", "rlib", "lib") or getattr(ctx.attr, "out_binary", False): return [] if crate_info.type == "staticlib": @@ -655,6 +655,20 @@ def establish_cc_info(ctx, crate_info, toolchain, cc_toolchain, feature_configur cc_toolchain = cc_toolchain, static_library = crate_info.output, ) + elif crate_info.type in ("rlib", "lib"): + # bazel hard-codes a check for endswith((".a", ".pic.a", + # ".lib")) in create_library_to_link, so we work around that + # by creating a symlink to the .rlib with a .a extension. + dot_a = ctx.actions.declare_file(crate_info.name + ".a", sibling = crate_info.output) + ctx.actions.symlink(output = dot_a, target_file = crate_info.output) + # TODO(hlopko): handle PIC/NOPIC correctly + library_to_link = cc_common.create_library_to_link( + actions = ctx.actions, + feature_configuration = feature_configuration, + cc_toolchain = cc_toolchain, + static_library = dot_a, + pic_static_library = dot_a, + ) elif crate_info.type == "cdylib": library_to_link = cc_common.create_library_to_link( actions = ctx.actions,