Skip to content

Commit f4cbea5

Browse files
authored
Added rust_common.create_crate_info (#818)
* Added `rust_common.create_crate_info` * Updated docs
1 parent 19c74ce commit f4cbea5

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

proto/proto.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
222222
ctx = ctx,
223223
toolchain = find_toolchain(ctx),
224224
crate_type = "rlib",
225-
crate_info = rust_common.crate_info(
225+
crate_info = rust_common.create_crate_info(
226226
name = crate_name,
227227
type = "rlib",
228228
root = lib_rs,

rust/private/common.bzl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,22 @@ In the Bazel lingo, `rust_common` gives the access to the Rust Sandwich API.
2525

2626
load(":providers.bzl", "CrateInfo", "DepInfo")
2727

28+
def _create_crate_info(**kwargs):
29+
"""A constructor for a `CrateInfo` provider
30+
31+
This function should be used in place of directly creating a `CrateInfo`
32+
provider to improve API stability.
33+
34+
Args:
35+
**kwargs: An inital set of keyword arguments.
36+
37+
Returns:
38+
CrateInfo: A provider
39+
"""
40+
return CrateInfo(**kwargs)
41+
2842
rust_common = struct(
43+
create_crate_info = _create_crate_info,
2944
crate_info = CrateInfo,
3045
dep_info = DepInfo,
3146
)

rust/private/rust.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def _rust_library_common(ctx, crate_type):
254254
ctx = ctx,
255255
toolchain = toolchain,
256256
crate_type = crate_type,
257-
crate_info = rust_common.crate_info(
257+
crate_info = rust_common.create_crate_info(
258258
name = crate_name,
259259
type = crate_type,
260260
root = crate_root,
@@ -289,7 +289,7 @@ def _rust_binary_impl(ctx):
289289
ctx = ctx,
290290
toolchain = toolchain,
291291
crate_type = ctx.attr.crate_type,
292-
crate_info = rust_common.crate_info(
292+
crate_info = rust_common.create_crate_info(
293293
name = crate_name,
294294
type = ctx.attr.crate_type,
295295
root = crate_root_src(ctx.attr, ctx.files.srcs, ctx.attr.crate_type),
@@ -406,7 +406,7 @@ def _rust_test_common(ctx, toolchain, output):
406406
# Target is building the crate in `test` config
407407
# Build the test binary using the dependency's srcs.
408408
crate = ctx.attr.crate[rust_common.crate_info]
409-
crate_info = rust_common.crate_info(
409+
crate_info = rust_common.create_crate_info(
410410
name = crate_name,
411411
type = crate_type,
412412
root = crate.root,
@@ -421,7 +421,7 @@ def _rust_test_common(ctx, toolchain, output):
421421
)
422422
else:
423423
# Target is a standalone crate. Build the test binary as its own crate.
424-
crate_info = rust_common.crate_info(
424+
crate_info = rust_common.create_crate_info(
425425
name = crate_name,
426426
type = crate_type,
427427
root = crate_root_src(ctx.attr, ctx.files.srcs, "lib"),

0 commit comments

Comments
 (0)