Skip to content

Commit

Permalink
Deploying to gh-pages from @ 5e426fa 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
github-merge-queue[bot] committed Jan 10, 2025
1 parent bfd8a96 commit f7677f8
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
33 changes: 32 additions & 1 deletion crate_universe_bzlmod.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ <h1 id="table-of-contents"><a class="header" href="#table-of-contents">Table of
<ul>
<li><a href="#cargo-workspaces">Cargo Workspace</a></li>
<li><a href="#direct-dependencies">Direct Packages</a></li>
<li><a href="#binary-dependencies">Binary Dependencies</a></li>
<li><a href="#vendored-dependencies">Vendored Dependencies</a></li>
</ul>
</li>
Expand All @@ -193,6 +194,7 @@ <h2 id="dependencies"><a class="header" href="#dependencies">Dependencies</a></h
<ol>
<li>Cargo workspace</li>
<li>Direct Dependencies</li>
<li>Binary Dependencies</li>
<li>Vendored Dependencies</li>
</ol>
<h3 id="cargo-workspaces"><a class="header" href="#cargo-workspaces">Cargo Workspaces</a></h3>
Expand Down Expand Up @@ -268,7 +270,7 @@ <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direc
<p>In cases where Rust targets have heavy interactions with other Bazel targets (<a href="https://docs.bazel.build/versions/main/be/c-cpp.html">Cc</a>, <a href="https://rules-proto-grpc.com/en/4.5.0/lang/rust.html">Proto</a>,
etc.), maintaining Cargo.toml files may have diminishing returns as things like rust-analyzer
begin to be confused about missing targets or environment variables defined only in Bazel.
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>
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-python">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
Expand Down Expand Up @@ -299,6 +301,35 @@ <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direc
</code></pre>
<p>Notice, direct dependencies do not need repining.
Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.</p>
<h3 id="binary-dependencies"><a class="header" href="#binary-dependencies">Binary Dependencies</a></h3>
<p>With cargo you <code>can install</code> binary dependencies (bindeps) as well with <code>cargo install</code> command.</p>
<p>We don't have such easy facilities available in bazel besides specifying it as a dependency.
To mimic cargo's bindeps feature we use the unstable feature called <a href="https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies">artifact-dependencies</a>
which integrates well with bazel concepts.</p>
<p>You could use the syntax specified in the above document to place it in <code>Cargo.toml</code>. For that you can consult the following <a href="https://github.com/bazelbuild/rules_rust/blob/main/examples/crate_universe/MODULE.bazel#L279-L291">example</a>.</p>
<p>This method has the following consequences:</p>
<ul>
<li>if you use shared dependency tree with your project these binary dependencies will interfere with yours (may conflict)</li>
<li>you have to use nightly <code>host_tools_repo</code> to generate dependencies because</li>
</ul>
<p>Alternatively you can specify this in a separate <code>repo</code> with <code>cargo.from_specs</code> syntax:</p>
<pre><code class="language-python">bindeps = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")

bindeps.spec(package = "cargo-machete", version = "=0.7.0", artifact = "bin")
bindeps.annotation(crate = "cargo-machete", gen_all_binaries = True)

bindeps.from_specs(
name = "bindeps",
host_tools_repo = "rust_host_tools_nightly",
)

