Rust environment build caching doesn't work with monorepos

Recently my rust builds have jumped from <1 min per build to >5 minutes per build. Consulting the logs, I can see that every dependency is getting re-built every time, even though they should be hitting the build cache.

Has something changed in the rust environment?

Update: Running “Clear build cache & deploy” does not fix the situation.

Hey @samuela, it may be that your repo structure may differ from what we expect. We’re caching any target directory at your repo root. I’ll see if we have any changes in the works to more effectively cache in those situations.

My rust project is in a subdirectory called api, so that would explain it. Is there a way to specify where the target directory lives?

I guess my builds have just always been slow but I never really noticed before.

I think we can add some intelligence on our side to handle subdirectories (and monorepos, really) more gracefully. I’m raise this for prioritization.

In the meantime, I think you can specify to Cargo a different target directory. You can do this with an environment variable CARGO_TARGET_DIR or add a --target-dir to your build and run commands. I think the latter is probably ideal in this case so that you can make use of relative directories. If your commands are cargo build ... and cargo run ..., then try adding --target-dir . after build and run.

Thanks, I’ll give that a shot!