Skip to content

Commit 3f90c3a

Browse files
committed
Added a section about updating submodules
The process for updating rustfmt is quite involved because of the way everything is configured. This section covers the steps for updating rustfmt and rationale behind them.
1 parent bd4907d commit 3f90c3a

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

CONTRIBUTING.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ It can also be more convenient during development to set `submodules = false`
364364
in the `config.toml` to prevent `x.py` from resetting to the original branch.
365365

366366
#### Breaking rustfmt or rls
367+
[breaking-rustfmt-or-rls]: #breaking-rustfmt-or-rls
367368

368369
Rust's build system also builds the
369370
[RLS](https://github.com/rust-lang-nursery/rls)
@@ -382,7 +383,9 @@ When this happens, follow these steps:
382383
1. First, if it doesn't exist already, create a `config.toml` by copying
383384
`config.toml.example` in the root directory of the Rust repository.
384385
Set `submodules = false` in the `[build]` section. This will prevent `x.py`
385-
from resetting to the original branch after you make your changes.
386+
from resetting to the original branch after you make your changes. If you
387+
need to [update any submodules to their latest versions][updating-submodules],
388+
see the section of this file about that for more information.
386389
2. Run `./x.py test src/tools/rustfmt`. Fix any errors in the submodule itself
387390
(the `src/tools/rustfmt` directory) until it works.
388391
3. Run `./x.py test src/tools/rls`. Fix any errors in the submodule itself
@@ -401,6 +404,65 @@ When this happens, follow these steps:
401404
12. Eventually the rls/rustfmt submodules will get re-updated back to the
402405
master branch
403406

407+
#### Updating submodules
408+
[updating-submodules]: #updating-submodules
409+
410+
These instructions are specific to updating `rustfmt`, however they may apply
411+
to the other submodules as well. Please help by improving these instructions
412+
if you find any discrepencies or special cases that need to be addressed.
413+
414+
To update the `rustfmt` submodule, start by running the appropriate
415+
[`git submodule` command](https://git-scm.com/book/en/v2/Git-Tools-Submodules).
416+
For example, to update to the latest commit on the remote master branch,
417+
you may want to run:
418+
```
419+
git submodule update --remote src/tools/rustfmt
420+
```
421+
If you run `./x.py build` now, and you are lucky, it may just work. If you see
422+
an error message about patches that did not resolve to any crates, you will need
423+
to complete a few more steps which are outlined with their rationale below.
424+
425+
*(This error may change in the future to include more information.)*
426+
```
427+
error: failed to resolve patches for `https://github.com/rust-lang-nursery/rustfmt`
428+
429+
Caused by:
430+
patch for `rustfmt-nightly` in `https://github.com/rust-lang-nursery/rustfmt` did not resolve to any crates
431+
failed to run: ~/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path ~/rust/src/bootstrap/Cargo.toml
432+
```
433+
434+
If you haven't used the `[patch]`
435+
section of `Cargo.toml` before, there is [some relevant documentation about it
436+
in the cargo docs](http://doc.crates.io/manifest.html#the-patch-section). In
437+
addition to that, you should read the
438+
[Overriding dependencies](http://doc.crates.io/specifying-dependencies.html#overriding-dependencies)
439+
section of the documentation as well.
440+
441+
Specifically, the following [section in Overriding dependencies](http://doc.crates.io/specifying-dependencies.html#testing-a-bugfix) reveals what the problem is:
442+
443+
> Next up we need to ensure that our lock file is updated to use this new version of uuid so our project uses the locally checked out copy instead of one from crates.io. The way [patch] works is that it'll load the dependency at ../path/to/uuid and then whenever crates.io is queried for versions of uuid it'll also return the local version.
444+
>
445+
> This means that the version number of the local checkout is significant and will affect whether the patch is used. Our manifest declared uuid = "1.0" which means we'll only resolve to >= 1.0.0, < 2.0.0, and Cargo's greedy resolution algorithm also means that we'll resolve to the maximum version within that range. Typically this doesn't matter as the version of the git repository will already be greater or match the maximum version published on crates.io, but it's important to keep this in mind!
446+
447+
This says that when we updated the submodule, the version number in our
448+
`src/tools/rustfmt/Cargo.toml` changed. The new version is different from
449+
the version in `Cargo.lock`, so the build can no longer continue.
450+
451+
To resolve this, we need to update `Cargo.lock`. Luckily, cargo provides a
452+
command to do this easily.
453+
454+
First, go into the `src/` directory since that is where `Cargo.toml` is in
455+
the rust repository. Then run, `cargo update -p rustfmt-nightly` to solve
456+
the problem.
457+
458+
```
459+
$ cd src
460+
$ cargo update -p rustfmt-nightly
461+
```
462+
463+
This should change the version listed in `src/Cargo.lock` to the new version you updated
464+
the submodule to. Running `./x.py build` should work now.
465+
404466
## Writing Documentation
405467
[writing-documentation]: #writing-documentation
406468

0 commit comments

Comments
 (0)