Skip to content

Commit db91d09

Browse files
committed
Documents managing tools in the Rust repo
1 parent 59e796a commit db91d09

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

tools-in-rust-repo.md

+139
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Maintaining tools in the Rust repository
2+
3+
This document contains information for tool maintainers and Rust contributors
4+
who need to work with tools that are part of the Rust distribution and
5+
repository. For information on requirements for such tools see the
6+
[stability docs](https://github.com/nrc/dev-tools-team/blob/master/stability/README.md).
7+
8+
When adding tools or making significant changes, please be sure to cc @nrc and
9+
@aclexcrichton on PRs. Adding tools to the Rust repo requires approval from the
10+
dev-tools team and sign-off from the core team.
11+
12+
13+
## Repository layout
14+
15+
Tools should live in their own repository which should be in an official
16+
organisation (e.g., [rust-lang-nursery](https://github.com/rust-lang-nursery)).
17+
Tools should be included into the Rust repository as a Git submodule in the
18+
[src/tools](https://github.com/rust-lang/rust/tree/master/src/tools) directory.
19+
20+
21+
## Constraints on tools
22+
23+
It is essential that any commit used as a submodule in the Rust repo is
24+
preserved forever (i.e., is *never* deleted or changed). This ensures that we
25+
will continue to be able to build any historic release of Rust (which is
26+
important for bisecting regressions, etc). In order to do this, any commit
27+
pulled into the Rust repo as a submodule must be from a Rust organisation repo,
28+
not an author's. If the commit is only on a branch, that branch cannot be
29+
deleted. Whether the commit is on a branch or master, it cannot be rebased
30+
(which essentially deletes the commit and creates a new one).
31+
32+
Tools used in the Rust repo cannot use Cargo workspaces. This is because the
33+
tool itself will be treated as a workspace crate and workspaces cannot be
34+
nested.
35+
36+
37+
## Making breaking changes
38+
39+
If making a change to a 'core' part of Rust causes breakage in any of the tools,
40+
then there is a bit of a dance to perform to land the Rust PR.
41+
42+
Communication is key here! If you're a compiler dev, communicate with tool devs
43+
as soon as possible (and vice versa).
44+
45+
At the end of the day, the tool's maintainers are responsible for ensuring that
46+
their tool continues to build and pass tests in the Rust repo. For non-trivial
47+
fixes, tool devs should be happy to help fix breaking changes.
48+
49+
How to land a breaking change:
50+
51+
* Make your changes to the Rust repo
52+
* Make changes to the tool (against its own repo, not the submodule in the Rust
53+
repo) to address the breaking changes.
54+
- check that the tool's tests pass inside the Rust repo
55+
- either push a branch to the tool's repo or submit a PR
56+
* Point the Rust submodule at the new tool commit
57+
* Land the PR
58+
* Wait for the PR to be included in a nightly release...
59+
* Merge the tool commit to the tool's master branch
60+
- if the commit was changed or rebased, **do not delete** the commit's branch
61+
* Create a new PR to the Rust repo pointing the tool submodule back to tool's
62+
master tip; land it.
63+
64+
When changing the tool submodule, make sure that any other commits are OK to
65+
land (i.e., they are not work in progress and tests pass, etc.).
66+
67+
68+
### Exceptions
69+
70+
Rarely, a breaking change might be too complex to manage in the above fashion.
71+
In such cases it is OK to temporarily stop building and testing the tool while
72+
the tool devs fix the issue.
73+
74+
* If you think this is necessary, you must communicate this to the tool's
75+
maintainers, the dev-tools team, and the compiler team before landing the PR
76+
(and preferably before starting the work).
77+
* Try and do this early in the release cycle to give the maximum amount of time
78+
to fix the tool before the beta uplift.
79+
* It is never OK to do this on beta or stable branches.
80+
* Avoid doing this, if you can.
81+
82+
The steps to follow are similar to the previous steps, but you must comment out
83+
code in the build system as needed, rather than change the submodule, when
84+
landing your initial PR.
85+
86+
87+
## Building and testing a tool
88+
89+
After adding the tool as a submodule, you'll need to make some changes to the
90+
build system to build and test the tool, and to have it distributed with Rustup.
91+
92+
For all these changes, it is probably easiest to see how it is done for an
93+
existing tool and try and copy that where possible. You can try grepping for
94+
`rls` and `Rls` inside [src/bootstrap](https://github.com/rust-lang/rust/tree/master/src/bootstrap).
95+
96+
To build the tool you'll need to add the tool as a workspace to `src/Cargo.toml`
97+
and make several changes to `src/bootstrap/tool.rs`.
98+
99+
To run a tool's tests, you'll need to make changes to `src/bootstrap/check.rs`.
100+
101+
You probably want the 'tidy' script not to check your tool, to do that you'll
102+
need to add the tool directory to the skip list in `src/tools/tidy/src/lib.rs`.
103+
104+
105+
## Distribution
106+
107+
To include a tool as a Rustup component you have to ensure that a tarball of the
108+
compiled tool is created and put in the right place, and that there is an entry
109+
in the Rustup manifest (generated by the build system). You don't need to make
110+
any changes to Rustup itself. You'll need to edit `src/bootstrap/dist.rs` and
111+
`src/bootstrap/install.rs`.
112+
113+
114+
## Tips
115+
116+
Rustbuild will update submodules as part of its build process. If you don't
117+
commit the change, it will be overwritten. Therefore, you should either commit
118+
after updating a submodule and before building, or set `submodules = false` in
119+
`config.toml`.
120+
121+
After making changes to `Cargo.toml`, you need to build to ensure `Cargo.lock`
122+
is updated. Changes to `Cargo.lock` must be committed along with `Cargo.toml`
123+
changes.
124+
125+
To run tests for a tool, use `./x.py check src/tools/rls`. Note that it is
126+
possible for tool tests to pass in their own CI, but fail when run inside the
127+
Rust repo because of the different environment.
128+
129+
130+
## People who can help you
131+
132+
Usernames are for irc/GitHub.
133+
134+
* Any questions - nrc/@nrc or ask in #rust-dev-tools
135+
* Rustbuild - simulacrum/@Mark-Simulacrum, acrichto/@alexcrichton, or ask in #rust-infra
136+
* Compiler issues - ask in #rustc, if you need a specific person try mw or nmatsakis.
137+
* Rust distribution - acrichto/@alexcrichton
138+
* Rustfmt or RLS - nrc/@nrc
139+
* Clippy - Manishearth/@Manishearth or oli-obk/@oli-obk

0 commit comments

Comments
 (0)