Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .bazelci/misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ tasks:
- "//:tests"
third-party-dependencies-linux:
name: "Example with third party dependencies"
platform: ubuntu1804
platform: ubuntu2204
working_directory: ../third-party-dependencies
build_targets:
- "..."
third-party-dependencies-macos:
name: "Example with third party dependencies"
platform: macos
platform: macos_arm64
working_directory: ../third-party-dependencies
build_targets:
- "..."
Expand Down
2 changes: 1 addition & 1 deletion java-maven/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.1.0
8.x
8 changes: 4 additions & 4 deletions java-maven/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"Bazel dependencies"

bazel_dep(name = "aspect_bazel_lib", version = "2.8.1")
bazel_dep(name = "container_structure_test", version = "1.16.0")
bazel_dep(name = "rules_jvm_external", version = "5.3")
bazel_dep(name = "rules_oci", version = "1.4.0")
bazel_dep(name = "aspect_bazel_lib", version = "2.21.2")
bazel_dep(name = "container_structure_test", version = "1.19.1")
bazel_dep(name = "rules_jvm_external", version = "6.8")
bazel_dep(name = "rules_oci", version = "2.2.6")
bazel_dep(name = "rules_java", version = "7.11.1")

maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
Expand Down
2 changes: 1 addition & 1 deletion rust-examples/01-hello-world/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module(
)

# https://github.com/bazelbuild/rules_rust/releases
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "rules_rust", version = "0.65.0")

# Rust toolchain
RUST_EDITION = "2021" # NOTE: 2024 edition will be released with Rust 1.85.0
Expand Down
2 changes: 1 addition & 1 deletion rust-examples/02-hello-cross/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module(
###############################################################################
# B A Z E L D E P E N D E N C I E S # https://registry.bazel.build/
###############################################################################
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "rules_rust", version = "0.65.0")
bazel_dep(name = "platforms", version = "0.0.11")

bazel_dep(name = "toolchains_llvm", version = "1.2.0", dev_dependency = True)
Expand Down
2 changes: 1 addition & 1 deletion rust-examples/03-comp-opt/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module(
)

# https://github.com/bazelbuild/rules_rust/releases
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "rules_rust", version = "0.65.0")

RUST_EDITION = "2021" # NOTE: 2024 will be released with Rust 1.86.0

Expand Down
2 changes: 1 addition & 1 deletion rust-examples/04-ffi/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module(
)

# https://github.com/bazelbuild/rules_rust/releases
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "rules_rust", version = "0.65.0")
bazel_dep(name = "rules_cc", version = "0.0.9")

# Rust toolchain
Expand Down
2 changes: 1 addition & 1 deletion rust-examples/05-deps-cargo/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module(
)

# https://github.com/bazelbuild/rules_rust/releases
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "rules_rust", version = "0.65.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")

# Rust toolchain
Expand Down
2 changes: 1 addition & 1 deletion rust-examples/06-deps-direct/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module(
)

# https://github.com/bazelbuild/rules_rust/releases
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "rules_rust", version = "0.65.0")

# Rust toolchain
RUST_EDITION = "2021"
Expand Down
2 changes: 1 addition & 1 deletion rust-examples/07-deps-vendor/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module(
)

# https://github.com/bazelbuild/rules_rust/releases
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "rules_rust", version = "0.65.0")

# Rust toolchain
RUST_EDITION = "2021" # NOTE: 2024 edition will be released with Rust 1.85.0
Expand Down
40 changes: 20 additions & 20 deletions rust-examples/07-deps-vendor/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Vendored Rust Dependencies

This example shows how to vendor Rust dependencies and use those vendored dependencies
in a binary target.
This example shows how to vendor Rust dependencies and use those vendored dependencies
in a binary target.

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

`
Expand All @@ -19,8 +19,8 @@ If you ever see an error stating:

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

Just run:

Expand All @@ -31,7 +31,7 @@ And then build again; the build will succeed.
## Setup

For the setup, you just add rules_rust as usual. Note, you do not declare any dependencies
or crate_universe at this stage.
or crate_universe at this stage.

```starlark
module(
Expand All @@ -40,7 +40,7 @@ module(
)

# https://github.com/bazelbuild/rules_rust/releases
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "rules_rust", version = "0.65.0")

# Rust toolchain
RUST_EDITION = "2021" # NOTE: 2024 edition will be released with Rust 1.85.0
Expand All @@ -60,23 +60,23 @@ register_toolchains("@rust_toolchains//:all")
```


The vendor folder name can be arbitrary, but by convention, its either thirdparty or 3rdparty to indicate vendored dependencies. Also note, you can structure any number of sub-folders in the vendor folder for example. Note, in that case, each sub-folder must have a `BUILD.bazel` file that declares its vendored dependencies.
The vendor folder name can be arbitrary, but by convention, its either thirdparty or 3rdparty to indicate vendored dependencies. Also note, you can structure any number of sub-folders in the vendor folder for example. Note, in that case, each sub-folder must have a `BUILD.bazel` file that declares its vendored dependencies.

```starlark
basic
thirdparty
├── common
│ ├── tokio
│ ├── warp
│ ├── warp
├── sys
│ ├── bzip2
├── macros
│ ├── sys
│ ├── sys
```



In this example, the vendor folder is named thirdparty and you add a `BUILD.bazel` to declare your dependencies, for example:

In this example, the vendor folder is named thirdparty and you add a `BUILD.bazel` to declare your dependencies, for example:

```starlark
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")
Expand All @@ -103,39 +103,39 @@ crates_vendor(
)
```

Then you run `bazel run //thirdparty:crates_vendor` which then downloads all the dependencies and creates the folder `thirdparty/crates`.
Then you run `bazel run //thirdparty:crates_vendor` which then downloads all the dependencies and creates the folder `thirdparty/crates`.

