Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable substitution in cargo.toml #4221

Closed
stepancheg opened this issue Jun 25, 2017 · 6 comments
Closed

Variable substitution in cargo.toml #4221

stepancheg opened this issue Jun 25, 2017 · 6 comments
Labels
A-workspaces Area: workspaces C-enhancement Category: enhancement

Comments

@stepancheg
Copy link
Contributor

While working with Cargo, editing version numbers is a bit annoying.

For example, I have a repository with two crates:

aaa version = 0.1.2
bbb version = 0.1.2 depends on aaa version = 0.1.2

When I incrementing version number, I need to edit version several times, which is as i said, annoying, because I constantly forget to update one of several version fields.

What think could solve this problem is something like substitution variables declared in [workspace] section. E. g.

[workspace.vars]
v = "0.1.4"
futures_v = "0.1"
version = "${v}"
[dependencies]
bbb = { path = "../aaa", version = "=${v}" }
futures = "${futures_v}"
@locka99
Copy link

locka99 commented Jul 6, 2017

I'm running in to a similar issue. I have a workspace with 7 sub configs. There a quite a bit of duplication in these files since crates share the same meta info, version, and some external and internal dependencies. Some of the duplication could be solved by using substitution variables or pushing up some of the values to the top level.

It would certainly make packaging and publishing easier if I could just bump a number up in one file instead of doing it over many.

@ashleygwilliams ashleygwilliams added A-workspaces Area: workspaces C-enhancement Category: enhancement labels Jul 7, 2017
@ashleygwilliams
Copy link
Member

hey @stepancheg thanks for filing this! in order to proceed with this, the team would need to decide whether this is a feature we would want to accept.

@carols10cents is gonna throw this on the team agenda to discuss it! we'll follow up after that.

@carols10cents
Copy link
Member

We discussed this in the cargo meeting, and we agree that it's is annoying to have to update the version number in multiple places.

However, we don't think supporting variables in Cargo.toml is a great solution to this problem-- we'd rather work on enhancing workspaces to support using one version of a crate across the workspace.

Additionally, if you do want to have variables interpolated into your Cargo.toml, it's possible to do this with a tool external to cargo that would be run before building.

So we don't think adding variable interpolation is something cargo should support. Thank you for the issue though! 🌞

@mieubrisse
Copy link

Just wanted to add a +1 to this old thread, since I'm hitting the same issue - when you have two crates that need the same version, you have to remember to keep them in sync. Java's Gradle has the gradle.properties file that gets sourced automatically for interpolation use in the build.gradle file; it'd be really cool to have something like this in Rust.

@locka99
Copy link

locka99 commented Feb 9, 2021

The workaround I use now is to tag a version with a unique comment like this in all my crates:

version = "0.9.0" # OPCUARustVersion

Then it's relatively easy to search and replace on 0.9.0" # OPCUARustVersion and change it to a new value.

@gilescope
Copy link
Contributor

That's a tad hacky. Do not repeat yourself is a principle for a reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-workspaces Area: workspaces C-enhancement Category: enhancement
Projects
None yet
Development

No branches or pull requests

6 participants