Skip to content

Commit

Permalink
Consider compile_data when deciding if sources are generated
Browse files Browse the repository at this point in the history
This fixes issue where generated compile_data didn't work in some cases.
  • Loading branch information
martingms committed Jan 9, 2025
1 parent 749a0ec commit 03dacc4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rust/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions test/unit/compile_data/compile_data_gen.rs
Original file line number Diff line number Diff line change
@@ -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");
}
}
18 changes: 18 additions & 0 deletions test/unit/compile_data/compile_data_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down

0 comments on commit 03dacc4

Please sign in to comment.