Define cargo aliases as a strings instead of lists#1772
Merged
Conversation
Having the xtask alias be defined as a string allows cross-rs to be cloned into a subdirectory of another project that defines its own xtask alias. This compatibility is only possible if both the parent project's xtask alias and the cross-rs' xtask alias are strings. Cargo implements hierarchical config structure[^1] where the parent and the child configs are merged. - If the parent and the child have a different type, then cargo outright fails to load the configuration due to the type mismatch[^2]. - If both the parent and the child have the array type, the arrays are appended to each other instead of being replaced[^3]. This results in a broken command if the parent's array is non-empty. - If both the parent and the child have the type string, the child's value takes precedence. This is the only way to configure both the parent's and the child's `cargo.toml` to make the merging work as expected. Having the alias defined as a literal string matches the example provided in matklad/cargo-xtask[^4], it is commonly used, and provides the best compatibility. And unfortunately Cargo doesn't support ignoring parent's configs yet[^5]. [^1]: https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure [^2]: failed to merge config value from `parent/.cargo/config.toml` into `parent/cross/.cargo/config.toml`: expected array, but found string [^3]: For example, if the parent alias.xtask is `["foo", "bar"]` the resulting command is `["foo", "bar", "run", "-p", "xtask", "--"]`. [^4]: https://github.com/matklad/cargo-xtask#defining-xtasks [^5]: rust-lang/cargo#7621
Member
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Having the xtask alias be defined as a string allows cross-rs to be cloned into a subdirectory of another project that defines its own xtask alias. This compatibility is only possible if both the parent project's xtask alias and the cross-rs' xtask alias are strings.
Cargo implements hierarchical config structure1 where the parent and the child configs are merged.
cargo.tomlto make the merging work as expected.Having the alias defined as a literal string matches the example provided in matklad/cargo-xtask4, it is commonly used, and provides the best compatibility. And unfortunately Cargo doesn't support ignoring parent's configs yet5.
Footnotes
https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure ↩
failed to merge config value from
parent/.cargo/config.tomlintoparent/cross/.cargo/config.toml: expected array, but found string ↩For example, if the parent alias.xtask is
["foo", "bar"]theresulting command is
["foo", "bar", "run", "-p", "xtask", "--"]. ↩https://github.com/matklad/cargo-xtask#defining-xtasks ↩
https://redirect.github.com/rust-lang/cargo/issues/7621 ↩