|
3 | 3 | <!-- toc --> |
4 | 4 |
|
5 | 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: |
| 6 | +Rust supports building against multiple LLVM versions: |
8 | 7 |
|
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. |
14 | 12 |
|
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. |
16 | 16 |
|
17 | | -There are two reasons we would want to update LLVM: |
| 17 | +Our LLVM fork only accepts: |
18 | 18 |
|
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. |
22 | 21 |
|
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. |
24 | 24 |
|
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: |
27 | 26 |
|
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. |
29 | 31 |
|
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. |
32 | 70 |
|
33 | 71 | 1. Make sure the bugfix is in upstream LLVM. |
34 | 72 | 2. Identify the branch that rustc is currently using. The `src/llvm-project` |
35 | 73 | submodule is always pinned to a branch of the |
36 | 74 | [rust-lang/llvm-project repository]. |
37 | 75 | 3. Fork the rust-lang/llvm-project repository. |
38 | 76 | 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. |
42 | 83 | Be sure to reference the Rust and/or LLVM issue that you're fixing in the PR |
43 | 84 | 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. |
49 | 90 |
|
50 | 91 | An example PR: |
51 | 92 | [#59089](https://github.com/rust-lang/rust/pull/59089) |
@@ -187,3 +228,4 @@ keep in mind while going through them: |
187 | 228 | [`llvm-wrapper`]: https://github.com/rust-lang/rust/tree/master/compiler/rustc_llvm/llvm-wrapper |
188 | 229 | [wg-llvm]: https://rust-lang.zulipchat.com/#narrow/stream/187780-t-compiler.2Fwg-llvm |
189 | 230 | [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