Skip to content

Commit

Permalink
Deploying to gh-pages from @ ba49599 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
github-merge-queue[bot] committed Dec 13, 2024
1 parent ee84f38 commit 417b389
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
24 changes: 12 additions & 12 deletions crate_universe_bzlmod.html
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ <h1 id="table-of-contents"><a class="header" href="#table-of-contents">Table of
</ol>
<h2 id="setup"><a class="header" href="#setup">Setup</a></h2>
<p>To use rules_rust in a project using bzlmod, add the following to your MODULE.bazel file:</p>
<pre><code class="language-starlark">bazel_dep(name = "rules_rust", version = "0.49.3")
<pre><code class="language-python">bazel_dep(name = "rules_rust", version = "0.49.3")
</code></pre>
<p>You find the latest version on the <a href="https://github.com/bazelbuild/rules_rust/releases">release page</a>.</p>
<p>After adding <code>rules_rust</code> in your MODULE.bazel, set the following to begin using <code>crate_universe</code>:</p>
<pre><code class="language-starlark">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
<pre><code class="language-python">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
// # ... Dependencies
use_repo(crate, "crates")
</code></pre>
Expand All @@ -199,7 +199,7 @@ <h3 id="cargo-workspaces"><a class="header" href="#cargo-workspaces">Cargo Works
<p>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 <a href="../examples/bzlmod/all_crate_deps">example folder</a>.</p>
<pre><code class="language-starlark">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
<pre><code class="language-python">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")

