Hacky way to copy files from build.rs/OUT_DIR?


  1. I am using prost_build. It generates a helloworld.rs from helloworld.proto
  2. I include this helloworld.rs into my Rust project via
pub mod hello_world {
    include!(concat!(env!("OUT_DIR"), "/helloworld.rs"));
  1. Everything compiles fine.

  2. The only problem is that IntelliJ auto completion can't jump into OUT_DIR/helloworld.rs

  3. I'm wondering if there is a hacky way to always copy the file into proj/src/out/helloworld.rs (basically if the file is under proj/src/..., IntelliJ is going to work).


To a hard coded path? Does this work well if the crate is packaged as a library ?

I would not mind a cargo command that I invoked manually and which copies the file from concat!(env!("OUT_DIR"), "/helloworld.rs") but it is not clear to me how to access OUT_DIR in a shell script.

Given the personal editor nature of the question, and the hacky qualifier, I wasn't really considering portability.

Another problem with this approach is that in the target entries, I have three helloworld.rs:


Right now, I think the compilation process is:

cargo build execution ==

  1. build.rs
  2. tries to compile my code

I would like to have a file manual-build.rs, which (1) cargo build does not call and (2) I can manually call on my own.

So something like prost_build - Rust , but instead of being called from build.rs , I call manually and specify where the OUTPUT goes to.

rust-protobuf/protobuf-codegen at master · stepancheg/rust-protobuf · GitHub seems to work.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.