Stream: t-compiler/wg-rls-2.0

Topic: How to get `Out-Dir`


Edwin Cheng (Mar 08 2020 at 18:52, on Zulip):

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 ?

matklad (Mar 08 2020 at 18:59, on Zulip):

Yeah, I think we need to run cargo-check. Id started though with many
just a way to manually specify OUT_DIR via config?

Christopher Durham (Mar 08 2020 at 19:10, on Zulip):

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

Christopher Durham (Mar 08 2020 at 19:11, on Zulip):

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.

matklad (Mar 08 2020 at 19:23, on Zulip):

I believe cargo replaces cached output of build.rs

Christopher Durham (Mar 08 2020 at 19:24, on Zulip):

Correct, if the inputs to build.rs are not changed, cargo won't rerun the build.rs

Christopher Durham (Mar 08 2020 at 19:26, on Zulip):

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:

Christopher Durham (Mar 08 2020 at 19:31, on Zulip):

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.

Christopher Durham (Mar 08 2020 at 19:35, on Zulip):

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

Christopher Durham (Mar 08 2020 at 19:36, on Zulip):

But the current way it's accessible is purely through the build-script-executed message IIUC.

Christopher Durham (Mar 08 2020 at 19:38, on Zulip):

And ofc 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.

Edwin Cheng (Mar 08 2020 at 19:49, on Zulip):

@matklad Sound reasonable. I would start from config.

Christopher Durham (Mar 08 2020 at 19:50, on Zulip):

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?

Edwin Cheng (Mar 08 2020 at 19:52, on Zulip):

I remember IntelliJ use build-plan ?

matklad (Mar 08 2020 at 19:55, on Zulip):

Ah, sorry for typo. Cargo replays build output of cached bulid scripts: https://gist.github.com/matklad/a685495d4f67a17b62b29ac278af1afa

Last update: Sep 30 2020 at 16:30UTC