In cargo#7622, @matklad introduce a new build-script-executed JSON message
out-dir. However, calling
cargo metadatasolely will not include these data because they are compiler-messages. So do we want to run
cargo check at RA server start up to get these messages explicitly? Or there are some magical sub-command in cargo which would build the build-scripts only, but not all deps ?
Yeah, I think we need to run
cargo-check. Id started though with many
just a way to manually specify
OUT_DIR via config?
Or there are some magical sub-command in cargo which would build the build-scripts only, but not all deps ?
@matklad has an issue currently open for approximately that https://github.com/rust-lang/cargo/issues/7178
This is actually a pretty interesting question when you get into it:
cargo check on an existing workspace (i.e. one that hasn't been cleaned) _won't recompile (recheck) dependencies_. So you won't even get to run dependencies' build scripts to get the build-script-executed message.
I believe cargo replaces cached output of build.rs
I think the "best user experience" would be to have a persistent cache of dependencies' OUT_DIR to avoid the need to re-run build scripts on project load. Roughly:
If cache is present:
If OUT_DIR exists:
Compilation cache has been cleared since last project launch.
If cache is not present (or was just deleted):
Here's the docs for buildscript rerun-if-changed. TL;DR: by default, buildscripts rerun if any file "in the package" changes. The buildscript can, however, request to be rerun on any closed set of file changes and any set of (non-cargo) environment variables.
There's also the issue I opened that's still open for adding OUT_DIR information to
cargo metadata: https://github.com/rust-lang/cargo/issues/7546
But the current way it's accessible is purely through the build-script-executed message IIUC.
cargo metadata has less information than an actual build, so it can't really know the correct
OUT_DIR (currently?) relies on target-specific information.
@matklad Sound reasonable. I would start from config.
Relevant snippets from IntelliJ IDEA:
On the "fetch and index dependencies" step, if the "run build scripts" experimental feature is enabled, run
cargo check on the project and extract build script json outputs https://github.com/intellij-rust/intellij-rust/blob/8b3c4edc66774d3c94dfced742febfb23c56a706/src/main/kotlin/org/rust/cargo/toolchain/Cargo.kt#L94-L165
If I'm not mistaken that means that it doesn't actually get dependency build scripts if they've already been cached. However, I think this isn't a problem for IntelliJ Rust because I think IDEA caches indexing information?
I remember IntelliJ use build-plan ?
Ah, sorry for typo. Cargo replays build output of cached bulid scripts: https://gist.github.com/matklad/a685495d4f67a17b62b29ac278af1afa