Skip to content

Commit cc34e4a

Browse files
authored
Update the "Updating LLVM" documentation (#451)
Make sure existing sections are up-to-date and then also add some words about the recent convention we developed for updating LLVM versions with respect to branch naming as well.
1 parent 2d5a47f commit cc34e4a

File tree

1 file changed

+63
-27
lines changed

1 file changed

+63
-27
lines changed

src/codegen/updating-llvm.md

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,26 @@ policy!), but for now these are rough guidelines!
1717

1818
## Why update LLVM?
1919

20-
There are two primary reasons nowadays that we want to update LLVM in one way or
20+
There are a few reasons nowadays that we want to update LLVM in one way or
2121
another:
2222

23-
* First, a bug could have been fixed! Often we find bugs in the compiler and fix
23+
* A bug could have been fixed! Often we find bugs in the compiler and fix
2424
them upstream in LLVM. We'll want to pull fixes back to the compiler itself as
2525
they're merged upstream.
2626

27-
* Second, a new feature may be available in LLVM that we want to use in rustc,
27+
* A new feature may be available in LLVM that we want to use in rustc,
2828
but we don't want to wait for a full LLVM release to test it out.
2929

30+
* LLVM itself may have a new release and we'd like to update to this LLVM
31+
release.
32+
3033
Each of these reasons has a different strategy for updating LLVM, and we'll go
31-
over both in detail here.
34+
over them in detail here.
3235

3336
## Bugfix Updates
3437

35-
For updates of LLVM that typically just update a bug, we cherry-pick the bugfix
36-
to the branch we're already using. The steps for this are:
38+
For updates of LLVM that are to fix a small bug, we cherry-pick the bugfix to
39+
the branch we're already using. The steps for this are:
3740

3841
1. Make sure the bugfix is in upstream LLVM.
3942
2. Identify the branch that rustc is currently using. The `src/llvm-project`
@@ -43,10 +46,13 @@ to the branch we're already using. The steps for this are:
4346
4. Check out the appropriate branch (typically named `rustc/a.b-yyyy-mm-dd`)
4447
5. Cherry-pick the upstream commit onto the branch
4548
6. Push this branch to your fork
46-
7. Send a Pull Request to rust-lang/llvm-project to the same branch as before
49+
7. Send a Pull Request to rust-lang/llvm-project to the same branch as before.
50+
Be sure to reference the Rust and/or LLVM issue that you're fixing in the PR
51+
description.
4752
8. Wait for the PR to be merged
4853
9. Send a PR to rust-lang/rust updating the `src/llvm-project` submodule with
49-
your bugfix
54+
your bugfix. This can be done locally with `git submodule update --remote
55+
src/llvm-project` typically.
5056
10. Wait for PR to be merged
5157

5258
The tl;dr; is that we can cherry-pick bugfixes at any time and pull them back
@@ -70,28 +76,21 @@ through each in detail.
7076
1. Create a new branch in the rust-lang/llvm-project repository. This branch
7177
should be named `rustc/a.b-yyyy-mm-dd` where `a.b` is the current version
7278
number of LLVM in-tree at the time of the branch and the remaining part is
73-
today's date.
79+
today's date. Move this branch to the commit in LLVM that you'd like, which
80+
for this is probably the current LLVM HEAD.
7481

7582
2. Apply Rust-specific patches to the llvm-project repository. All features and
7683
bugfixes are upstream, but there's often some weird build-related patches
7784
that don't make sense to upstream which we have on our repositories. These
7885
patches are around the latest patches in the rust-lang/llvm-project branch
7986
that rustc is currently using.
8087

81-
3. Update the `compiler-rt` submodule in the
82-
`rust-lang-nursery/compiler-builtins` repository. Push this update to the
83-
same branch name of the `llvm-project` submodule to the
84-
of the `rust-lang/compiler-rt` repository. Then push this update to a branch
85-
of `compiler-builtins` with the same-named branch. Note that this step is
86-
frequently optional since we may not need to update `compiler-rt`.
87-
88-
4. Prepare a commit to rust-lang/rust
89-
90-
* Update `src/llvm-project`
91-
* Update `compiler-builtins` crate in `Cargo.lock` (if necessary)
92-
93-
5. Build your commit. Make sure you've committed the previous changes to ensure
94-
submodule updates aren't reverted. Some commands you should execute are:
88+
3. Build the new LLVM in the `rust` repository. To do this you'll want to update
89+
the `src/llvm-project` repository to your branch and the revision you've
90+
created. It's also typically a good idea to update `.gitmodules` with the new
91+
branch name of the LLVM submodule. Make sure you've committed changes to
92+
`src/llvm-project` to ensure submodule updates aren't reverted. Some commands
93+
you should execute are:
9594

9695
* `./x.py build src/llvm` - test that LLVM still builds
9796
* `./x.py build src/tools/lld` - same for LLD
@@ -101,7 +100,7 @@ through each in detail.
101100
LLVM bindings. Note that you should use `#ifdef` and such to ensure that the
102101
bindings still compile on older LLVM versions.
103102

104-
6. Test for regressions across other platforms. LLVM often has at least one bug
103+
4. Test for regressions across other platforms. LLVM often has at least one bug
105104
for non-tier-1 architectures, so it's good to do some more testing before
106105
sending this to bors! If you're low on resources you can send the PR as-is
107106
now to bors, though, and it'll get tested anyway.
@@ -120,11 +119,20 @@ through each in detail.
120119
* `./src/ci/docker/run.sh dist-various-2`
121120
* `./src/ci/docker/run.sh armhf-gnu`
122121

123-
7. Send a PR! Hopefully it's smooth sailing from here :).
122+
5. Prepare a PR to `rust-lang/rust`. Work with maintainers of
123+
`rust-lang/llvm-project` to get your commit in a branch of that repository,
124+
and then you can send a PR to `rust-lang/rust`. You'll change at least
125+
`src/llvm-project` and will likely also change `src/rustllvm/*` as well.
124126

125127
For prior art, previous LLVM updates look like
126128
[#55835](https://github.com/rust-lang/rust/pull/55835)
127129
[#47828](https://github.com/rust-lang/rust/pull/47828)
130+
[#62474](https://github.com/rust-lang/rust/pull/62474)
131+
[#62592](https://github.com/rust-lang/rust/pull/62592). Note that sometimes it's
132+
easiest to land `src/rustllvm/*` compatibility as a PR before actually updating
133+
`src/llvm-project`. This way while you're working through LLVM issues others
134+
interested in trying out the new LLVM can benefit from work you've done to
135+
update the C++ bindings.
128136

129137
### Caveats and gotchas
130138

@@ -134,8 +142,36 @@ keep in mind while going through them:
134142
* LLVM bugs are hard to find, don't hesitate to ask for help! Bisection is
135143
definitely your friend here (yes LLVM takes forever to build, yet bisection is
136144
still your friend)
137-
* Updating LLDB has some Rust-specific patches currently that aren't upstream.
138-
If you have difficulty @tromey can likely help out.
139145
* If you've got general questions, @alexcrichton can help you out.
140146
* Creating branches is a privileged operation on GitHub, so you'll need someone
141147
with write access to create the branches for you most likely.
148+
149+
## New LLVM Release Updates
150+
151+
Updating to a new release of LLVM is very similar to the "feature updates"
152+
section above. The release process for LLVM is often months-long though and we
153+
like to ensure compatibility ASAP. The main tweaks to the "feature updates"
154+
section above is generally around branch naming. The sequence of events
155+
typically looks like:
156+
157+
1. LLVM announces that its latest release version has branched. This will show
158+
up as a branch in https://github.com/llvm/llvm-project typically named
159+
`release/$N.x` where `$N` is the version of LLVM that's being released.
160+
161+
2. We then follow the "feature updates" section above to create a new branch of
162+
LLVM in our rust-lang/llvm-project repository. This follows the same naming
163+
convention of branches as usual, except that `a.b` is the new version. This
164+
update is eventually landed in the rust-lang/rust repository.
165+
166+
3. Over the next few months, LLVM will continually push commits to its
167+
`release/a.b` branch. Often those are bug fixes we'd like to have as well.
168+
The merge process for that is to use `git merge` itself to merge LLVM's
169+
`release/a.b` branch with the branch created in step 2. This is typically
170+
done multiple times when necessary while LLVM's release branch is baking.
171+
172+
4. LLVM then announces the release of version `a.b`.
173+
174+
5. After LLVM's official release, we follow the "feature update" section again
175+
to create a new branch in the rust-lang/llvm-project repository, this time
176+
with a new date. The commit history should look much cleaner as just a few
177+
Rust-specific commits stacked on top of stock LLVM's release branch.

0 commit comments

Comments
 (0)