Skip to content

Commit 9a137c3

Browse files
authored
Updated CrateInfo.data documentation (#3978)
Update documentation and add some testing for future clarification.
1 parent 82506df commit 9a137c3

5 files changed

Lines changed: 54 additions & 3 deletions

File tree

rust/private/providers.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ CrateInfo = provider(
2424
),
2525
"compile_data": "depset[File]: Compile data required by this crate.",
2626
"compile_data_targets": "depset[Label]: Compile data targets required by this crate.",
27-
"data": "depset[File]: Compile data required by crates that use the current crate as a proc-macro.",
28-
"deps": "depset[DepVariantInfo]: This crate's (rust or cc) dependencies' providers.",
27+
"data": "depset[File]: Runtime data associated with the target. Not passed to `Rustc` actions, except for `proc-macro` targets where `Rustc` is the runtime.",
28+
"deps": "depset[DepVariantInfo]: This crate's direct (rust or cc) dependencies' providers.",
2929
"edition": "str: The edition of this crate.",
3030
"is_test": "bool: If the crate is being compiled in a test context",
3131
"metadata": "File: The output from rustc from producing the output file. It is optional.",

test/unit/compile_data/compile_data_test.bzl

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
load("@bazel_skylib//lib:unittest.bzl", "analysistest", "asserts")
44
load("@bazel_skylib//rules:write_file.bzl", "write_file")
5-
load("//rust:defs.bzl", "rust_common", "rust_doc", "rust_library", "rust_test")
5+
load("//rust:defs.bzl", "rust_common", "rust_doc", "rust_library", "rust_proc_macro", "rust_test")
66
load(
77
"//test/unit:common.bzl",
88
"assert_action_mnemonic",
@@ -102,6 +102,27 @@ def _transitive_compile_data_not_in_compile_inputs_test_impl(ctx):
102102

103103
return analysistest.end(env)
104104

105+
def _proc_macro_data_in_compile_inputs_test_impl(ctx):
106+
env = analysistest.begin(ctx)
107+
target = analysistest.target_under_test(env)
108+
109+
rustc_action = None
110+
for action in target.actions:
111+
if action.mnemonic == "Rustc":
112+
rustc_action = action
113+
break
114+
115+
asserts.false(env, rustc_action == None, "Expected a Rustc action")
116+
117+
data_inputs = [i for i in rustc_action.inputs.to_list() if "proc_macro_data_dep.txt" in i.path]
118+
asserts.true(
119+
env,
120+
len(data_inputs) > 0,
121+
"Expected proc-macro data dep file to appear in Rustc action inputs, but it was not found",
122+
)
123+
124+
return analysistest.end(env)
125+
105126
def _data_propagates_to_runfiles_test_impl(ctx):
106127
env = analysistest.begin(ctx)
107128
target = analysistest.target_under_test(env)
@@ -124,6 +145,7 @@ wrapper_rule_propagates_and_joins_compile_data_test = analysistest.make(_wrapper
124145
compile_data_propagates_to_rust_doc_test = analysistest.make(_compile_data_propagates_to_rust_doc_test_impl)
125146
transitive_data_not_in_compile_inputs_test = analysistest.make(_transitive_data_not_in_compile_inputs_test_impl)
126147
transitive_compile_data_not_in_compile_inputs_test = analysistest.make(_transitive_compile_data_not_in_compile_inputs_test_impl)
148+
proc_macro_data_in_compile_inputs_test = analysistest.make(_proc_macro_data_in_compile_inputs_test_impl)
127149
data_propagates_to_runfiles_test = analysistest.make(_data_propagates_to_runfiles_test_impl)
128150

129151
def _define_test_targets():
@@ -269,6 +291,20 @@ def _define_test_targets():
269291
edition = "2021",
270292
)
271293

294+
rust_proc_macro(
295+
name = "proc_macro_with_data",
296+
srcs = ["proc_macro_with_data.rs"],
297+
data = ["proc_macro_data_dep.txt"],
298+
edition = "2021",
299+
)
300+
301+
rust_library(
302+
name = "lib_depending_on_proc_macro",
303+
srcs = ["lib_depending_on_proc_macro.rs"],
304+
proc_macro_deps = [":proc_macro_with_data"],
305+
edition = "2021",
306+
)
307+
272308
def compile_data_test_suite(name):
273309
"""Entry-point macro called from the BUILD file.
274310
@@ -313,6 +349,11 @@ def compile_data_test_suite(name):
313349
target_under_test = ":lib_depending_on_data",
314350
)
315351

352+
proc_macro_data_in_compile_inputs_test(
353+
name = "proc_macro_data_in_compile_inputs_test",
354+
target_under_test = ":lib_depending_on_proc_macro",
355+
)
356+
316357
native.test_suite(
317358
name = name,
318359
tests = [
@@ -323,5 +364,6 @@ def compile_data_test_suite(name):
323364
":transitive_data_not_in_compile_inputs_test",
324365
":transitive_compile_data_not_in_compile_inputs_test",
325366
":data_propagates_to_runfiles_test",
367+
":proc_macro_data_in_compile_inputs_test",
326368
],
327369
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn hello() {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
proc macro data dep
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extern crate proc_macro;
2+
use proc_macro::TokenStream;
3+
4+
#[proc_macro]
5+
pub fn noop(_item: TokenStream) -> TokenStream {
6+
TokenStream::new()
7+
}

0 commit comments

Comments
 (0)