Skip to content

Commit d194bc5

Browse files
authored
Update LLVM docs (#2039)
* Update LLVM docs * Apply feedback
1 parent 43d8378 commit d194bc5

File tree

1 file changed

+71
-27
lines changed

1 file changed

+71
-27
lines changed

src/backend/updating-llvm.md

+71-27
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,93 @@
22

33
<!-- toc -->
44

5-
<!-- 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:
5+
<!-- date-check: Aug 2024 -->
6+
Rust supports building against multiple LLVM versions:
7+
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.
12+
13+
By default, Rust uses its own fork in the [rust-lang/llvm-project repository].
14+
This fork is based on a `release/$N.x` branch of the upstream project, where
15+
`$N` is either the latest released major version, or the current major version
16+
in release candidate phase. The fork is never based on the `main` development
17+
branch.
18+
19+
Our LLVM fork only accepts:
820

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
21+
* Backports of changes that have already landed upstream.
22+
* Workarounds for build issues affecting our CI environment.
1423

15-
## Why update LLVM?
24+
With the exception of one grandfathered-in patch for SGX enablement, we do not
25+
accept functional patches that have not been upstreamed first.
1626

17-
There are two reasons we would want to update LLVM:
27+
There are three types of LLVM updates, with different procedures:
1828

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.
29+
* Backports while the current major LLVM version is supported.
30+
* Backports while the current major LLVM version is no longer supported (or
31+
the change is not eligible for upstream backport).
32+
* Update to a new major LLVM version.
2233

23-
* LLVM itself may have a new release.
34+
## Backports (upstream supported)
2435

25-
Each of these reasons has a different strategy for updating LLVM, and we'll go
26-
over them in detail here.
36+
While the current major LLVM version is supported upstream, fixes should be
37+
backported upstream first, and the release branch then merged back into the
38+
Rust fork.
39+
40+
1. Make sure the bugfix is in upstream LLVM.
41+
2. If this hasn't happened already, request a backport to the upstream release
42+
branch. If you have LLVM commit access, follow the [backport process].
43+
Otherwise, open an issue requesting the backport. Continue once the
44+
backport has been approved and merged.
45+
3. Identify the branch that rustc is currently using. The `src/llvm-project`
46+
submodule is always pinned to a branch of the
47+
[rust-lang/llvm-project repository].
48+
4. Fork the rust-lang/llvm-project repository.
49+
5. Check out the appropriate branch (typically named `rustc/a.b-yyyy-mm-dd`).
50+
6. Add a remote for the upstream repository using
51+
`git remote add upstream https://github.com/llvm/llvm-project.git` and
52+
fetch it using `git fetch upstream`.
53+
7. Merge the `upstream/release/$N.x` branch.
54+
8. Push this branch to your fork.
55+
9. Send a Pull Request to rust-lang/llvm-project to the same branch as before.
56+
Be sure to reference the Rust and/or LLVM issue that you're fixing in the PR
57+
description.
58+
10. Wait for the PR to be merged.
59+
11. Send a PR to rust-lang/rust updating the `src/llvm-project` submodule with
60+
your bugfix. This can be done locally with `git submodule update --remote
61+
src/llvm-project` typically.
62+
12. Wait for PR to be merged.
63+
64+
An example PR:
65+
[#59089](https://github.com/rust-lang/rust/pull/59089)
2766

28-
## Bugfix Updates
67+
## Backports (upstream not supported)
2968

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:
69+
Upstream LLVM releases are only supported for two to three months after the
70+
GA release. Once upstream backports are no longer accepted, changes should be
71+
cherry-picked directly to our fork.
3272

3373
1. Make sure the bugfix is in upstream LLVM.
3474
2. Identify the branch that rustc is currently using. The `src/llvm-project`
3575
submodule is always pinned to a branch of the
3676
[rust-lang/llvm-project repository].
3777
3. Fork the rust-lang/llvm-project repository.
3878
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.
79+
5. Add a remote for the upstream repository using
80+
`git remote add upstream https://github.com/llvm/llvm-project.git` and
81+
fetch it using `git fetch upstream`.
82+
6. Cherry-pick the relevant commit(s) using `git cherry-pick -x`.
83+
7. Push this branch to your fork.
84+
8. Send a Pull Request to rust-lang/llvm-project to the same branch as before.
4285
Be sure to reference the Rust and/or LLVM issue that you're fixing in the PR
4386
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.
87+
9. Wait for the PR to be merged.
88+
10. Send a PR to rust-lang/rust updating the `src/llvm-project` submodule with
89+
your bugfix. This can be done locally with `git submodule update --remote
90+
src/llvm-project` typically.
91+
11. Wait for PR to be merged.
4992

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

0 commit comments

Comments
 (0)