Why does my program build when I change a config file

A new phenomenon is driving me crazy. I have a program that reads a config file containing JSON. Until recently, I could edit the config file and rerun my program without it building. Now it builds on every edit. That's not much of a problem, but the 20 seconds or so it takes to build seems like an eternity compared to the earlier behavior.

The problem occurs with "cargo run" from the command line on a Mac running cargo 1.37.0. The only change I can think of was adding the config file to my github repository.

That's certainly an odd behavior. Can you try exporting out of git to see if it persists?

Shot in the dark here, but are you using any GUI git frontend or virtual git filesystem or anything that could be making the modification dates change unexpectedly?

Nope. The problem first showed up when running from IntelliJ. That's when I tried running it from from a terminal window with the same behavior.

Huh. What's the config file being used for? If it's consumed by a build.rs file, for example, it would trigger a rebuild. If it's just a file your program is loading at runtime, this is surprising behavior.

It's a data file read in main().

Could you create a minimal reproducible example for further investigate?

Here's a clue.

    pub static ref CONFIG: Config = Config::new().unwrap();


impl Config {
    pub fn new() -> Result<Config, Error> {
        let config_file_name = args()
        let config_file = OpenOptions::new()
        let config: Config = serde_json::from_reader(config_file)?;

Am I too clever for my own good?

No idea!

I think you should have a minimal reproducible example that people just copy/paste (or git clone) then cargo run to reproduce the problem.

Do you have a build.rs at all? If you do, then cargo defaults to rebuilding if any file in your project changes (because it doesn't know which ones the build script might read). The build.rs can output cargo:rerun-if-changed lines to override this default.

1 Like

Thanks. That was the problem. It now works as expected from the console. Now all I have to do is figure out how to make it work from IntelliJ.

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