How-to: ignore cargo config file in parent folder

Hi there,

I actually have a crate that contains a dependent crate as sub-folder. While the parent crate requires a ./.cargo/config.toml file to successfully compile the crate in the subfolder should be build without thus settings. According to the documentation cargo will merge config files if they exist along the search path. However, I'd like to skip the usage of the parent folder cargo config file usage.

In fact the thing is that the parent cargo config file contains a specific build target, but the dependent crate in the subfolder (it's a proc-macro crate) need always to be build for the host system.

Any way to stop cargo from looking in the parent folder if a config file is found in the current folder already or just prevent cargo from looking for a config file at all?

Thanks in advance for any hint.

Could you restructure your directory so instead of having something like this...

  • crate-a/
    • .cargo/config
    • crate-b/
      • .cargo/config

... You move the child to be at the same level as the parent instead of nested.

  • my-project/
    • crate-a/
      • .cargo/config
    • crate-b/
      • .cargo/config

That would mean your config files are no longer merged. With any common configuration put in the top-level directory.

Hi,

well, if this is the only option I might need to do this, but I really try to not require this change, as the child is a proc macro crate and shall only be used as part of the main crate I‘d really like to reflect this also in my folder structure and this the GitHub repo. Any other options available?

I’m not sure if this is possible. But you might be able to duplicate any settings in the child crate but with their default values to override the parent one

There were some other solutions proposed in this recent thread. I don't think any have been adopted yet, but they might be available in the future: Problems of `.cargo/config` files and possible solutions - cargo - Rust Internals

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.