Skip to content

Commit

Permalink
crate_universe: Allow passing extra args down to crate_universe_boots…
Browse files Browse the repository at this point in the history
…trap (#2279)

this is useful for rules_nixpkgs which allows us to specify an external
rust toolchain controlled by Nix. Currently, we are required to carry a
patch to modify rules_rust:
https://github.com/tweag/rules_nixpkgs/tree/master/examples/toolchains/rust

Now we can add something like this to our WORKSPACE to use a custom
cargo and rustc:
```
crate_universe_dependencies(
    bootstrap = True,
    rust_toolchain_cargo_template = "@nix_rust//:bin/{tool}",
    rust_toolchain_rustc_template = "@nix_rust//:bin/{tool}",
)
```

---------

Co-authored-by: UebelAndre <github@uebelandre.com>
  • Loading branch information
DolceTriade and UebelAndre authored Nov 25, 2023
1 parent a09c6d9 commit b96e37e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions crate_universe/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ load("//crate_universe/3rdparty/crates:crates.bzl", _vendor_crate_repositories =
load("//crate_universe/private:vendor_utils.bzl", "crates_vendor_deps")
load("//crate_universe/tools/cross_installer:cross_installer_deps.bzl", "cross_installer_deps")

def crate_universe_dependencies(rust_version = rust_common.default_version, bootstrap = False):
def crate_universe_dependencies(rust_version = rust_common.default_version, bootstrap = False, **kwargs):
"""Define dependencies of the `cargo-bazel` Rust target
Args:
rust_version (str, optional): The version of rust to use when generating dependencies.
bootstrap (bool, optional): If true, a `cargo_bootstrap_repository` target will be generated.
**kwargs: Arguments to pass through to cargo_bazel_bootstrap.
"""
third_party_deps()

if bootstrap:
cargo_bazel_bootstrap(rust_version = rust_version)
cargo_bazel_bootstrap(rust_version = rust_version, **kwargs)

_vendor_crate_repositories()

Expand Down
3 changes: 2 additions & 1 deletion docs/crate_universe.md
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ A macro for defining repositories for all generated crates
## crate_universe_dependencies

<pre>
crate_universe_dependencies(<a href="#crate_universe_dependencies-rust_version">rust_version</a>, <a href="#crate_universe_dependencies-bootstrap">bootstrap</a>)
crate_universe_dependencies(<a href="#crate_universe_dependencies-rust_version">rust_version</a>, <a href="#crate_universe_dependencies-bootstrap">bootstrap</a>, <a href="#crate_universe_dependencies-kwargs">kwargs</a>)
</pre>

Define dependencies of the `cargo-bazel` Rust target
Expand All @@ -732,6 +732,7 @@ Define dependencies of the `cargo-bazel` Rust target
| :------------- | :------------- | :------------- |
| <a id="crate_universe_dependencies-rust_version"></a>rust_version | The version of rust to use when generating dependencies. | `"1.74.0"` |
| <a id="crate_universe_dependencies-bootstrap"></a>bootstrap | If true, a <code>cargo_bootstrap_repository</code> target will be generated. | `False` |
| <a id="crate_universe_dependencies-kwargs"></a>kwargs | Arguments to pass through to cargo_bazel_bootstrap. | none |


<a id="render_config"></a>
Expand Down

0 comments on commit b96e37e

Please sign in to comment.