Is there a way/tool to normalize member's Cargo.toml

I'm trying to use Workspace to manage multiple crates in a project. When building production releases, I'm using a build service, that consume the source code of the individual crate.

Because of workspace inherits, the member crate's Cargo.toml file does not have the full contents needed to build. So I'm looking if there is any existing command or 3rd tool already exists to render or normalize the member's Cargo.toml, essentially substitute workspace related references with the actually values.

For example, in project root:
Cargo.toml:

[workspace]
members = [ "crates/foo" ]
[workspace.package]
version = "1.2.3"

In crates/foo/Cargo.toml:

[package]
name = "foo"
version.workspace = true

I'm finding a way to render crates/foo/Cargo.toml to:

[package]
name = "foo"
version = "1.2.3"

Thanks.

1 Like

cargo package will do this as part of creating the package (foo.crate) file. It sounds like a good idea to make your build service accept .crate files directly.

3 Likes

TIL! cargo package sounds promising, I'll definitely look into adding support for .crate file to the build service.

Thank you for you quick reply!

cargo_toml — Rust parser // Lib.rs implements workspace inheritance.

2 Likes

Apparently cargo package does not support/allow git dependencies because it is aiming for creating package for publishing. So I do need to look at your cargo_toml library!

The limitation is only a crates.io policy. Custom Cargo registries allow git dependencies. Maybe you can trick cargo into thinking it's packaging for another registry. Or maybe you can even make your builder talk the Cargo registry protocol to support publishing to it directly.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.