Support variables in `Cargo.toml`?

This is very useful, especially in the workspace scenario.

Just like java maven: Maven – Introduction to the POM

For example:

# Cargo.toml

[workspace]
members = ["foo", "bar"]

[variables]
foo_name = "foo"
foo_version = "0.1.0"
# foo/Cargo.toml

[package]
name = "${foo_name}"
version = "${foo_version}"
# bar/Cargo.toml

[package]
name = "bar"
version = "0.1.0"

[dependencies]
${foo_name} = { version = "${foo_version}", path = "../${foo_name}" }

The variable foo_name and foo_version can be shared between packages. Therefore, it is very convenient to modify.

1 Like

I known the workspace.package, but he is not flexible.

At least, my example can not be done with workspace.package.

This design has been rejected already, and Cargo decided to add workspace inheritance instead.

https://rust-lang.github.io/rfcs/2906-cargo-workspace-deduplicate.html

11 Likes