|
| 1 | +# New Packages |
| 2 | + |
| 3 | +This chapter sketches out how to add a new package to the cargo workspace. |
| 4 | + |
| 5 | +## Steps |
| 6 | + |
| 7 | +Choose the relevant parent directory |
| 8 | +- `credential/` for credential-process related packages |
| 9 | +- `benches/` for benchmarking of cargo itself |
| 10 | +- `crates/` for everything else |
| 11 | + |
| 12 | +Run `cargo new <name>` |
| 13 | +- `<name>`: |
| 14 | + - We tend to use `-` over `_` |
| 15 | + - For internal APIs, to avoid collisions with third-party subcommands, we can use the `cargo-util-` prefix |
| 16 | + - For xtasks, we use the `xtask-` prefix |
| 17 | +- `package.rust-version` |
| 18 | + - Internal packages tend to have a policy of "latest" with a [`# MSRV:1` comment](#msrv-policy) |
| 19 | + - Ecosystem packages tend to have a policy of "N-2" with a [`# MSRV:3` comment](#msrv-policy) |
| 20 | + - If the right choice is inherited from the workspace, feel free to keep it that way |
| 21 | +- If running without [cargo new automatically adding to workspace](https://github.com/rust-lang/cargo/pull/12779), add it as a workspace member if not already captured by a glob |
| 22 | + |
| 23 | +If its an xtask, |
| 24 | +- Add it to `.cargo/config.toml`s `[alias]` table |
| 25 | +- Mark `package.publish = false` |
| 26 | + |
| 27 | +If needed to be published with `cargo`, |
| 28 | +add the package to `publish.py` in the repo root, |
| 29 | +in dependency order. |
| 30 | + |
| 31 | +Note: by adding the package to the workspace, you automatically get |
| 32 | +- CI running `cargo test` |
| 33 | +- CI verifying MSRV |
| 34 | +- CI checking for `cargo doc` warnings |
| 35 | + |
| 36 | +## MSRV Policy |
| 37 | + |
| 38 | +Our MSRV policies are |
| 39 | +- Internal packages: support latest version |
| 40 | +- Ecosystem packages: support latest 3 versions |
| 41 | + |
| 42 | +We proactively update the MSRV |
| 43 | +- So contributors don't shy away from using newer features, either assuming they |
| 44 | + can't ask or feeling like they have to have a justification when asking |
| 45 | +- To avoid a de facto MSRV developing from staying on a version for a long |
| 46 | + period of time, leaving users unhappy when their expectations aren't met |
| 47 | + |
| 48 | +To proactively update the MSRV, we use [RenovateBot](https://docs.renovatebot.com/) |
| 49 | +with the configuration file in `.github/renovatebot.json5`. |
| 50 | +To know what MSRV policy to use, |
| 51 | +it looks for comments of the form `# MSRV:N`, |
| 52 | +where `N` is the number of supported rust versions. |
0 commit comments