-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Providing path to originally selected manifest file #13484
Comments
This kind of inverse relation that a dependency knows the full picture of a build sounds a bit odd. Could you elaborate more on what you actually want to achieve? BTW, there is a relevant issue #3946 about finding the root workspace, and the current experiment of that is an unstable env var |
I have a sys crate who's bindings are globally configurable. I want to be able to configure the bindings based off of info in the metadata table in downstream crates. I also considered configuring it via cargo features, but features are meant to be additive and not mutually exclusive, and I also think this metadata approach is a better user experience. More context here: microsoft/windows-drivers-rs#82 (comment) I need a path to pass to From the description of |
This provides what cargo sets as the `current_dir` for the `rustc` process. While `std::file!` is unspecified in what it is relative to, it is relatively safe, it is generally relative to `rustc`s `current_dir`. This can be useful for snapshot testing. For example, `snapbox` has been using this macro on nightly since assert-rs/snapbox#247, falling back to finding a parent of `CARGO_MANIFEST_DIR`, if present. This has been in use in Cargo since rust-lang#13441. This was added in rust-lang#12996. Relevant points discussed in that issue: - This diverged from the original proposal from the Cargo team of having a `CARGO_WORKSPACE_DIR` that is the "workspace" of the package being built (ie registry packages would map to `CARGO_MANIFEST_DIR`). In looking at the `std::file!` use case, `CARGO_MANIFEST_DIR`, no matter how we defined it, would only sort of work because no sane definition of that maps to `rustc`'s `current_dir`.a This instead focuses on the mechanism currently being used. - Using "current dir" in the name is meant to be consistent with `std::env::current_dir`. - I can go either way on `CARGO_RUSTC` vs `RUSTC`. Existing related variables: - `RUSTC` - `RUSTC_WRAPPER` - `RUSTC_WORKSPACE_WRAPPER` - `RUSTFLAGS` (no `C`) - `CARGO_CACHE_RUSTC_INFO` Note that rust-lang#3946 was overly broad and covered many use cases. One of those was for packages to look up information on their dependents. Issue rust-lang#13484 is being left open to track that. Fixes rust-lang#3946
This provides what cargo sets as the `current_dir` for the `rustc` process. While `std::file!` is unspecified in what it is relative to, it is relatively safe, it is generally relative to `rustc`s `current_dir`. This can be useful for snapshot testing. For example, `snapbox` has been using this macro on nightly since assert-rs/snapbox#247, falling back to finding a parent of `CARGO_MANIFEST_DIR`, if present. This has been in use in Cargo since rust-lang#13441. This was added in rust-lang#12996. Relevant points discussed in that issue: - This diverged from the original proposal from the Cargo team of having a `CARGO_WORKSPACE_DIR` that is the "workspace" of the package being built (ie registry packages would map to `CARGO_MANIFEST_DIR`). In looking at the `std::file!` use case, `CARGO_MANIFEST_DIR`, no matter how we defined it, would only sort of work because no sane definition of that maps to `rustc`'s `current_dir`.a This instead focuses on the mechanism currently being used. - Using "current dir" in the name is meant to be consistent with `std::env::current_dir`. - I can go either way on `CARGO_RUSTC` vs `RUSTC`. Existing related variables: - `RUSTC` - `RUSTC_WRAPPER` - `RUSTC_WORKSPACE_WRAPPER` - `RUSTFLAGS` (no `C`) - `CARGO_CACHE_RUSTC_INFO` Note that rust-lang#3946 was overly broad and covered many use cases. One of those was for packages to look up information on their dependents. Issue rust-lang#13484 is being left open to track that. Fixes rust-lang#3946
I propose we close this feature request. This creates an inverse relationship in packages. Smoothing out that path I feel like would lean to anti-patterns. Particularly problematic about this is that it assumes a selected manifest is where the config can come from. |
This would also be true of mutually exclusive global features, right? dependencies can have conditional compilation based on the
These are not concerns for my specific use case, since I just use need to know where the walking starts from cargo's perspective. I run #3946 wouldn't work for this use case since the end-user workspace is different from the workspace the dependencies live in. An official feature for "mutually exclusive global features" would replace the need for what I am currently doing with |
Features. mutually exclusive features, etc are a very controlled mechanism for communicating vs giving carte blanche access to dependents.
Unless you only support workspace config, you would need a way to find which package config is relevant. We also have to keep in mind the general shape of a feature and not design for one specific user. |
Yeah, in my specific use case, I look at all the package configs and bail if there are conflicting configs
Totally agree with you here. Sounds like closing this in favor of the proposed "mutually exclusive global features" is the conclusion for me here |
Thanks for the conversation from you all. Closing. |
Problem
When running cargo commands like
cargo build
, packages are automatically selected based off of the cargo manifest selected (either based off of the current working directory of the invocation or the--manifest-path
argument). AFAIU, a dependency graph is generated based off of this manifest and then the build is executed. By this logic, before any build-script runs, cargo already knows all of the packages that need to be built and has access to all of its manifest data. I want to access that data in one of the dependency's build.rs.I have 2 crates- crate A and crate B. crate B has a path dependency on crate A. I would like to be able to read custom metadata in crate B's manifest by using
cargo_metadata
from within crate A'sbuild.rs
. This metadata is something like a globally configured feature proposed in https://internals.rust-lang.org/t/pre-rfc-mutually-excusive-global-features/19618/38. When runningcargo metadata
cli command from crate B's directory, I can see the metadata in the crate B's manifest, but when getting metadata via crate A's build.rs, I cannot. If both crates existed in the same workspace, it would work, but I intend for crate A to be able to be consumed by others to use and configure via metadata in user's dependent crates.If the originally selected manifest path was provided to build scripts, I could point to that manifest when using
cargo_metadata
in crate A's build.rs. As it stands, I need to useOUT_DIR
to derive where the selected/root manifest of the build is, but this is fragile and does not work when the default target directory is changed by things like--target-dir
(similar issue to #9661 ).Proposed Solution
A environment variable provided to builds scripts that exposes to originally selected manifest path.
Notes
seems like a similar feature request to #8148
The text was updated successfully, but these errors were encountered: