Skip to content

Define cargo aliases as a strings instead of lists#1772

Merged
Emilgardis merged 1 commit into
cross-rs:mainfrom
legeana:xtask-compatibility
Apr 23, 2026
Merged

Define cargo aliases as a strings instead of lists#1772
Emilgardis merged 1 commit into
cross-rs:mainfrom
legeana:xtask-compatibility

Conversation

@legeana
Copy link
Copy Markdown
Contributor

@legeana legeana commented Apr 21, 2026

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.

  • If the parent and the child have a different type, then cargo outright fails to load the configuration due to the type mismatch2.
  • If both the parent and the child have the array type, the arrays are appended to each other instead of being replaced3. 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-xtask4, it is commonly used, and provides the best compatibility. And unfortunately Cargo doesn't support ignoring parent's configs yet5.

Footnotes

  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. https://redirect.github.com/rust-lang/cargo/issues/7621

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
@legeana legeana requested a review from a team as a code owner April 21, 2026 12:33
@Emilgardis Emilgardis added no changelog A valid PR without changelog (no-changelog) no-ci-tests labels Apr 23, 2026
@Emilgardis
Copy link
Copy Markdown
Member

Thank you!

@Emilgardis Emilgardis added this pull request to the merge queue Apr 23, 2026
Merged via the queue into cross-rs:main with commit 65fe72b Apr 23, 2026
20 checks passed
@legeana legeana deleted the xtask-compatibility branch April 23, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog A valid PR without changelog (no-changelog) no-ci-tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants