Skip to content

Commit ca7ae04

Browse files
danakjAravind Vasudevan
authored andcommitted
Destroy the clang-libs package, remove build_chromium_rust_toolchain
Stop packaging the clang-libs package on the clang builder as it was designed for building Bindgen inside the chromium build and that is no longer done. Bindgen is built along with the Rust toolchain on the toolchain bots. Remove the checkout_clang_libs DEPS variable and the scripts to grab them. Remove the build_chromium_rust_toolchain DEPS variable which would build the Rust toolchain as part of gclient sync. This is not used by any bots. The toolchain is built through a recipe. Remove the checkout_rust_toolchain_deps DEPS variable as its the same as setting checkout_rust: False, so we don't need both. The toolchain bots don't need to set this since they don't gclient sync and if they did, they could set checkout_rust to False instead. R=hans@chromium.org Bug: 1426886 Change-Id: I47f91f6fa69ae964e031a98091da47874c7781fc Cq-Include-Trybots: luci.chromium.try:android-rust-arm32-rel,android-rust-arm64-dbg,android-rust-arm64-rel,linux-rust-x64-dbg,linux-rust-x64-rel Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4408005 Reviewed-by: Hans Wennborg <hans@chromium.org> Commit-Queue: danakj <danakj@chromium.org> Cr-Commit-Position: refs/heads/main@{#1130134} NOKEYCHECK=True GitOrigin-RevId: 358a7f4aa1aa14339c10453fd2f8136279349288
1 parent 97e9423 commit ca7ae04

File tree

1 file changed

+48
-218
lines changed

1 file changed

+48
-218
lines changed

README.md

Lines changed: 48 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -21,198 +21,64 @@ build it centrally (with the scripts here) and distribute it for all to use
2121

2222
## Rust build overview
2323

24-
Each Rust package is built from an official Rust nightly source release and a
25-
corresponding LLVM revision. Hence a new Rust package must be built whenever
26-
either Rust or Clang is updated.
24+
Each Rust package is built from an Rust git, usually from HEAD directly, along
25+
with the current Clang/LLVM revision in use in Chromium. Hence a new Rust
26+
package must be built whenever either Rust or Clang is updated. When building
27+
Rust we also build additional tools such as clippy and rustfmt, and interop
28+
tools including bindgen and crubit.
2729

28-
Chromium's Clang build process leaves behind several artifacts needed for the
29-
Rust build. Each Rust build begins after a Clang build and uses these artifacts,
30-
which include `clang`, LLVM libraries, etc.
30+
The Rust build also includes building LLVM for rustc to use, and Clang for
31+
bindgen and crubit to use.
3132

