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

compile_data does not work together with generated sources #3171

Open
martingms opened this issue Jan 8, 2025 · 0 comments · May be fixed by #3176
Open

compile_data does not work together with generated sources #3171

martingms opened this issue Jan 8, 2025 · 0 comments · May be fixed by #3176
Labels

Comments

@martingms
Copy link

When using generated srcs and non-generated compile_data in the same rust_library target, the non-generated srcs are symlinked into the out-tree for the build, but the same is not done for non-generated compile_data, so the files are not available for include_str! or whatever.

Here's a patch that reproduces this within the existing compile_data tests:

diff --git a/test/unit/compile_data/compile_data.rs b/test/unit/compile_data/compile_data.rs
index 26f060e0..ddc8fabd 100644
--- a/test/unit/compile_data/compile_data.rs
+++ b/test/unit/compile_data/compile_data.rs
@@ -1,6 +1,8 @@
 /// Data loaded from compile data
 pub const COMPILE_DATA: &str = include_str!("compile_data.txt");
 
+mod generated;
+
 #[cfg(test)]
 mod test {
     use super::*;
@@ -23,4 +25,9 @@ mod test {
             assert_eq!(TEST_COMPILE_DATA.trim_end(), "test compile data contents");
         }
     }
+
+    #[test]
+    fn test_generated() {
+        assert_eq!(generated::GENERATED, "generated");
+    }
 }
diff --git a/test/unit/compile_data/compile_data_test.bzl b/test/unit/compile_data/compile_data_test.bzl
index cd0eb7f2..383ea65c 100644
--- a/test/unit/compile_data/compile_data_test.bzl
+++ b/test/unit/compile_data/compile_data_test.bzl
@@ -61,9 +61,15 @@ wrapper_rule_propagates_and_joins_compile_data_test = analysistest.make(_wrapper
 compile_data_propagates_to_rust_doc_test = analysistest.make(_compile_data_propagates_to_rust_doc_test_impl)
 
 def _define_test_targets():
+    native.genrule(
+        name = "generated_src",
+        outs = ["generated.rs"],
+        cmd = """echo 'const GENERATED: &str = "generated";' > $@""",
+    )
+
     rust_library(
         name = "compile_data",
-        srcs = ["compile_data.rs"],
+        srcs = ["compile_data.rs", ":generated.rs"],
         compile_data = ["compile_data.txt"],
         edition = "2018",
     )

This is possible to work around by using genrule or similar to copy the files in compile_data to make it "generated", but this does not seem ideal.

@UebelAndre UebelAndre added the bug label Jan 8, 2025
martingms added a commit to martingms/rules_rust that referenced this issue Jan 9, 2025
@martingms martingms linked a pull request Jan 9, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants