Skip to content

Commit 1266e2b

Browse files
committed
Update LLVM docs
1 parent ed3365e commit 1266e2b

File tree

1 file changed

+68
-26
lines changed

1 file changed

+68
-26
lines changed

src/backend/updating-llvm.md

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,90 @@
33
<!-- toc -->
44

55
<!-- date-check: Jul 2023 -->
6-
There is no formal policy about when to update LLVM or what it can be updated to,
7-
but a few guidelines are applied:
6+
Rust supports building against multiple LLVM versions:
87

9-
* We try to always support the latest released version
10-
* We try to support the last few versions
11-
(and the number changes over time)
12-
* We allow moving to arbitrary commits during development
13-
* We strongly prefer to upstream all patches to LLVM before including them in rustc
8+
* Tip-of-tree for the current LLVM development branch is usually supported
9+
within a few days. PRs for such fixes are tagged with `llvm-main`.
10+
* The latest released major version is always supported.
11+
* The one or two preceding major versions are usually supported.
1412

15-
## Why update LLVM?
13+
By default, Rust uses its own fork in the [rust-lang/llvm-project repository].
14+
This fork is based on a `release/NN.x` branch of the upstream project, rather
15+
than the `main` development branch.
1616

17-
There are two reasons we would want to update LLVM:
17+
Our LLVM fork only accepts:
1818

19-
* A bug could have been fixed!
20-
Note that if we are the ones who fixed such a bug,
21-
we prefer to upstream it, then pull it back for use by rustc.
19+
* Backports of changes that have already landed upstream.
20+
* Workarounds for build issues affecting our CI environment.
2221

23-
* LLVM itself may have a new release.
22+
With the exception of one grandfathered-in patch for SGX enablement, we do not
23+
accept functional patches that have not been upstreamed first.
2424

25-
Each of these reasons has a different strategy for updating LLVM, and we'll go
26-
over them in detail here.
25+
There are three types of LLVM updates, with different procedures:
2726

28-
## Bugfix Updates
27+
* Backports while the current major LLVM version is supported.
28+
* Backports while the current major LLVM version is no longer supported (or
29+
the change is not eligible for upstream backport).
30+
* Update to a new major LLVM version.
2931

30-
For updates of LLVM that are to fix a small bug, we cherry-pick the bugfix to
31-
the branch we're already using. The steps for this are:
32+
## Backports (upstream supported)
33+
34+
While the current major LLVM version is supported upstream, fixes should be
35+
backported upstream first, and the release branch then merged back into the
36+
Rust fork.
37+
38+
1. Make sure the bugfix is in upstream LLVM.
39+
2. If this hasn't happened already, request a backport to the upstream release
40+
branch. If you have LLVM commit access, follow the [backport process].
41+
Otherwise, open an issue requesting the backport. Continue once the
42+
backport has been approved and merged.
43+
3. Identify the branch that rustc is currently using. The `src/llvm-project`
44+
submodule is always pinned to a branch of the
45+
[rust-lang/llvm-project repository].
46+
4. Fork the rust-lang/llvm-project repository.
47+
5. Check out the appropriate branch (typically named `rustc/a.b-yyyy-mm-dd`).
48+
6. Add a remote for the upstream repository using
49+
`git remote add upstream https://github.com/llvm/llvm-project.git` and
50+
fetch it using `git fetch upstream`.
51+
7. Merge the `upstream/release/NN.x` branch.
52+
8. Push this branch to your fork.
53+
9. Send a Pull Request to rust-lang/llvm-project to the same branch as before.
54+
Be sure to reference the Rust and/or LLVM issue that you're fixing in the PR
55+
description.
56+
10. Wait for the PR to be merged.
57+
11. Send a PR to rust-lang/rust updating the `src/llvm-project` submodule with
58+
your bugfix. This can be done locally with `git submodule update --remote
59+
src/llvm-project` typically.
60+
12. Wait for PR to be merged.
61+
62+
An example PR:
63+
[#59089](https://github.com/rust-lang/rust/pull/59089)
64+
65+
## Backports (upstream not supported)
66+
67+
Upstream LLVM releases are only supported for two to three months after the
68+
GA release. Once upstream backports are no longer accepted, changes should be
69+
cherry-picked directly to our fork.
3270

3371
1. Make sure the bugfix is in upstream LLVM.
3472
2. Identify the branch that rustc is currently using. The `src/llvm-project`
3573
submodule is always pinned to a branch of the
3674
[rust-lang/llvm-project repository].
3775
3. Fork the rust-lang/llvm-project repository.
3876
4. Check out the appropriate branch (typically named `rustc/a.b-yyyy-mm-dd`).
39-
5. Cherry-pick the upstream commit onto the branch.
40-
6. Push this branch to your fork.
41-
7. Send a Pull Request to rust-lang/llvm-project to the same branch as before.
77+
5. Add a remote for the upstream repository using
78+
`git remote add upstream https://github.com/llvm/llvm-project.git` and
79+
fetch it using `git fetch upstream`.
80+
6. Cherry-pick the relevant commit(s) using `git cherry-pick -x`.
81+
7. Push this branch to your fork.
82+
8. Send a Pull Request to rust-lang/llvm-project to the same branch as before.
4283
Be sure to reference the Rust and/or LLVM issue that you're fixing in the PR
4384
description.
44-
8. Wait for the PR to be merged.
45-
9. Send a PR to rust-lang/rust updating the `src/llvm-project` submodule with
46-
your bugfix. This can be done locally with `git submodule update --remote
47-
src/llvm-project` typically.
48-
10. Wait for PR to be merged.
85+
9. Wait for the PR to be merged.
86+
10. Send a PR to rust-lang/rust updating the `src/llvm-project` submodule with
87+
your bugfix. This can be done locally with `git submodule update --remote
88+
src/llvm-project` typically.
89+
11. Wait for PR to be merged.
4990

5091
An example PR:
5192
[#59089](https://github.com/rust-lang/rust/pull/59089)
@@ -187,3 +228,4 @@ keep in mind while going through them:
187228
[`llvm-wrapper`]: https://github.com/rust-lang/rust/tree/master/compiler/rustc_llvm/llvm-wrapper
188229
[wg-llvm]: https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm
189230
[Dev Desktops]: https://forge.rust-lang.org/infra/docs/dev-desktop.html
231+
[backport process]: https://llvm.org/docs/GitHub.html#backporting-fixes-to-the-release-branches

0 commit comments

Comments
 (0)