Skip to content

Commit f7677f8

Browse files
Deploying to gh-pages from @ 5e426fa 🚀
1 parent bfd8a96 commit f7677f8

File tree

4 files changed

+67
-5
lines changed

4 files changed

+67
-5
lines changed

crate_universe_bzlmod.html

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ <h1 id="table-of-contents"><a class="header" href="#table-of-contents">Table of
168168
<ul>
169169
<li><a href="#cargo-workspaces">Cargo Workspace</a></li>
170170
<li><a href="#direct-dependencies">Direct Packages</a></li>
171+
<li><a href="#binary-dependencies">Binary Dependencies</a></li>
171172
<li><a href="#vendored-dependencies">Vendored Dependencies</a></li>
172173
</ul>
173174
</li>
@@ -193,6 +194,7 @@ <h2 id="dependencies"><a class="header" href="#dependencies">Dependencies</a></h
193194
<ol>
194195
<li>Cargo workspace</li>
195196
<li>Direct Dependencies</li>
197+
<li>Binary Dependencies</li>
196198
<li>Vendored Dependencies</li>
197199
</ol>
198200
<h3 id="cargo-workspaces"><a class="header" href="#cargo-workspaces">Cargo Workspaces</a></h3>
@@ -268,7 +270,7 @@ <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direc
268270
<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>,
269271
etc.), maintaining Cargo.toml files may have diminishing returns as things like rust-analyzer
270272
begin to be confused about missing targets or environment variables defined only in Bazel.
271-
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>
273+
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>
272274
<p>crates_repository supports this through the packages attribute,
273275
as shown below.</p>
274276
<pre><code class="language-python">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
@@ -299,6 +301,35 @@ <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direc
299301
</code></pre>
300302
<p>Notice, direct dependencies do not need repining.
301303
Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.</p>
304+
<h3 id="binary-dependencies"><a class="header" href="#binary-dependencies">Binary Dependencies</a></h3>
305+
<p>With cargo you <code>can install</code> binary dependencies (bindeps) as well with <code>cargo install</code> command.</p>
306+
<p>We don't have such easy facilities available in bazel besides specifying it as a dependency.
307+
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>
308+
which integrates well with bazel concepts.</p>
309+
<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>
310+
<p>This method has the following consequences:</p>
311+
<ul>
312+
<li>if you use shared dependency tree with your project these binary dependencies will interfere with yours (may conflict)</li>
313+
<li>you have to use nightly <code>host_tools_repo</code> to generate dependencies because</li>
314+
</ul>
315+
<p>Alternatively you can specify this in a separate <code>repo</code> with <code>cargo.from_specs</code> syntax:</p>
316+
<pre><code class="language-python">bindeps = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
317+
318+
bindeps.spec(package = "cargo-machete", version = "=0.7.0", artifact = "bin")
319+
bindeps.annotation(crate = "cargo-machete", gen_all_binaries = True)
320+
321+
bindeps.from_specs(
322+
name = "bindeps",
323+
host_tools_repo = "rust_host_tools_nightly",
324+
)
325+
326+
use_repo(bindeps, "bindeps")
327+
</code></pre>
328+
<p>You can run the specified binary dependency with the following command or create additional more complex rules on top of it.</p>
329+
<pre><code class="language-bash">bazel run @bindeps//:cargo-machete__cargo-machete
330+
</code></pre>
331+
<p>Notice, direct dependencies do not need repining.
332+
Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.</p>
302333
<h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">Vendored Dependencies</a></h3>
303334
<p>In some cases, it is require that all external dependencies are vendored, meaning downloaded
304335
and stored in the workspace. This helps, for example, to conduct licence scans, apply custom patches,

