file does not work

I am trying to generate version hash of every build from git hash but unfortunately I cannot get file working.
For testing purposes I just put a println!() inside the main function in the but I never see the log before builds. Am I doing something wrong ?

Would you mind providing us with some more information/code about your current circumstance?

I have created a file called on the project root which has only
fn main(){println!("testing")} written in. I've also added build = "" in my Cargo.toml file
before every build I expect to see "testing" printed on the console but there's nothing

I’ve found that adding the line in the Cargo.toml isn’t always needed, as long as there is a file with a fn main().
About the output of the build script, don't try to test output with a println. Other cargo functions like test and build (Specifically block terminal output, and don't print it out. So, when testing things like these, panic instead. If you do panic, you will end up with a compilation error, meaning that it's actually been run.
Read more on output here

Thanks panicking was the way to go for testing

Don't use it in a regular production build though :sweat_smile: (As in something you do every build)

:slight_smile: I just wanted to see if it works :smiley: I will use it to generate the version string than include it during build in the main file

1 Like


cargo build -vv

Do you know that cargo run script by default only when file is changed?
So if you edit or and then run cargo build then cargo doesn't run, because of there is no changes in

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.