Naming conventions for Cargo workspaces

Are there any naming conventions for Cargo workspaces? I'm having issues with naming a workspace "core" as it seems like it conflicts with the "core" crate when used with an attribute macro. Attribute macro seems to generate code that uses the "core" crate which, if I have a "core" workspace certainly does break the compilation.

I usually use a virtual workspace which doesn't have a package name.

2 Likes

Do you have an example for that? I'm having trouble understanding how virtual workspaces will work in my use-case. I do have a primary package (application) and using sub-packages to separate some code.

An example using a virtual workspace is tokio. The top-level directory has a virtual manifest with no [package] section. All of the crates (including the main tokio crate) are in subdirectories of the workspace.

The other approach can be seen in ripgrep. Here, the main application package is also the workspace, so its manifest file contains both a [package] section and a [workspace] section. The name of the package is ripgrep because that is the name of the application.

If you want to use the primary application as the workspace (like ripgrep does), then the package name is the application name. You may want to choose a different name than core for your package, however, because that name is already taken by one of Rust's standard library crates.

Or, you can use a virtual workspace (like tokio does). Then your application package and all of your “sub-packages” will live in separate directories inside the workspace, and you don't need a package name for the workspace.

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.