print.html

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,6 +1940,7 @@ <h1 id="table-of-contents"><a class="header" href="#table-of-contents">Table of
19401940
<ul>
19411941
<li><a href="crate_universe_bzlmod.html#cargo-workspaces">Cargo Workspace</a></li>
19421942
<li><a href="crate_universe_bzlmod.html#direct-dependencies">Direct Packages</a></li>
1943+
<li><a href="crate_universe_bzlmod.html#binary-dependencies">Binary Dependencies</a></li>
19431944
<li><a href="crate_universe_bzlmod.html#vendored-dependencies">Vendored Dependencies</a></li>
19441945
</ul>
19451946
</li>
@@ -1965,6 +1966,7 @@ <h2 id="dependencies"><a class="header" href="#dependencies">Dependencies</a></h
19651966
<ol>
19661967
<li>Cargo workspace</li>
19671968
<li>Direct Dependencies</li>
1969+
<li>Binary Dependencies</li>
19681970
<li>Vendored Dependencies</li>
19691971
</ol>
19701972
<h3 id="cargo-workspaces"><a class="header" href="#cargo-workspaces">Cargo Workspaces</a></h3>
@@ -2040,7 +2042,7 @@ <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direc
20402042
<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>,
20412043
etc.), maintaining Cargo.toml files may have diminishing returns as things like rust-analyzer
20422044
begin to be confused about missing targets or environment variables defined only in Bazel.
2043-
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>
2045+
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>
20442046
<p>crates_repository supports this through the packages attribute,
20452047
as shown below.</p>
20462048
<pre><code class="language-python">crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
@@ -2071,6 +2073,35 @@ <h3 id="direct-dependencies"><a class="header" href="#direct-dependencies">Direc
20712073
</code></pre>
20722074
<p>Notice, direct dependencies do not need repining.
20732075
Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.</p>
2076+
<h3 id="binary-dependencies"><a class="header" href="#binary-dependencies">Binary Dependencies</a></h3>
2077+
<p>With cargo you <code>can install</code> binary dependencies (bindeps) as well with <code>cargo install</code> command.</p>
2078+
<p>We don't have such easy facilities available in bazel besides specifying it as a dependency.
2079+
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>
2080+
which integrates well with bazel concepts.</p>
2081+
<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>
2082+
<p>This method has the following consequences:</p>
2083+
<ul>
2084+
<li>if you use shared dependency tree with your project these binary dependencies will interfere with yours (may conflict)</li>
2085+
<li>you have to use nightly <code>host_tools_repo</code> to generate dependencies because</li>
2086+
</ul>
2087+
<p>Alternatively you can specify this in a separate <code>repo</code> with <code>cargo.from_specs</code> syntax:</p>
2088+
<pre><code class="language-python">bindeps = use_extension("@rules_rust//crate_universe:extension.bzl", "crate")
2089+
2090+
bindeps.spec(package = "cargo-machete", version = "=0.7.0", artifact = "bin")
2091+
bindeps.annotation(crate = "cargo-machete", gen_all_binaries = True)
2092+
2093+
bindeps.from_specs(
2094+
name = "bindeps",
2095+
host_tools_repo = "rust_host_tools_nightly",
2096+
)
2097+
2098+
use_repo(bindeps, "bindeps")
2099+
</code></pre>
2100+
<p>You can run the specified binary dependency with the following command or create additional more complex rules on top of it.</p>
2101+
<pre><code class="language-bash">bazel run @bindeps//:cargo-machete__cargo-machete
2102+
</code></pre>
2103+
<p>Notice, direct dependencies do not need repining.
2104+
Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.</p>
20742105
<h3 id="vendored-dependencies"><a class="header" href="#vendored-dependencies">Vendored Dependencies</a></h3>
20752106
<p>In some cases, it is require that all external dependencies are vendored, meaning downloaded
20762107
and stored in the workspace. This helps, for example, to conduct licence scans, apply custom patches,
@@ -2499,7 +2530,7 @@ <h3 id="direct-packages"><a class="header" href="#direct-packages">Direct Packag
24992530
],
25002531
)
25012532
</code></pre>
2502-
<h3 id="binary-dependencies"><a class="header" href="#binary-dependencies">Binary dependencies</a></h3>
2533+
<h3 id="binary-dependencies-1"><a class="header" href="#binary-dependencies-1">Binary dependencies</a></h3>
25032534
<p>Neither of the above approaches supports depending on binary-only packages.</p>
25042535
<p>In order to depend on a Cargo package that contains binaries and no library, you
25052536
will need to do one of the following:</p>

searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

searchindex.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)