crate.from_cargo(
name = "crates",
Expand All @@ -215,7 +215,7 @@ <h3 id="cargo-workspaces"><a class="header" href="#cargo-workspaces">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:</p>
<pre><code class="language-starlark">load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
<pre><code class="language-python">load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")

rust_library(
Expand Down Expand Up @@ -246,7 +246,7 @@ <h3 id="cargo-workspaces"><a class="header" href="#cargo-workspaces">Cargo Works
</code></pre>
<p>For a Rust binary that does not depend on any macro, use the following configuration
in your build file:</p>
<pre><code class="language-starlark">rust_binary(
<pre><code class="language-python">rust_binary(
name = "bin",
srcs = ["src/main.rs"],
deps = all_crate_deps(normal = True),
Expand All @@ -271,7 +271,7 @@ <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direc
In situations like this, it may be desirable to have a “Cargo free” setup. You find an example in the in the <a href="../examples/bzlmod/hello_world_no_cargo">example folder</a>.</p>
<p>crates_repository supports this through the packages attribute,
as shown below.</p>
<pre><code class="language-starlark">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
<pre><code class="language-python">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")
Expand All @@ -282,7 +282,7 @@ <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direc
</code></pre>
<p>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:</p>
<pre><code class="language-starlark">rust_binary(
<pre><code class="language-python">rust_binary(
name = "bin",
crate_root = "src/main.rs",
srcs = glob([
Expand All @@ -305,7 +305,7 @@ <h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">V
or to ensure full build reproducibility since no download error could possibly occur.
You find a complete example in the in the <a href="../examples/bzlmod/all_deps_vendor">example folder</a>.</p>
<p>For the setup, you need to add the skylib in addition to the rust rules to your MODUE.bazel.</p>
<pre><code class="language-starlark">module(
<pre><code class="language-python">module(
name = "deps_vendored",
version = "0.0.0"
)
Expand Down Expand Up @@ -346,7 +346,7 @@ <h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">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.</p>
<pre><code class="language-starlark">load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")
<pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")

crates_vendor(
name = "crates_vendor",
Expand Down Expand Up @@ -388,7 +388,7 @@ <h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">V
that depends on a vendored dependency. You find a list of all available vendored dependencies
in the BUILD file of the generated folder: <code>basic/3rdparty/crates/BUILD.bazel</code>
You declare a vendored dependency in you target as following:</p>
<pre><code class="language-starlark">load("@rules_rust//rust:defs.bzl", "rust_binary")
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_binary")

rust_binary(
name = "hello_sys",
Expand All @@ -400,7 +400,7 @@ <h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">V
<p>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 <code>sys_deps.bzl</code>
and add the following content:</p>
<pre><code class="language-starlark"># rename the default name "crate_repositories" in case you import multiple vendored folders.
<pre><code class="language-python"># 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():
Expand All @@ -412,7 +412,7 @@ <h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">V
just load the vendored dependencies.</p>
<p>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 <code>WORKSPACE.bzlmod</code> and add the following content.</p>
<pre><code class="language-starlark">load("//:sys_deps.bzl", "sys_deps")
<pre><code class="language-python">load("//:sys_deps.bzl", "sys_deps")
sys_deps()
</code></pre>
<p>Now, you can build the project as usual.</p>
Expand Down
24 changes: 12 additions & 12 deletions print.html
Original file line number Diff line number Diff line change
Expand Up @@ -2751,11 +2751,11 @@ <h1 id="table-of-contents"><a class="header" href="#table-of-contents">Table of
</ol>
<h2 id="setup-4"><a class="header" href="#setup-4">Setup</a></h2>
<p>To use rules_rust in a project using bzlmod, add the following to your MODULE.bazel file:</p>
<pre><code class="language-starlark">bazel_dep(name = "rules_rust", version = "0.49.3")
<pre><code class="language-python">bazel_dep(name = "rules_rust", version = "0.49.3")
</code></pre>
<p>You find the latest version on the <a href="https://github.com/bazelbuild/rules_rust/releases">release page</a>.</p>
<p>After adding <code>rules_rust</code> in your MODULE.bazel, set the following to begin using <code>crate_universe</code>:</p>
<pre><code class="language-starlark">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
<pre><code class="language-python">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
// # ... Dependencies
use_repo(crate, "crates")
</code></pre>
Expand All @@ -2770,7 +2770,7 @@ <h3 id="cargo-workspaces"><a class="header" href="#cargo-workspaces">Cargo Works
<p>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 <a href="../examples/bzlmod/all_crate_deps">example folder</a>.</p>
<pre><code class="language-starlark">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
<pre><code class="language-python">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")

crate.from_cargo(
name = "crates",
Expand All @@ -2786,7 +2786,7 @@ <h3 id="cargo-workspaces"><a class="header" href="#cargo-workspaces">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:</p>
<pre><code class="language-starlark">load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
<pre><code class="language-python">load("@crate_index//:defs.bzl", "aliases", "all_crate_deps")
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")

rust_library(
Expand Down Expand Up @@ -2817,7 +2817,7 @@ <h3 id="cargo-workspaces"><a class="header" href="#cargo-workspaces">Cargo Works
</code></pre>
<p>For a Rust binary that does not depend on any macro, use the following configuration
in your build file:</p>
<pre><code class="language-starlark">rust_binary(
<pre><code class="language-python">rust_binary(
name = "bin",
srcs = ["src/main.rs"],
deps = all_crate_deps(normal = True),
Expand All @@ -2842,7 +2842,7 @@ <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direc
In situations like this, it may be desirable to have a “Cargo free” setup. You find an example in the in the <a href="../examples/bzlmod/hello_world_no_cargo">example folder</a>.</p>
<p>crates_repository supports this through the packages attribute,
as shown below.</p>
<pre><code class="language-starlark">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
<pre><code class="language-python">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")
Expand All @@ -2853,7 +2853,7 @@ <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direc
</code></pre>
<p>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:</p>
<pre><code class="language-starlark">rust_binary(
<pre><code class="language-python">rust_binary(
name = "bin",
crate_root = "src/main.rs",
srcs = glob([
Expand All @@ -2876,7 +2876,7 @@ <h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">V
or to ensure full build reproducibility since no download error could possibly occur.
You find a complete example in the in the <a href="../examples/bzlmod/all_deps_vendor">example folder</a>.</p>
<p>For the setup, you need to add the skylib in addition to the rust rules to your MODUE.bazel.</p>
<pre><code class="language-starlark">module(
<pre><code class="language-python">module(
name = "deps_vendored",
version = "0.0.0"
)
Expand Down Expand Up @@ -2917,7 +2917,7 @@ <h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">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.</p>
<pre><code class="language-starlark">load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")
<pre><code class="language-python">load("@rules_rust//crate_universe:defs.bzl", "crate", "crates_vendor")

crates_vendor(
name = "crates_vendor",
Expand Down Expand Up @@ -2959,7 +2959,7 @@ <h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">V
that depends on a vendored dependency. You find a list of all available vendored dependencies
in the BUILD file of the generated folder: <code>basic/3rdparty/crates/BUILD.bazel</code>
You declare a vendored dependency in you target as following:</p>
<pre><code class="language-starlark">load("@rules_rust//rust:defs.bzl", "rust_binary")
<pre><code class="language-python">load("@rules_rust//rust:defs.bzl", "rust_binary")

rust_binary(
name = "hello_sys",
Expand All @@ -2971,7 +2971,7 @@ <h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">V
<p>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 <code>sys_deps.bzl</code>
and add the following content:</p>
<pre><code class="language-starlark"># rename the default name "crate_repositories" in case you import multiple vendored folders.
<pre><code class="language-python"># 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():
Expand All @@ -2983,7 +2983,7 @@ <h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">V
just load the vendored dependencies.</p>
<p>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 <code>WORKSPACE.bzlmod</code> and add the following content.</p>
<pre><code class="language-starlark">load("//:sys_deps.bzl", "sys_deps")
<pre><code class="language-python">load("//:sys_deps.bzl", "sys_deps")
sys_deps()
</code></pre>
<p>Now, you can build the project as usual.</p>
Expand Down

0 comments on commit 417b389

Please sign in to comment.