diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl index e95989682d..9b1efb0a38 100644 --- a/rust/private/utils.bzl +++ b/rust/private/utils.bzl @@ -811,7 +811,11 @@ def transform_sources(ctx, srcs, compile_data, crate_root): Tuple(List[File], List[File], File): The transformed srcs, compile_data and crate_root """ - has_generated_sources = len([src for src in srcs if not src.is_source]) > 0 + has_generated_sources = ( + len([src for src in srcs if not src.is_source]) + + len([src for src in compile_data if not src.is_source]) + > 0 + ) if not has_generated_sources: return srcs, compile_data, crate_root diff --git a/test/unit/compile_data/compile_data_gen.rs b/test/unit/compile_data/compile_data_gen.rs new file mode 100644 index 0000000000..e6dccc823f --- /dev/null +++ b/test/unit/compile_data/compile_data_gen.rs @@ -0,0 +1,12 @@ +/// Data loaded from generated compile data +pub const COMPILE_DATA: &str = include_str!("generated.txt"); + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn test_compile_data_contents() { + assert_eq!(COMPILE_DATA.trim_end(), "generated compile data contents"); + } +} diff --git a/test/unit/compile_data/compile_data_test.bzl b/test/unit/compile_data/compile_data_test.bzl index d4159a38c6..e4af703513 100644 --- a/test/unit/compile_data/compile_data_test.bzl +++ b/test/unit/compile_data/compile_data_test.bzl @@ -95,6 +95,24 @@ def _define_test_targets(): crate = ":compile_data_env", ) + native.genrule( + name = "generated_compile_data", + outs = ["generated.txt"], + cmd = "echo 'generated compile data contents' > $@", + ) + + rust_library( + name = "compile_data_gen", + srcs = ["compile_data_gen.rs"], + compile_data = [":generated.txt"], + edition = "2021", + ) + + rust_test( + name = "compile_data_gen_unit_test", + crate = ":compile_data_gen", + ) + native.genrule( name = "generated_src", outs = ["generated.rs"],