[Build Script] Use local module from generated file?

Howdy,

I have a simple project that generates code from a grammar file. The first brace-enclosed block in that file is some rust code that is being injected verbatim into the generated Rust file. I want to move that code to a module adjacent to the grammar file and replace it with a directive to use that module. But the naïve approach makes Rust look for the module in the build script's OUT_DIR, i.e. next to the file that was generated. Is there a way to do what I want without copying or linking that file into OUT_DIR?

Thanks in advance!

If you move the Rust code to, say, src/foo.rs in your package's source, then a file generated in OUT_DIR[1] can access its contents via use crate::foo::{insert, names, here};.


  1. Assuming it's include!()'d by another Rust file, of course ↩︎

That's what I did, as far as I can tell. I put it in parse_support.rs right next to src/main.rs. Oddly, LSP is telling me the file isn't included anywhere in the module tree, and of course,

   Compiling rsdparsing v0.1.0 (/Users/dave/src/rsdparsing)
error[E0432]: unresolved import `crate::parse_support`
 --> /Users/dave/src/rsdparsing/target/debug/build/rsdparsing-092f260092059bcd/out/actions.rs:9:16
  |
9 |     use crate::parse_support::{GlobalsStruct};
  |                ^^^^^^^^^^^^^ could not find `parse_support` in the crate root

I was missinig pub mod parse_support; in main.rs. I don't really understand how modules work in Rust, clearly.