You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: crate_universe/extensions.bzl
+43-2
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,7 @@ There are some examples of using crate_universe with bzlmod in the [example fold
14
14
2. [Dependencies](#dependencies)
15
15
* [Cargo Workspace](#cargo-workspaces)
16
16
* [Direct Packages](#direct-dependencies)
17
+
* [Binary Dependencies](#binary-dependencies)
17
18
* [Vendored Dependencies](#vendored-dependencies)
18
19
3. [Crate reference](#crate)
19
20
* [from_cargo](#from_cargo)
@@ -45,7 +46,8 @@ There are three different ways to declare dependencies in your MODULE.
45
46
46
47
1) Cargo workspace
47
48
2) Direct Dependencies
48
-
3) Vendored Dependencies
49
+
3) Binary Dependencies
50
+
4) Vendored Dependencies
49
51
50
52
### Cargo Workspaces
51
53
@@ -136,7 +138,7 @@ For more details about repin, [please refer to the documentation](https://bazelb
136
138
In cases where Rust targets have heavy interactions with other Bazel targets ([Cc](https://docs.bazel.build/versions/main/be/c-cpp.html), [Proto](https://rules-proto-grpc.com/en/4.5.0/lang/rust.html),
137
139
etc.), maintaining Cargo.toml files may have diminishing returns as things like rust-analyzer
138
140
begin to be confused about missing targets or environment variables defined only in Bazel.
139
-
In situations like this, it may be desirable to have a “Cargo free” setup. You find an example in the in the [example folder](../examples/bzlmod/hello_world_no_cargo).
141
+
In situations like this, it may be desirable to have a "Cargo free" setup. You find an example in the in the [example folder](../examples/bzlmod/hello_world_no_cargo).
140
142
141
143
crates_repository supports this through the packages attribute,
142
144
as shown below.
@@ -175,6 +177,45 @@ rust_binary(
175
177
Notice, direct dependencies do not need repining.
176
178
Only a cargo workspace needs updating whenever the underlying Cargo.toml file changed.
177
179
180
+
### Binary Dependencies
181
+
182
+
With cargo you `can install` binary dependencies (bindeps) as well with `cargo install` command.
183
+
184
+
We don't have such easy facilities available in bazel besides specifying it as a dependency.
185
+
To mimic cargo's bindeps feature we use the unstable feature called [artifact-dependencies](https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies)
186
+
which integrates well with bazel concepts.
187
+
188
+
You could use the syntax specified in the above document to place it in `Cargo.toml`. For that you can consult the following [example](https://github.com/bazelbuild/rules_rust/blob/main/examples/crate_universe/MODULE.bazel#L279-L291).
189
+
190
+
This method has the following consequences:
191
+
* if you use shared dependency tree with your project these binary dependencies will interfere with yours (may conflict)
192
+
* you have to use nightly `host_tools_repo` to generate dependencies because
193
+
194
+
Alternatively you can specify this in a separate `repo` with `cargo.from_specs` syntax:
0 commit comments