Skip to content

Commit

Permalink
Update rules_rust to fix the issue with repinning the rust crates (so…
Browse files Browse the repository at this point in the history
…urcegraph#49698)

This PR updates `rules_rust` to `v0.19.0`, as we're using Rust `1.68.0`
which is only supported in that version. I suspect that's what caused
the strange errors when repinning.

Quoting @tjdevries explanation on the fix: 

> Pinned explicitly with features that match the features
> required by rocket. Once bazel rules correctly roll up all the
features,
> we can remove this, but until then, this works just fine for building
> with bazel (and we rarely update rocket, so this is fine).

The whole issue are coming from:
bazelbuild/rules_rust#1884 and
bazelbuild/rules_rust#1885 which are addressing
the problem upstream.

---

Still, this now circles back to a compilation error what we've
previously seen. To reproduce it

```
bazel build //docker-images/syntax-highlighter/...
```

Which in turn leads to the following errors: 

```
ERROR: /private/var/tmp/_bazel_tech/3eea80c6015362974b7d423d1f30cb62/external/crate_index__futures-util-0.3.21/BUILD.bazel:22:13: Compiling Rust rlib futures_util v0.3.21 (180 files) [for tool] failed: (Exit 1): process_wrapper failed: error executing command (from target @crate_index__futures-util-0.3.21//:futures_util) bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/rules_rust/util/process_wrapper/process_wrapper --env-file ... (remaining 82 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
error[E0432]: unresolved imports `futures_task::waker`, `futures_task::ArcWake`
  --> external/crate_index__futures-util-0.3.21/src/stream/stream/flatten_unordered.rs:21:20
   |
21 | use futures_task::{waker, ArcWake};
   |                    ^^^^^  ^^^^^^^ no `ArcWake` in the root
   |                    |
   |                    no `waker` in the root
   |                    help: a similar name exists in the module (notice the capitalization): `Waker`

error[E0432]: unresolved import `futures_task::ArcWake`
  --> external/crate_index__futures-util-0.3.21/src/task/mod.rs:23:9
   |
23 | pub use futures_task::ArcWake;
   |         ^^^^^^^^^^^^^^^^^^^^^ no `ArcWake` in the root

error[E0432]: unresolved import `futures_task::waker`
  --> external/crate_index__futures-util-0.3.21/src/task/mod.rs:27:9
   |
27 | pub use futures_task::waker;
   |         ^^^^^^^^^^^^^^-----
   |         |             |
   |         |             help: a similar name exists in the module (notice the capitalization): `Waker`
   |         no `waker` in the root

error[E0432]: unresolved imports `futures_task::waker_ref`, `futures_task::WakerRef`
  --> external/crate_index__futures-util-0.3.21/src/task/mod.rs:31:24
   |
31 | pub use futures_task::{waker_ref, WakerRef};
   |                        ^^^^^^^^^  ^^^^^^^^ no `WakerRef` in the root
   |                        |
   |                        no `waker_ref` in the root

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0432`.
ERROR: /private/var/tmp/_bazel_tech/3eea80c6015362974b7d423d1f30cb62/external/crate_index__futures-util-0.3.21/BUILD.bazel:22:13: Compiling Rust rlib futures_util v0.3.21 (180 files) failed: (Exit 1): process_wrapper failed: error executing command (from target @crate_index__futures-util-0.3.21//:futures_util) bazel-out/darwin_arm64-opt-exec-2B5CBBC6/bin/external/rules_rust/util/process_wrapper/process_wrapper --env-file ... (remaining 82 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
error[E0432]: unresolved imports `futures_task::waker`, `futures_task::ArcWake`
  --> external/crate_index__futures-util-0.3.21/src/stream/stream/flatten_unordered.rs:21:20
   |
21 | use futures_task::{waker, ArcWake};
   |                    ^^^^^  ^^^^^^^ no `ArcWake` in the root
   |                    |
   |                    no `waker` in the root
   |                    help: a similar name exists in the module (notice the capitalization): `Waker`

error[E0432]: unresolved import `futures_task::ArcWake`
  --> external/crate_index__futures-util-0.3.21/src/task/mod.rs:23:9
   |
23 | pub use futures_task::ArcWake;
   |         ^^^^^^^^^^^^^^^^^^^^^ no `ArcWake` in the root

error[E0432]: unresolved import `futures_task::waker`
  --> external/crate_index__futures-util-0.3.21/src/task/mod.rs:27:9
   |
27 | pub use futures_task::waker;
   |         ^^^^^^^^^^^^^^-----
   |         |             |
   |         |             help: a similar name exists in the module (notice the capitalization): `Waker`
   |         no `waker` in the root

error[E0432]: unresolved imports `futures_task::waker_ref`, `futures_task::WakerRef`
  --> external/crate_index__futures-util-0.3.21/src/task/mod.rs:31:24
   |
31 | pub use futures_task::{waker_ref, WakerRef};
   |                        ^^^^^^^^^  ^^^^^^^^ no `WakerRef` in the root
   |                        |
   |                        no `waker_ref` in the root

error: aborting due to 4 previous errors
```

## Test plan

<!-- All pull requests REQUIRE a test plan:
https://docs.sourcegraph.com/dev/background-information/testing_principles
-->

Green CI. 

## App preview:

- [Web](https://sg-web-jh-bzl-fix-rust.onrender.com/search)

Check out the [client app preview
documentation](https://docs.sourcegraph.com/dev/how-to/client_pr_previews)
to learn more.

---------

Co-authored-by: TJ DeVries <devries.timothyj@gmail.com>
Co-authored-by: Jason Bedard <jason@aspect.dev>
  • Loading branch information
3 people committed Mar 21, 2023
1 parent 4bc4234 commit 9349d29
Show file tree
Hide file tree
Showing 26 changed files with 2,499 additions and 920 deletions.
7 changes: 3 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,11 @@ http_archive(
],
)


http_archive(
name = "rules_rust",
sha256 = "d125fb75432dc3b20e9b5a19347b45ec607fabe75f98c6c4ba9badaab9c193ce",
# As of Mar 8 2023, the latest release is 0.18.0, but that release
# has a bug which triggers a compilation error in futures-util-0.3.21
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.17.0/rules_rust-v0.17.0.tar.gz"],
sha256 = "dc8d79fe9a5beb79d93e482eb807266a0e066e97a7b8c48d43ecf91f32a3a8f3",
urls = ["https://github.com/bazelbuild/rules_rust/releases/download/0.19.0/rules_rust-v0.19.0.tar.gz"],
)

# rules_js setup ================================
Expand Down
2 changes: 2 additions & 0 deletions client/branded/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions client/web/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/web/dev/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions client/web/src/integration/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion cmd/frontend/graphqlbackend/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dev/pr-auditor/BUILD.bazel

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions doc/dev/background-information/bazel.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ ERROR: /Users/william/code/sourcegraph/WORKSPACE:197:18: fetching crates_reposit
Error in path: Not a regular file: /Users/william/code/sourcegraph/docker-images/syntax-highlighter/fake.lock
ERROR: Error computing the main repository mapping: no such package '@crate_index//': Not a regular file: /Users/william/code/sourcegraph/docker-images/syntax-highlighter/Cargo.Bazel.lock
```
The error happens when the file specified in the lockfiles attribute of `crates_repository` (see WORKSPACE file for the definition) does not exist on disk. Currently this rule does not generate the file, instead it just generates the _content_ of the file. So to get passed this error you should create the file `touch docker-images/syntax-highlighter/Cargo.Bazel.lock`. With the file create it we can now populate `Cargo.Bazel.lock` with content using bazel by running `CARGO_BAZEL_REPIN=1 bazel sync --only=crates_index`.
The error happens when the file specified in the lockfiles attribute of `crates_repository` (see WORKSPACE file for the definition) does not exist on disk. Currently this rule does not generate the file, instead it just generates the _content_ of the file. So to get passed this error you should create the file `touch docker-images/syntax-highlighter/Cargo.Bazel.lock`. With the file create it we can now populate `Cargo.Bazel.lock` with content using bazel by running `CARGO_BAZEL_REPIN=1 bazel sync --only=crate_index`.

### When I build `syntax-highlighter` it complains that the current `lockfile` is out of date
The error will look like this:
Expand Down Expand Up @@ -332,7 +332,7 @@ ERROR: Error computing the main repository mapping: no such package '@crate_inde
The current `lockfile` is out of date for 'crate_index'. Please re-run bazel using `CARGO_BAZEL_REPIN=true` if this is expected and the lockfile should be updated.
```
Bazel uses a separate lock file to keep track of the dependencies and needs to be updated. To update the `lockfile` run `CARGO_BAZEL_REPIN=1 bazel sync --only=crates_index`. This command takes a while to execute as it fetches all the dependencies specified in `Cargo.lock` and populates `Cargo.Bazel.lock`.
Bazel uses a separate lock file to keep track of the dependencies and needs to be updated. To update the `lockfile` run `CARGO_BAZEL_REPIN=1 bazel sync --only=crate_index`. This command takes a while to execute as it fetches all the dependencies specified in `Cargo.lock` and populates `Cargo.Bazel.lock`.

## Resources

Expand Down
Loading

0 comments on commit 9349d29

Please sign in to comment.