32-
A special CI job is used to build Clang and Rust from the revisions specified in
33-
the Chromium source tree. These are uploaded to a storage bucket. After being
34-
manually blessed by a developer, they can then be fetched by Chromium checkouts.
33+
The `*_upload_clang` and `*_upload_rust` trybots are used to build Clang and
34+
Rust respectively from the revisions specified in the Chromium source tree.
35+
These are uploaded to a storage bucket when the build succeeds. After being
36+
copied from staging to production by a developer (see
37+
[cs/copy_staging_to_prod_and_goma.sh](
38+
http://cs/copy_staging_to_prod_and_goma.sh)), they can then be fetched by
39+
`gclient sync`.
3540

36-
Scripts are provided in tree to fetch the packages for the specified revisions.
41+
The `update_rust.py` script is used by `gclient sync` to fetch the Rust
42+
toolchain for the revisions specified in the script.
3743

38-
Whenever a Chromium checkout is updated, `gclient` hooks will update the
39-
toolchain packages to match the revisions listed in tree.
44+
## Rolling Rust
4045

46+
Follow the directions in [//docs/updating_clang.md](
47+
../../docs/updating_clang.md) to roll Clang and Rust together. To just
48+
roll Rust on its own, use the `--skip-clang` argument when running
49+
`upload_revision.py`.
4150

42-
## Updating Rust
51+
The upload_revision.py script will update the revision of Rust to be
52+
built and used in `update_rust.py` and will start the trybots that
53+
will build the Rust toolchain.
4354

44-
### Set the revision
55+
After the build has succeeded and the new toolchain has been copied to
56+
production, the CQ will run trybots to verify that our code still builds
57+
and tests pass with the new Rust toolchain.
4558

46-
First, pick a new instance of the [CIPD `rust_src`
47-
package](https://chrome-infra-packages.appspot.com/p/chromium/third_party/rust_src/+/).
48-
Click it and copy the version ID (e.g. `version:2@2022-01-01`) to the `//DEPS` entry for
49-
`src/third_party/rust_src/src`. For example (though don't change the other parts
50-
of the entry):
59+
### Possible failure: Missing dependencies
5160

52-
```
53-
'src/third_party/rust_src/src': {
54-
'packages': [
55-
{
56-
'package': 'chromium/third_party/rust_src',
57-
'version': 'version:2@2022-01-01',
58-
},
59-
],
60-
# ...
61-
},
62-
```
63-
64-
Similarly, update the `RUST_REVISION` named in `//tools/rust/update_rust.py`,
65-
removing dashes from the date (e.g. `version:2@2022-01-01` becomes
66-
`RUST_REVISION = '20220101'`). Reset `RUST_SUB_REVISION = 1`.
67-
68-
Run the following to check for changes to Rust's `src/stage0.json`, which
69-
contains revisions of upstream binaries to be fetched and used in the Rust
70-
build:
71-
72-
```
73-
tools/rust/build_rust.py --verify-stage0-hash
74-
```
75-
76-
If it exists without printing anything, the stage0 hash is up-to-date and
77-
nothing needs to be done. Otherwise, it will print the actual hash like so:
78-
79-
```
80-
...
81-
Actual hash: 6b1c61d494ad447f41c8ae3b9b3239626eecac00e0f0b793b844e0761133dc37
82-
...
83-
```
84-
85-
...in which case you should check the `stage0.json` changes for trustworthiness
86-
(criteria TBD) and then update `STAGE0_JSON_SHA256` in update_rust.py with the
87-
new hash. Re-run the above and confirm it succeeds.
88-
89-
90-
### Optional: build locally and run tests
91-
92-
This step is not strictly necessary since the CI tooling will catch any errors.
93-
But the CI build process is slow and this can save some time.
94-
95-
To fetch the new Rust sources, and avoid errors during `gclient sync`:
96-
1. Ensure your `.gclient` file has `checkout_rust_toolchain_deps` set to `True`,
97-
but avoid setting `use_rust` to `True`. The latter will try to download the
98-
compiled rustc but as you've just updated the version there is no compiled rustc
99-
to download so it will fail.
100-
1. Additionally, to aid in testing, turn off rust support in GN, with
101-
`enable_rust = false`, since it requires the presence of a Rust toolchain, but
102-
building the toolchain destroys your local toolchain until the build succeeds.
103-
104-
Running this will do a full build and provide a local toolchain that works for
105-
the host machine, albeit not the same as the CI-provided one:
106-
107-
```
108-
tools/rust/build_rust.py --fetch-llvm-libs --use-final-llvm-build-dir
109-
```
110-
111-
To do a full build, first build Clang locally (TODO: provide instructions) then
112-
simply run `tools/rust/build_rust.py` with no arguments.
113-
114-
However, for most cases simply doing
115-
116-
```
117-
tools/rust/build_rust.py --fetch-llvm-libs --use-final-llvm-build-dir --run-xpy -- build --stage 1 library/std
118-
```
119-
120-
will catch most errors and will be fast.
121-
122-
### Upload CL
123-
124-
Run `tools/clang/scripts/upload_revision.py` to roll Clang and Rust to the
125-
latest revision. It will update `//DEPS` and `/tools/rust/update_rust.py` with
126-
new Rust version info, upload a CL to gerrit, and start tryjobs to build the
127-
toolchain.
128-
129-
See [//docs/updating_clang.md](../../docs/updating_clang.md) for more info
130-
on to roll Clang and Rust.
131-
132-
To roll Rust only, (make sure you are synced to HEAD and) pass the current Clang
133-
version to `tools/clang/scripts/upload_revision.py`, as:
134-
```
135-
tools/clang/scripts/upload_revision.py --clang-git-hash HASH --clang-sub-revision SUBREV
136-
```
137-
138-
The `HASH` and `SUBREV` can be found from:
139-
```
140-
# HASH
141-
grep ^CLANG_REVISION tools/clang/scripts/update.py | sed -E 's/.*-g([0-9a-z]+).*/\1/'
142-
# SUBREV
143-
grep ^CLANG_SUB_REVISION tools/clang/scripts/update.py | sed -E 's/.*([0-9a-z]+).*/\1/'
144-
```
145-
146-
If you want to use an older version of Rust, use `cipd` to find the version
147-
you want to use.
148-
149-
To find all instances of the Rust toolchain sources available:
150-
```
151-
cipd instances chromium/third_party/rust_src
152-
```
153-
154-
This will output something like:
155-
```
156-
Instance ID │ Timestamp │ Uploader │ Refs
157-
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
158-
6fLkoaoLWCFzVUlkhDevcLHj18bTXF5DxSCQTtNTJaMC │ Dec 15 06:16 EST 2022 │ chromium-cipd-builder@... │ latest
159-
ohKW73PweFtV25O9vCbRzZoF1nxHGfurbLc0NWV2io8C │ Dec 14 06:13 EST 2022 │ chromium-cipd-builder@... │
160-
J6zeUMnPfukyu5fo0NFdAH6w9HEDyJzo1D0YhrP15bcC │ Dec 13 06:10 EST 2022 │ chromium-cipd-builder@... │
161-
pd-8U_6sH8y0dUwfFNUqKcu9GkMYnZmE2e6dOVG7ONUC │ Dec 12 06:12 EST 2022 │ chromium-cipd-builder@... │
162-
```
163-
164-
From here, you may get the version info for an intance with:
165-
```
166-
cipd describe chromium/third_party/rust_src -version INSTANCE_ID
167-
```
168-
169-
With `INSTANCE_ID` as `ohKW73PweFtV25O9vCbRzZoF1nxHGfurbLc0NWV2io8C`, the
170-
describe output looks something like:
171-
```
172-
Package: chromium/third_party/rust_src
173-
Instance ID: ohKW73PweFtV25O9vCbRzZoF1nxHGfurbLc0NWV2io8C
174-
Tags:
175-
version:2@2022-12-14
176-
```
177-
178-
The Rust toolchain version is what comes after `version:` in the tags. In this
179-
case, it would be `2@2022-12-14`.
180-
181-
Then, pass this version to `tools/clang/scripts/upload_revision.py` as in:
182-
```
183-
tools/clang/scripts/upload_revision.py --rust-cipd-version 2@2022-12-14
184-
```
185-
186-
This will generate a patch and upload it to Gerrit with the specified Rust
187-
toolchain version.
188-
189-
### Verify that Rust compiled
190-
191-
The `tools/clang/scripts/upload_revision.py` starts builders that will compile
192-
Clang and Rust. At this time, the builders succeed **even if Rust failed**. To
193-
see if Rust did compile, check the build page (e.g.
194-
https://ci.chromium.org/ui/p/chromium/builders/try/linux_upload_clang/2611/overview)
195-
and confirm the "package rust" step succeeded. If it did not, further
196-
investigation is needed.
197-
198-
### Upload to production
199-
200-
After the package is built, a developer with permissions must copy the uploaded
201-
(Clang and) Rust packages from staging to production, in order for `gclient
202-
sync` to find them. This must be done before submitting the CL or it will break
203-
`gclient sync` for all Rust users. As of writing, anyone in [Clang
204-
OWNERS](/tools/clang/scripts/OWNERS) or collinbaker@chromium.org can perform
205-
this task.
61+
`build_rust.py` will vendor all dependencies before starting the build. To do
62+
this it first initializes git submodules. Then it runs `cargo vendor`. However
63+
some parts of the compiler build are excluded from the top level Cargo.toml
64+
workspace. Thus it passes `--sync dir` for a number of subdirectories, based
65+
on [dist.rs, the nightly tarball packager](
66+
https://github.com/rust-lang/rust/blob/master/src/bootstrap/dist.rs#L986-L995).
20667

207-
### Submit CL
68+
If another Cargo.toml is required in the future, and not part of the workspace
69+
it would produce missing dependencies, and the set of directories in
70+
`build_rust.py` would need to be updated.
20871

209-
Once the package has been uploaded to production (see above), it is ready to be
210-
fetched from any Chromium checkout.
72+
### Local development
21173

212-
Submit the CL. CQ tryjobs will use the specified toolchain package
213-
version. Any build failures will need to be investigated, as these indicate
214-
breaking changes to Rust.
74+
To build the Rust toolchain locally, run `//tools/rust/build_rust.py`. It
75+
has additional flags to skip steps if you're making local changes and want
76+
to retry a build. The script will produce its outputs in
77+
`//third_party/rust-toolchain/`, which is the same place that `gclient sync`
78+
places them.
21579

80+
Building the `rust_build_tests` GN target is a good way to quickly verify the
81+
toolchain is working.
21682

21783
## Rolling Crubit tools
21884

@@ -232,19 +98,10 @@ to a new version:
23298
be made obsolete once Rust-specific tryjobs cover Crubit
23399
tests.
234100

235-
236-
## Building and testing the tools locally
101+
## Building and testing Crubit locally
237102

238103
### Prerequisites
239104

240-
#### LLVM/Clang build
241-
242-
`build_crubit.py` depends on having a locally-built LLVM/Clang:
243-
`tools/clang/scripts/build.py --bootstrap --without-android --without-fuchsia`.
244-
Among other things this prerequisite is required to generate
245-
`third_party/llvm-bootstrap-install` where `build_crubit.py` will look for
246-
LLVM/Clang libs and headers).
247-
248105
#### Bazel
249106

250107
`build_crubit.py` depends on Bazel.
@@ -267,19 +124,13 @@ solutions = [
267124
]
268125
```
269126

270-
#### Supported host platforms
271-
272-
So far `build_crubit.py` has only been tested on Linux hosts.
273-
274127
### Building
275128

276-
Just run `tools/rust/build_rust.py` or `tools/rust/build_crubit.py`.
129+
Just run `tools/rust/build_crubit.py`. So far `build_crubit.py` has only been
130+
tested on Linux hosts.
277131

278132
### Deploying
279133

280-
`build_rust.py` by default copies the newly build executables/binaries into
281-
`//third_party/rust-toolchain`.
282-
283134
`build_crubit.py` will copy files into the directory specified in the
284135
(optional) `--install-to` cmdline parameter - for example:
285136

@@ -289,29 +140,8 @@ $ tools/rust/build_crubit.py --install-to=third_party/rust-toolchain/bin/
289140

290141
### Testing
291142

292-
Ensure that `args.gn` contains `enable_rust = true` and then build
293-
`//build/rust/tests` directory - e.g. `ninja -C out/rust build/rust/tests`.
294-
295-
Native Rust tests from `//build/rust` can be run via
296-
`out/rust/bin/run_build_rust_tests`.
297-
298143
Crubit tests are under `//build/rust/tests/test_rs_bindings_from_cc`. Until
299144
Crubit is built on the bots, the tests are commented out in
300145
`//build/rust/tests/BUILD.gn`, but they should still be built and run before
301146
rolling Crubit. TODO(https://crbug.com/1329611): Rephrase this paragraph
302147
after Crubit is built and tested on the bots.
303-
304-
## Possible Failures
305-
306-
### Missing dependencies
307-
308-
`build_rust.py` will vendor all dependencies before starting the build. To do
309-
this it first initializes git submodules. Then it runs `cargo vendor`. However
310-
some parts of the compiler build are excluded from the top level Cargo.toml
311-
workspace. Thus it passes `--sync dir` for a number of subdirectories, based
312-
on [dist.rs, the nightly tarball packager](
313-
https://github.com/rust-lang/rust/blob/master/src/bootstrap/dist.rs#L986-L995).
314-
315-
If another Cargo.toml is required in the future, and not part of the workspace
316-
it would produce missing dependencies, and the set of directories in
317-
`build_rust.py` would need to be updated.

0 commit comments

Comments
 (0)