Skip to content

Fixes Rust example 8 failing on downstream Bazel Head CI #554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 0 additions & 4 deletions .bazelci/tutorial-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,12 @@ tasks:
name: "Rust grpc"
platform: ubuntu2204
working_directory: ../rust-examples/08-grpc-client-server
run_targets: # This step is needed to generate the vendor directory required for the build to succeed.
- "//thirdparty:crates_vendor"
build_targets:
- "//..."
rust-08-grpc-client-server-macos:
name: "Rust grpc"
platform: macos_arm64
working_directory: ../rust-examples/08-grpc-client-server
run_targets: # This step is needed to generate the vendor directory required for the build to succeed.
- "//thirdparty:crates_vendor"
build_targets:
- "//..."
rust-09-oci-container-linux:
Expand Down
2 changes: 1 addition & 1 deletion rust-examples/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.0.1
8.1.0
77 changes: 65 additions & 12 deletions rust-examples/08-grpc-client-server/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ bazel_dep(name = "toolchains_llvm", version = "1.2.0", dev_dependency = True)
###############################################################################
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(
llvm_version = "18.1.8",
llvm_version = "19.1.6-1",
sha256 = {
# Generate checksums with shasum -a 256 filename.tar.zst
"darwin-aarch64": "41d8dea52d18c4e8b90c4fcd31965f9f297df9f40a38a33d60748dbe7f8330b8",
"darwin-x86_64": "",
"linux-aarch64": "",
"linux-x86_64": "",
"darwin-aarch64": "94ed965925dbdc25b29e6fcfa9a84b28d915d5c9da7c71405fc20bbcf8396bd1",
"darwin-x86_64": "9395b07fd5018816bcaee84522d9c9386fdbefe62fdf8afff89b57e1b7095463",
"linux-aarch64": "24fd3405f65ccbc39f0d14a5126ee2edb5904d7a9525ae483f34a510a1bdce3e",
"linux-x86_64": "bad3d776c222c99056eba8b64c085a1e08edd783cb102e1b6eba43b78ce2fe2b",
},
stdlib = {
"linux-x86_64": "stdc++",
"linux-aarch64": "stdc++",
},
urls = {
"darwin-aarch64": ["https://github.com/MaterializeInc/toolchains/releases/download/clang-18.1.8-4/darwin_aarch64.tar.zst"],
"darwin-x86_64": ["https://github.com/MaterializeInc/toolchains/releases/download/clang-18.1.8-4/darwin_x86_64.tar.zst"],
"linux-aarch64": ["https://github.com/MaterializeInc/toolchains/releases/download/clang-18.1.8-4/linux_aarch64.tar.zst"],
"linux-x86_64": ["https://github.com/MaterializeInc/toolchains/releases/download/clang-18.1.8-4/linux_x86_64.tar.zst"],
"darwin-aarch64": ["https://github.com/MaterializeInc/toolchains/releases/download/clang-19.1.6-1/darwin_aarch64.tar.zst"],
"darwin-x86_64": ["https://github.com/MaterializeInc/toolchains/releases/download/clang-19.1.6-1/darwin_x86_64.tar.zst"],
"linux-aarch64": ["https://github.com/MaterializeInc/toolchains/releases/download/clang-19.1.6-1/linux_aarch64.tar.zst"],
"linux-x86_64": ["https://github.com/MaterializeInc/toolchains/releases/download/clang-19.1.6-1/linux_x86_64.tar.zst"],
},
)

Expand All @@ -59,7 +59,60 @@ use_repo(rust, "rust_toolchains")

register_toolchains("@rust_toolchains//:all")

# Custom Rust Prost toolchain
register_toolchains("@//build/prost_toolchain")
# Custom Prost toolchain
register_toolchains(
"@//build/prost_toolchain",
)

# Rust crate dependencies.
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")

# protobuf / gRPC dependencies
crate.spec(
package = "prost",
version = "0.13.0",
)
crate.spec(
default_features = False,
package = "prost-types",
version = "0.13.0",
)
crate.spec(
features = ["transport"],
package = "tonic",
version = "0.12.0",
)
crate.spec(
package = "tonic-build",
version = "0.12.0",
)
crate.spec(
package = "protoc-gen-prost",
version = "0.4",
)
crate.annotation(
crate = "protoc-gen-prost",
gen_binaries = ["protoc-gen-prost"],
)
crate.spec(
package = "protoc-gen-tonic",
version = "0.4",
)
crate.annotation(
crate = "protoc-gen-tonic",
gen_binaries = ["protoc-gen-tonic"],
)

