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

Unset .cargo/config key for subdirectory #8112

Open
phil-opp opened this issue Apr 15, 2020 · 1 comment
Open

Unset .cargo/config key for subdirectory #8112

phil-opp opened this issue Apr 15, 2020 · 1 comment
Labels
A-configuration Area: cargo config files and env vars A-cross-compiling Area: using --target flag for other platforms C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Comments

@phil-opp
Copy link
Contributor

Describe the problem you are trying to solve

I'm writing a crate that sets a default target through the build.target key in the .cargo/config file. I now want to create an utility crate for building the project in a subdirectory (as a replacement for a Makefile). So the file layout looks like this:

project
|  .cargo
|  |  config
|  Cargo.toml
|  src
|  | …
|  utility
|  |  Cargo.toml
|  |  src
|  |  |  main.rs

The utility sub-crate should be executed on the host system. However, since the .cargo/config file of the main project is in a parent directory, its build.target key applies to the sub-crate as well.

Unfortunately, there seems to be no platform-independent way to reset the target to the host system again. I can pass --target x86_64-unknown-linux-gnu, but that won't work on other host systems such as Windows.

Describe the solution you'd like

I can imagine different solutions to this problem:

  • Provide a way to unset/remove a specific configuration key in a .cargo/config file. This way, the build.target key could be unset for the subdirectory, so that it builds for the native target again.
  • Add a way to opt-out of hierarchical merging with parent files for a .cargo/config file.
  • Add some kind of target alias for the host system. This way, the subdirectory could set the host system in build.target in a platform independent way. (I already proposed something like this for the --target flag in Add --target HOST alias for host target #6777.)

Notes

One example that the ability to remove configuration keys is useful in practice is the std::env::remove function of the standard library. Like for .cargo/config values, an environment variable set to the empty string "" is not equal to a variable that is not set. Therefore it makes sense to provide a way to go back to the "unset" state, which is especially useful if the variable was set by the parent program.

@phil-opp phil-opp added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Apr 15, 2020
@ehuss ehuss added A-configuration Area: cargo config files and env vars A-cross-compiling Area: using --target flag for other platforms labels Jun 24, 2020
@epage epage added the S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted. label Nov 4, 2023
@epage
Copy link
Contributor

epage commented Nov 4, 2023

As a heads up, config usually represents environment information and having a config tied to a package will only work if you only operate on the package within the subdirectory.

We have #12738 for tracking adding the missing project information that people fall back to configs.

Some things of note for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-configuration Area: cargo config files and env vars A-cross-compiling Area: using --target flag for other platforms C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` S-needs-design Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.
Projects
None yet
Development

No branches or pull requests

3 participants