Skip to content

Commit 03e7022

Browse files
committed
Auto merge of #12878 - epage:contrib, r=weihanglo
docs(contrib): Describe how to add a new package `@Muscraft` is considering adding a crate and we felt it was best to not just answer the question of how to do so but to document it!
2 parents 9bf67a1 + 9a36c04 commit 03e7022

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/doc/contrib/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [Design Principles](./design.md)
1212
- [Implementing a Change](./implementation/index.md)
1313
- [Architecture](./implementation/architecture.md)
14+
- [New packages](./implementation/packages.md)
1415
- [New subcommands](./implementation/subcommands.md)
1516
- [Console Output](./implementation/console.md)
1617
- [Filesystem](./implementation/filesystem.md)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)