diff --git a/crate_universe_bzlmod.html b/crate_universe_bzlmod.html index 38633e432f..99a702b96e 100644 --- a/crate_universe_bzlmod.html +++ b/crate_universe_bzlmod.html @@ -180,11 +180,11 @@

Table of

Setup

To use rules_rust in a project using bzlmod, add the following to your MODULE.bazel file:

-
bazel_dep(name = "rules_rust", version = "0.49.3")
+
bazel_dep(name = "rules_rust", version = "0.49.3")
 

You find the latest version on the release page.

After adding rules_rust in your MODULE.bazel, set the following to begin using crate_universe:

-
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
+
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
 //  # ... Dependencies
 use_repo(crate, "crates")
 
@@ -199,7 +199,7 @@

Cargo Works

One of the simpler ways to wire up dependencies would be to first structure your project into a Cargo workspace. The crates_repository rule can ingest a root Cargo.toml file and generate Bazel dependencies from there. You find a complete example in the in the example folder.

-
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
+
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
 
 crate.from_cargo(
     name = "crates",
@@ -215,7 +215,7 @@ 

Cargo Works Since these macros come from the generated repository, the dependencies and alias definitions they return will automatically update BUILD targets. In your BUILD files, you use these macros for a Rust library as shown below:

-
load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
+
load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
 load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
 
 rust_library(
@@ -246,7 +246,7 @@ 

Cargo Works

For a Rust binary that does not depend on any macro, use the following configuration in your build file:

-
rust_binary(
+
rust_binary(
     name = "bin",
     srcs = ["src/main.rs"],
     deps = all_crate_deps(normal = True),
@@ -271,7 +271,7 @@ 

Direc In situations like this, it may be desirable to have a “Cargo free” setup. You find an example in the in the example folder.

crates_repository supports this through the packages attribute, as shown below.

-
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
+
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
 
 crate.spec(package = "serde", features = ["derive"], version = "1.0")
 crate.spec(package = "serde_json", version = "1.0")
@@ -282,7 +282,7 @@ 

Direc

Consuming dependencies may be more ergonomic in this case through the aliases defined in the new repository. In your BUILD files, you use direct dependencies as shown below:

-
rust_binary(
+
rust_binary(
     name = "bin",
     crate_root = "src/main.rs",
     srcs = glob([
@@ -305,7 +305,7 @@ 

V or to ensure full build reproducibility since no download error could possibly occur. You find a complete example in the in the example folder.

For the setup, you need to add the skylib in addition to the rust rules to your MODUE.bazel.

-
module(
+
module(
     name = "deps_vendored",
     version = "0.0.0"
 )
@@ -346,7 +346,7 @@ 

V but by convention, its either thirdparty or 3rdparty to indicate vendored dependencies. In the 3rdparty folder, you add a target crates_vendor to declare your dependencies to vendor. In the example, we vendor a specific version of bzip2.

-
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")
+
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")
 
 crates_vendor(
     name = "crates_vendor",
@@ -388,7 +388,7 @@ 

V 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:

-
load("@rules_rust//rust:defs.bzl", "rust_binary")
+
load("@rules_rust//rust:defs.bzl", "rust_binary")
 
 rust_binary(
     name = "hello_sys",
@@ -400,7 +400,7 @@ 

V

Note, the vendored dependency is not yet accessible because you have to define first how to load the vendored dependencies. For that, you first create a file sys_deps.bzl and add the following content:

-
# rename the default name "crate_repositories" in case you import multiple vendored folders.
+
# rename the default name "crate_repositories" in case you import multiple vendored folders.
 load("//basic/3rdparty/crates:defs.bzl", basic_crate_repositories = "crate_repositories")
 
 def sys_deps():
@@ -412,7 +412,7 @@ 

V just load the vendored dependencies.

In a WORKSPACE configuration, you would just load and call sys_deps(), but in a MODULE configuration, you cannot do that. Instead, you create a new file WORKSPACE.bzlmod and add the following content.

-
load("//:sys_deps.bzl", "sys_deps")
+
load("//:sys_deps.bzl", "sys_deps")
 sys_deps()
 

Now, you can build the project as usual.

diff --git a/print.html b/print.html index 3363ba3aa5..2439d066e3 100644 --- a/print.html +++ b/print.html @@ -2751,11 +2751,11 @@

Table of

Setup

To use rules_rust in a project using bzlmod, add the following to your MODULE.bazel file:

-
bazel_dep(name = "rules_rust", version = "0.49.3")
+
bazel_dep(name = "rules_rust", version = "0.49.3")
 

You find the latest version on the release page.

After adding rules_rust in your MODULE.bazel, set the following to begin using crate_universe:

-
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
+
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
 //  # ... Dependencies
 use_repo(crate, "crates")
 
@@ -2770,7 +2770,7 @@

Cargo Works

One of the simpler ways to wire up dependencies would be to first structure your project into a Cargo workspace. The crates_repository rule can ingest a root Cargo.toml file and generate Bazel dependencies from there. You find a complete example in the in the example folder.

-
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
+
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
 
 crate.from_cargo(
     name = "crates",
@@ -2786,7 +2786,7 @@ 

Cargo Works Since these macros come from the generated repository, the dependencies and alias definitions they return will automatically update BUILD targets. In your BUILD files, you use these macros for a Rust library as shown below:

-
load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
+
load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
 load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
 
 rust_library(
@@ -2817,7 +2817,7 @@ 

Cargo Works

For a Rust binary that does not depend on any macro, use the following configuration in your build file:

-
rust_binary(
+
rust_binary(
     name = "bin",
     srcs = ["src/main.rs"],
     deps = all_crate_deps(normal = True),
@@ -2842,7 +2842,7 @@ 

Direc In situations like this, it may be desirable to have a “Cargo free” setup. You find an example in the in the example folder.

crates_repository supports this through the packages attribute, as shown below.

-
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
+
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
 
 crate.spec(package = "serde", features = ["derive"], version = "1.0")
 crate.spec(package = "serde_json", version = "1.0")
@@ -2853,7 +2853,7 @@ 

Direc

Consuming dependencies may be more ergonomic in this case through the aliases defined in the new repository. In your BUILD files, you use direct dependencies as shown below:

-
rust_binary(
+
rust_binary(
     name = "bin",
     crate_root = "src/main.rs",
     srcs = glob([
@@ -2876,7 +2876,7 @@ 

V or to ensure full build reproducibility since no download error could possibly occur. You find a complete example in the in the example folder.

For the setup, you need to add the skylib in addition to the rust rules to your MODUE.bazel.

-
module(
+
module(
     name = "deps_vendored",
     version = "0.0.0"
 )
@@ -2917,7 +2917,7 @@ 

V but by convention, its either thirdparty or 3rdparty to indicate vendored dependencies. In the 3rdparty folder, you add a target crates_vendor to declare your dependencies to vendor. In the example, we vendor a specific version of bzip2.

-
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")
+
load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")
 
 crates_vendor(
     name = "crates_vendor",
@@ -2959,7 +2959,7 @@ 

V 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:

-
load("@rules_rust//rust:defs.bzl", "rust_binary")
+
load("@rules_rust//rust:defs.bzl", "rust_binary")
 
 rust_binary(
     name = "hello_sys",
@@ -2971,7 +2971,7 @@ 

V

Note, the vendored dependency is not yet accessible because you have to define first how to load the vendored dependencies. For that, you first create a file sys_deps.bzl and add the following content:

-
# rename the default name "crate_repositories" in case you import multiple vendored folders.
+
# rename the default name "crate_repositories" in case you import multiple vendored folders.
 load("//basic/3rdparty/crates:defs.bzl", basic_crate_repositories = "crate_repositories")
 
 def sys_deps():
@@ -2983,7 +2983,7 @@ 

V just load the vendored dependencies.

In a WORKSPACE configuration, you would just load and call sys_deps(), but in a MODULE configuration, you cannot do that. Instead, you create a new file WORKSPACE.bzlmod and add the following content.

-
load("//:sys_deps.bzl", "sys_deps")
+
load("//:sys_deps.bzl", "sys_deps")
 sys_deps()
 

Now, you can build the project as usual.