Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo metadata: get build script OUT_DIR #7546

Open
CAD97 opened this issue Oct 28, 2019 · 3 comments
Open

cargo metadata: get build script OUT_DIR #7546

CAD97 opened this issue Oct 28, 2019 · 3 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-metadata S-needs-team-input Status: Needs input from team on whether/how to proceed.

Comments

@CAD97
Copy link
Contributor

CAD97 commented Oct 28, 2019

related: #7178
related: rust-lang/rust-analyzer#1967

cargo metadata Should add a key to each package that contains the path used for the OUT_DIR environment variable.

@CAD97 CAD97 added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Oct 28, 2019
@ehuss
Copy link
Contributor

ehuss commented Nov 8, 2019

This may not be possible in a general sense. The OUT_DIR hash depends on quite a few things (target, profile, features, etc.) that may not be available to the cargo metadata command. If I understand correctly, this is for rust-analyzer to be able to interpret include! macros after the build scripts have been run? Would it be possible for it to use the build-script-executed JSON message if it included the path?

@CAD97
Copy link
Contributor Author

CAD97 commented Nov 8, 2019

It's theoretically possible to get this information from anywhere. IntelliJ Rust currently has support for grabbing the path from --build-plan.

The important part is that this information is retrievable without having to rebuild any more of the crate graph than if the information was not asked for.

As a bonus, being able to find this information without actually building anything would be nice. (An include! into an absent OUT_DIR would then be a unresolved reference until first build rather than magically kicking off a build when opening the project without deliberate user interaction.)

@epage epage added the S-needs-team-input Status: Needs input from team on whether/how to proceed. label Nov 2, 2023
@epage epage changed the title cargo metadata: get OUT_DIR cargo metadata: get build script OUT_DIR Nov 2, 2023
@ydirson
Copy link

ydirson commented Feb 25, 2024

This would also be useful for more high-level build systems wrapping cargo (eg. Trunk), when a crate's build.rs produces output to be consumed by post-cargo build steps.

The Cargo Book states:

Build scripts may save any output files or intermediate artifacts in the directory specified in the OUT_DIR environment variable. Scripts should not modify any files outside of that directory.

Without easy access to the OUT_DIR value from external tools, it is just not possible to follow this rule.

cargo-outdir provides a workaround, but this is an unmaintained third-party crate with a 3y-old Cargo.lock, and any other 3rd-party tool would potentially be subject to the same kind of problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` Command-metadata S-needs-team-input Status: Needs input from team on whether/how to proceed.
Projects
None yet
Development

No branches or pull requests

4 participants