# Rust dependencies. See thirdparty/BUILD.bazel
crate.spec(
default_features = False,
features = [
"macros",
"net",
"rt-multi-thread",
"signal",
],
package = "tokio",
version = "1.39.3",
)
crate.from_specs()
use_repo(crate, "crates")
25 changes: 0 additions & 25 deletions rust-examples/08-grpc-client-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,6 @@ This example shows how to build a gRPC server and client in Rust with Bazel.
There is a Cargo Workspace configuration and a Bazelmod configuration. Furthermore,
all binary targets apply optimization from the [compiler optimization example](../03-comp-opt).

Before you can run the example, you must vendor all dependencies. You can do this as follows:

`
bazel run //thirdparty:crates_vendor
`

This may take a moment because Bazel downloads all the dependencies and stores them in the folder `thirdparty/crates`.

And then build all targets:

`bazel build //...`

If you ever see an error stating:

```text
no such package 'thirdparty/crates':
BUILD file not found in any of the following directories.
```

Just run:

`bazel run //thirdparty:crates_vendor`

And then build again; the build will succeed.


To run the example with Cargo, open one terminal and start the server with:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@ load("@rules_rust_prost//:defs.bzl", "rust_prost_toolchain")
rust_library_group(
name = "prost_runtime",
deps = [
"//thirdparty/crates:prost",
"@crates//:prost",
],
)

rust_library_group(
name = "tonic_runtime",
deps = [
":prost_runtime",
"//thirdparty/crates:tonic",
"@crates//:tonic",
],
)

# https://github.com/bazelbuild/rules_rust/blob/main/examples/bzlmod/proto_with_toolchain/build/prost_toolchain/BUILD.bazel
rust_prost_toolchain(
name = "prost_toolchain_impl",
prost_plugin = "//thirdparty/crates:protoc-gen-prost__protoc-gen-prost",
prost_plugin = "@crates//:protoc-gen-prost__protoc-gen-prost",
prost_runtime = ":prost_runtime",
prost_types = "//thirdparty/crates:prost-types",
tonic_plugin = "//thirdparty/crates:protoc-gen-tonic__protoc-gen-tonic",
prost_types = "@crates//:prost-types",
tonic_plugin = "@crates//:protoc-gen-tonic__protoc-gen-tonic",
tonic_runtime = ":tonic_runtime",
visibility = ["//visibility:public"],
)

toolchain(
name = "prost_toolchain",
toolchain = "prost_toolchain_impl",
toolchain_type = "@rules_rust_prost//:toolchain_type",
)
)
4 changes: 2 additions & 2 deletions rust-examples/08-grpc-client-server/grpc_client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ rust_binary(
# Internal crates
"//proto_bindings:rust_proto",
# External crates
"//thirdparty/crates:tokio",
"//thirdparty/crates:tonic",
"@crates//:tokio",
"@crates//:tonic",
],
)

Expand Down
4 changes: 2 additions & 2 deletions rust-examples/08-grpc-client-server/grpc_server/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ rust_binary(
# Internal crates
"//proto_bindings:rust_proto",
# External crates
"//thirdparty/crates:tokio",
"//thirdparty/crates:tonic",
"@crates//:tokio",
"@crates//:tonic",
],
)

Expand Down
68 changes: 0 additions & 68 deletions rust-examples/08-grpc-client-server/thirdparty/BUILD.bazel

This file was deleted.

9 changes: 9 additions & 0 deletions rust-examples/09-oci-container/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ You have to define your target registry in the [binary BUILD](tokio_oci/BUILD.ba
before you can publish your image. For details of how to configure a container registry,
please [consult the official documentation.](https://github.com/bazel-contrib/rules_oci/blob/main/docs/push.md)

## Updating dependencies

* Add or update dependencies in `thirdparty/BUILD.bazel`.
* Then run the vendoring target: `bazel run //thirdparty:crates_vendor`
* Rebuild the project: `bazel build //...`
* Run all tests: `bazel test //...`

See the [vendoring example](../07-deps-vendor) for details.

## Setup

The new rules_oci build container images in Bazel without Docker. The setup is a straightforward three step process:
Expand Down
44 changes: 44 additions & 0 deletions rust-examples/09-oci-container/thirdparty/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")

crates_vendor(
name = "crates_vendor",
annotations = {},
mode = "local",
packages = {
"arc-swap": crate.spec(
package = "arc-swap",
version = "1.7.0",
),
"serde": crate.spec(
features = ["derive"],
package = "serde",
version = "1.0",
),
"serde_json": crate.spec(
package = "serde_json",
version = "1.0",
),
"tokio": crate.spec(
default_features = False,
features = [
"macros",
"net",
"rt-multi-thread",
"signal",
],
package = "tokio",
version = "1.40.0",
),
"tokio-cron-scheduler": crate.spec(
features = ["signal"],
package = "tokio-cron-scheduler",
version = "0.11",
),
"warp": crate.spec(
package = "warp",
version = "0.3",
),
},
repository_name = "queng_vendored",
tags = ["manual"],
)
Loading