use_repo(bindeps, "bindeps")
</code></pre>
<p>You can run the specified binary dependency with the following command or create additional more complex rules on top of it.</p>
<pre><code class="language-bash">bazel run @bindeps//:cargo-machete__cargo-machete
</code></pre>
<p>Notice, direct dependencies do not need repining.
Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.</p>
<h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">Vendored Dependencies</a></h3>
<p>In some cases, it is require that all external dependencies are vendored, meaning downloaded
and stored in the workspace. This helps, for example, to conduct licence scans, apply custom patches,
Expand Down
35 changes: 33 additions & 2 deletions print.html
Original file line number Diff line number Diff line change
Expand Up @@ -1940,6 +1940,7 @@ <h1 id="table-of-contents"><a class="header" href="#table-of-contents">Table of
<ul>
<li><a href="crate_universe_bzlmod.html#cargo-workspaces">Cargo Workspace</a></li>
<li><a href="crate_universe_bzlmod.html#direct-dependencies">Direct Packages</a></li>
<li><a href="crate_universe_bzlmod.html#binary-dependencies">Binary Dependencies</a></li>
<li><a href="crate_universe_bzlmod.html#vendored-dependencies">Vendored Dependencies</a></li>
</ul>
</li>
Expand All @@ -1965,6 +1966,7 @@ <h2 id="dependencies"><a class="header" href="#dependencies">Dependencies</a></h
<ol>
<li>Cargo workspace</li>
<li>Direct Dependencies</li>
<li>Binary Dependencies</li>
<li>Vendored Dependencies</li>
</ol>
<h3 id="cargo-workspaces"><a class="header" href="#cargo-workspaces">Cargo Workspaces</a></h3>
Expand Down Expand Up @@ -2040,7 +2042,7 @@ <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direc
<p>In cases where Rust targets have heavy interactions with other Bazel targets (<a href="https://docs.bazel.build/versions/main/be/c-cpp.html">Cc</a>, <a href="https://rules-proto-grpc.com/en/4.5.0/lang/rust.html">Proto</a>,
etc.), maintaining Cargo.toml files may have diminishing returns as things like rust-analyzer
begin to be confused about missing targets or environment variables defined only in Bazel.
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>
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-python">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
Expand Down Expand Up @@ -2071,6 +2073,35 @@ <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direc
</code></pre>
<p>Notice, direct dependencies do not need repining.
Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.</p>
<h3 id="binary-dependencies"><a class="header" href="#binary-dependencies">Binary Dependencies</a></h3>
<p>With cargo you <code>can install</code> binary dependencies (bindeps) as well with <code>cargo install</code> command.</p>
<p>We don't have such easy facilities available in bazel besides specifying it as a dependency.
To mimic cargo's bindeps feature we use the unstable feature called <a href="https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies">artifact-dependencies</a>
which integrates well with bazel concepts.</p>
<p>You could use the syntax specified in the above document to place it in <code>Cargo.toml</code>. For that you can consult the following <a href="https://github.com/bazelbuild/rules_rust/blob/main/examples/crate_universe/MODULE.bazel#L279-L291">example</a>.</p>
<p>This method has the following consequences:</p>
<ul>
<li>if you use shared dependency tree with your project these binary dependencies will interfere with yours (may conflict)</li>
<li>you have to use nightly <code>host_tools_repo</code> to generate dependencies because</li>
</ul>
<p>Alternatively you can specify this in a separate <code>repo</code> with <code>cargo.from_specs</code> syntax:</p>
<pre><code class="language-python">bindeps = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")

bindeps.spec(package = "cargo-machete", version = "=0.7.0", artifact = "bin")
bindeps.annotation(crate = "cargo-machete", gen_all_binaries = True)

bindeps.from_specs(
name = "bindeps",
host_tools_repo = "rust_host_tools_nightly",
)

use_repo(bindeps, "bindeps")
</code></pre>
<p>You can run the specified binary dependency with the following command or create additional more complex rules on top of it.</p>
<pre><code class="language-bash">bazel run @bindeps//:cargo-machete__cargo-machete
</code></pre>
<p>Notice, direct dependencies do not need repining.
Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.</p>
<h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">Vendored Dependencies</a></h3>
<p>In some cases, it is require that all external dependencies are vendored, meaning downloaded
and stored in the workspace. This helps, for example, to conduct licence scans, apply custom patches,
Expand Down Expand Up @@ -2499,7 +2530,7 @@ <h3 id="direct-packages"><a class="header" href="#direct-packages">Direct Packag
],
)
</code></pre>
<h3 id="binary-dependencies"><a class="header" href="#binary-dependencies">Binary dependencies</a></h3>
<h3 id="binary-dependencies-1"><a class="header" href="#binary-dependencies-1">Binary dependencies</a></h3>
<p>Neither of the above approaches supports depending on binary-only packages.</p>
<p>In order to depend on a Cargo package that contains binaries and no library, you
will need to do one of the following:</p>
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion searchindex.json

Large diffs are not rendered by default.

0 comments on commit f7677f8

Please sign in to comment.