Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The compile_data attribute can now be gathered from dependencies #814

Merged
merged 8 commits into from
Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions proto/proto.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def _rust_proto_compile(protos, descriptor_sets, imports, crate_name, ctx, is_gr
edition = proto_toolchain.edition,
rustc_env = {},
is_test = False,
compile_data = depset([target.files for target in getattr(ctx.attr, "compile_data", [])]),
wrapped_crate_type = None,
),
output_hash = output_hash,
Expand Down
3 changes: 2 additions & 1 deletion rust/private/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CrateInfo = provider(
doc = "A provider containing general Crate information.",
fields = {
"aliases": "Dict[Label, String]: Renamed and aliased crates",
"compile_data": "depset[File]: Compile data required by this crate.",
"deps": "depset[Provider]: This crate's (rust or cc) dependencies' providers.",
"edition": "str: The edition of this crate.",
"is_test": "bool: If the crate is being compiled in a test context",
Expand All @@ -39,7 +40,7 @@ DepInfo = provider(
doc = "A provider containing information about a Crate's dependencies.",
fields = {
"dep_env": "File: File with environment variables direct dependencies build scripts rely upon.",
"direct_crates": "depset[CrateInfo]",
"direct_crates": "depset[AliasableDepInfo]",
"transitive_build_infos": "depset[BuildInfo]",
"transitive_crates": "depset[CrateInfo]",
"transitive_libs": "List[File]: All transitive dependencies, not filtered by type.",
Expand Down
4 changes: 4 additions & 0 deletions rust/private/rust.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def _rust_library_common(ctx, crate_type):
edition = get_edition(ctx.attr, toolchain),
rustc_env = ctx.attr.rustc_env,
is_test = False,
compile_data = depset(ctx.files.compile_data),
UebelAndre marked this conversation as resolved.
Show resolved Hide resolved
),
output_hash = output_hash,
)
Expand Down Expand Up @@ -301,6 +302,7 @@ def _rust_binary_impl(ctx):
edition = get_edition(ctx.attr, toolchain),
rustc_env = ctx.attr.rustc_env,
is_test = False,
compile_data = depset(ctx.files.compile_data),
),
)

Expand Down Expand Up @@ -418,6 +420,7 @@ def _rust_test_common(ctx, toolchain, output):
edition = crate.edition,
rustc_env = ctx.attr.rustc_env,
is_test = True,
compile_data = depset(crate.compile_data),
wrapped_crate_type = crate.type,
)
else:
Expand All @@ -434,6 +437,7 @@ def _rust_test_common(ctx, toolchain, output):
edition = get_edition(ctx.attr, toolchain),
rustc_env = ctx.attr.rustc_env,
is_test = True,
compile_data = depset(ctx.files.compile_data),
)

providers = rustc_compile_action(
Expand Down
4 changes: 2 additions & 2 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def collect_inputs(
Args:
ctx (ctx): The rule's context object.
file (struct): A struct containing files defined in label type attributes marked as `allow_single_file`.
files (list): A list of all inputs.
files (list): A list of all inputs (`ctx.files`).
toolchain (rust_toolchain): The current `rust_toolchain`.
cc_toolchain (CcToolchainInfo): The current `cc_toolchain`.
crate_info (CrateInfo): The Crate information of the crate to process build scripts for.
Expand All @@ -283,7 +283,6 @@ def collect_inputs(

compile_inputs = depset(
getattr(files, "data", []) +
getattr(files, "compile_data", []) +
[toolchain.rustc] +
toolchain.crosstool_files +
([build_info.rustc_env, build_info.flags] if build_info else []) +
Expand All @@ -294,6 +293,7 @@ def collect_inputs(
linker_depset,
crate_info.srcs,
dep_info.transitive_libs,
crate_info.compile_data,
],
)
build_env_files = getattr(files, "rustc_env_files", [])
Expand Down
14 changes: 14 additions & 0 deletions test/compile_data/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
load("//rust:defs.bzl", "rust_library", "rust_test")

# Note that this is the only target which assigns the `compile_data` attribute
rust_library(
name = "compile_data",
srcs = ["compile_data.rs"],
compile_data = ["compile_data.txt"],
edition = "2018",
)

rust_test(
name = "compile_data_unit_test",
crate = ":compile_data",
)
9 changes: 9 additions & 0 deletions test/compile_data/compile_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// Data loaded from compile data
pub const COMPILE_DATA: &str = include_str!("compile_data.txt");

/// A test that is expected to be compiled from a target that does not
/// directly populate the `compile_data` attribute
#[test]
UebelAndre marked this conversation as resolved.
Show resolved Hide resolved
fn test_compile_data_contents() {
assert_eq!(COMPILE_DATA, "compile data contents\n");
}
1 change: 1 addition & 0 deletions test/compile_data/compile_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
compile data contents