Skip to content

Cargo ignores config.toml of dependencies #11492

Closed
@BigBadE

Description

@BigBadE

Problem

Cargo internally only has one config, and will not load dependency configuration files when compiling them.
This causes a few issues with specific projects:

  1. Any dependencies that need to build with a different std than the project building them (for example, custom kernels writing a bootloader that need to run in 16bit mode).
  2. Any dependencies that need custom flags for a target (for example, if a library needs a special env variable for Windows or MacOS)

Steps

  1. Create a project "A"
  2. Create project "B"
  3. Make project "A" depend on project "B"
  4. Write "invalid" to the file .cargo/config.toml in project "B"
  5. Compile project "B", cargo errors with a TOML error
  6. Compile project "A", cargo succeeds with no TOML error

Possible Solution(s)

This may be hard to fix in Cargo, a lot of those settings may be applied before dependency resolution or not apply (like the [install] block setting where cargo install installs to), in which case they should be ignored. Other settings, like build-std, need to be applied.

I made a proof of concept at https://github.com/BigBadE/cargo, giving a possible implementation of this feature that adds the Config to the Unit, which means Config has to be clonable. For this proof of concept, a lot of LazyCells just use default, and some Unit methods just use the default Config. I'll open a PR if this is a usable implementation and not entirely naive.

Notes

No response

Version

cargo 1.64.0 (387270bc7 2022-09-16)
release: 1.64.0
commit-hash: 387270bc7f446d17869c7f208207c73231d6a252
commit-date: 2022-09-16
host: x86_64-pc-windows-msvc
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:Schannel)
os: Windows 10.0.19045 (Windows 10 Home) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-configurationArea: cargo config files and env varsC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions