Skip to content

Commit 750833e

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

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

tools-in-rust-repo.md

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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+
@alexcrichton 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+
(See https://github.com/llvm-mirror/compiler-rt/branches for example of this policy)
62+
* Create a new PR to the Rust repo pointing the tool submodule back to tool's
63+
master tip; land it.
64+
65+
When changing the tool submodule, make sure that any other commits are OK to
66+
land (i.e., they are not work in progress and tests pass, etc.).
67+
68+
69+
### Exceptions
70+
71+
Rarely, a breaking change might be too complex to manage in the above fashion.
72+
In such cases it is OK to temporarily stop building and testing the tool while
73+
the tool devs fix the issue.
74+
75+
* If you think this is necessary, you must communicate this to the tool's
76+
maintainers, the dev-tools team, and the compiler team before landing the PR
77+
(and preferably before starting the work).
78+
* Try and do this early in the release cycle to give the maximum amount of time
79+
to fix the tool before the beta uplift.
80+
* It is never OK to do this on beta or stable branches.
81+
* Avoid doing this, if you can.
82+
83+
The steps to follow are similar to the previous steps, but you must comment out
84+
code in the build system as needed, rather than change the submodule, when
85+
landing your initial PR.
86+
87+
88+
## Building and testing a tool
89+
90+
After adding the tool as a submodule, you'll need to make some changes to the
91+
build system to build and test the tool, and to have it distributed with Rustup.
92+
93+
For all these changes, it is probably easiest to see how it is done for an
94+
existing tool and try and copy that where possible. You can try grepping for
95+
`rls` and `Rls` inside [src/bootstrap](https://github.com/rust-lang/rust/tree/master/src/bootstrap).
96+
97+
To build the tool you'll need to add the tool as a workspace to `src/Cargo.toml`
98+
and make several changes to `src/bootstrap/tool.rs`.
99+
100+
To run a tool's tests, you'll need to make changes to `src/bootstrap/check.rs`.
101+
102+
You probably want the 'tidy' script not to check your tool, to do that you'll
103+
need to add the tool directory to the skip list in `src/tools/tidy/src/lib.rs`.
104+
105+
106+
## Distribution
107+
108+
To include a tool as a Rustup component you have to ensure that a tarball of the
109+
compiled tool is created and put in the right place, and that there is an entry
110+
in the Rustup manifest (generated by the build system). You don't need to make
111+
any changes to Rustup itself. You'll need to edit `src/bootstrap/dist.rs` and
112+
`src/bootstrap/install.rs` to create the tarball, and
113+
`src/tools/build-manifest/src/main.rs` to make an entry in the manifest.
114+
115+
116+
## Tips
117+
118+
Rustbuild will update submodules as part of its build process. If you don't
119+
commit the change, it will be overwritten. Therefore, you should either commit
120+
after updating a submodule and before building, or set `submodules = false` in
121+
`config.toml`.
122+
123+
After making changes to `Cargo.toml`, you need to build to ensure `Cargo.lock`
124+
is updated. Changes to `Cargo.lock` must be committed along with `Cargo.toml`
125+
changes.
126+
127+
To run tests for a tool, use `./x.py test src/tools/rls`. Note that it is
128+
possible for tool tests to pass in their own CI, but fail when run inside the
129+
Rust repo because of the different environment.
130+
131+
132+
## People who can help you
133+
134+
Usernames are for irc/GitHub.
135+
136+
* Any questions - nrc/@nrc or ask in #rust-dev-tools
137+
* Rustbuild - simulacrum/@Mark-Simulacrum, acrichto/@alexcrichton, or ask in #rust-infra
138+
* Compiler issues - ask in #rustc, if you need a specific person try mw or nmatsakis.
139+
* Rust distribution - acrichto/@alexcrichton
140+
* Rustfmt or RLS - nrc/@nrc
141+
* Clippy - Manishearth/@Manishearth or oli-obk/@oli-obk

0 commit comments

Comments
 (0)