**Important:**

By default, vendoring does not pin versions defined in crate.spec, which means if you were to declare a Tokio version 1.40
and a newer Tokio version 1.44 is already available, the newer version will be used without notifying you.
You can pin versions by using a `=` prefix in the `version` field, for example: `version = "=1.44.0"`. Only then rules_rust
You can pin versions by using a `=` prefix in the `version` field, for example: `version = "=1.44.0"`. Only then rules_rust
will use the exact version you have declared.


At this point, you have the following folder and files:
```starlark
basic
thirdparty
├── crates/
├── crates/
├── BUILD.bazel
```

Bazel generated a bunch of files and folder in the crates folder. For the most part, you just run
a build and when it completes, you then just check these vendored dependencies into git to ensure
all subsequent and CI build use the exact same dependencies.
all subsequent and CI build use the exact same dependencies.

## Usage

Suppose you have an application in `basic/src` that is defined in `basic/BUILD.bazel` and
Suppose you have an application in `basic/src` that is defined in `basic/BUILD.bazel` and
that depends on a vendored dependency. You find a list of all available vendored dependencies
in the BUILD file of the generated folder: `basic/3rdparty/crates/BUILD.bazel`
You declare a vendored dependency in you target as following:


**Important:**

The vendor script crates two aliases, one without version number and one with version number.
The vendor script crates two aliases, one without version number and one with version number.
It is generally recommended to use the alias without version number unless you have a specific reason
to pin a specific crate version.

Expand All @@ -147,8 +147,8 @@ rust_binary(
srcs = ["src/main.rs"],
visibility = ["//visibility:public"],
deps = [
"//thirdparty/crates:tokio", # Generally recommended to use the alis without version since mature crates rarely break.
# "//thirdparty/crates:tokio-1.43.0", # Uncomment the the versioned alias if you have to pin the exact crate version.
"//thirdparty/crates:tokio", # Generally recommended to use the alis without version since mature crates rarely break.
# "//thirdparty/crates:tokio-1.43.0", # Uncomment the the versioned alias if you have to pin the exact crate version.
],
)
```
Expand Down
4 changes: 2 additions & 2 deletions rust-examples/08-grpc-client-server/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ module(
# https://registry.bazel.build/
###############################################################################
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "rules_rust_prost", version = "0.57.1")
bazel_dep(name = "rules_rust", version = "0.65.0")
bazel_dep(name = "rules_rust_prost", version = "0.65.0")
bazel_dep(name = "rules_proto", version = "7.1.0")

# Toolchains
Expand Down
16 changes: 8 additions & 8 deletions rust-examples/08-grpc-client-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ See the compiler [optimization example](../03-comp-opt) for configuration detail

## Setup

The Prost and Tonic rules do not specify a default toolchain in order to avoid mismatched dependency issues.
The Prost and Tonic rules do not specify a default toolchain in order to avoid mismatched dependency issues.
While the Tonic toolchain works out of the box when its dependencies are matched, however,
Prost requires a custom toolchain that you have to define.

The setup requires three steps to complete:
1. Configure rules and dependencies
The setup requires three steps to complete:
1. Configure rules and dependencies
2. Configure a custom Prost toolchain
3. Register custom Prost toolchain.

To keep the build hermetic, we use the LLVM Clang compiler to compile all C/C++ dependencies.
To keep the build hermetic, we use the LLVM Clang compiler to compile all C/C++ dependencies.

### 1) Configure rules
### 1) Configure rules

### Rules

Expand All @@ -55,7 +55,7 @@ In your MODULE.bazel, you add the following:
# rules for proto
###############################################################################
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "rules_rust", version = "0.65.0")
bazel_dep(name = "rules_rust_prost", version = "0.57.1")
bazel_dep(name = "rules_proto", version = "7.1.0")

Expand Down Expand Up @@ -107,7 +107,7 @@ register_toolchains("@rust_toolchains//:all")
# Custom Rust Prost toolchain
register_toolchains("@//build/prost_toolchain")

# Rust dependencies. See thirdparty/BUILD.bazel
# Rust dependencies. See thirdparty/BUILD.bazel
```

Pay attention to the path, `build/prost_toolchain` because if your custom prost toolchain
Expand All @@ -118,7 +118,7 @@ is in a different folder, you have to update this path to make the build work.
This example uses [direct dependencies]( https://bazelbuild.github.io/rules_rust/crate_universe_bzlmod.html#direct-dependencies), so you add the following to your MODULE.bazel file:

Notice the crate annotations are required for tonic and prost and
are later used in the toolchain setup.
are later used in the toolchain setup.

```starlark
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
Expand Down
2 changes: 1 addition & 1 deletion rust-examples/09-oci-container/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module(
# Bazel Dependencies
# https://registry.bazel.build/
###############################################################################
bazel_dep(name = "rules_rust", version = "0.57.1")
bazel_dep(name = "rules_rust", version = "0.65.0")
bazel_dep(name = "rules_oci", version = "2.2.1")
bazel_dep(name = "rules_pkg", version = "1.0.1")

Expand Down
1 change: 0 additions & 1 deletion third-party-dependencies/.bazelrc

This file was deleted.

2 changes: 1 addition & 1 deletion third-party-dependencies/.bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.5.0
7.x
4 changes: 2 additions & 2 deletions third-party-dependencies/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

bazel_dep(name = "buildifier_prebuilt", version = "6.3.3", dev_dependency = True)

bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_cc", version = "0.2.8")
bazel_dep(name = "catch2", version = "3.4.0")
bazel_dep(name = "googletest", version = "1.14.0", repo_name = "gtest")
bazel_dep(name = "googletest", version = "1.17.0", repo_name = "gtest")