From f4804b407c05f4e63bbe17e84cdd8d5a87c653b2 Mon Sep 17 00:00:00 2001 From: Matt Stark Date: Mon, 19 Jun 2023 13:50:57 +1000 Subject: [PATCH] Support cargo_bazel_bootstrap for bzlmod --- MODULE.bazel | 3 +++ crate_universe/deps_bootstrap.bzl | 4 +++- .../private/module_extensions/BUILD.bazel | 0 .../module_extensions/cargo_bazel_bootstrap.bzl | 14 ++++++++++++++ 4 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 crate_universe/private/module_extensions/BUILD.bazel create mode 100644 crate_universe/private/module_extensions/cargo_bazel_bootstrap.bzl diff --git a/MODULE.bazel b/MODULE.bazel index 7ed0c6f75e..bbb610518e 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -25,3 +25,6 @@ use_repo( rust = use_extension("//rust:extensions.bzl", "rust") rust.host_tools(edition = "2021") use_repo(rust, "rust_host_tools") + +cargo_bazel_bootstrap = use_extension("//crate_universe/private/module_extensions:cargo_bazel_bootstrap.bzl", "cargo_bazel_bootstrap") +use_repo(cargo_bazel_bootstrap, "cargo_bazel_bootstrap") diff --git a/crate_universe/deps_bootstrap.bzl b/crate_universe/deps_bootstrap.bzl index 28f6d14b0d..e4fda6de97 100644 --- a/crate_universe/deps_bootstrap.bzl +++ b/crate_universe/deps_bootstrap.bzl @@ -6,12 +6,13 @@ load("//crate_universe/private:srcs.bzl", "CARGO_BAZEL_SRCS") # buildifier: disable=bzl-visibility load("//rust/private:common.bzl", "rust_common") -def cargo_bazel_bootstrap(name = "cargo_bazel_bootstrap", rust_version = rust_common.default_version): +def cargo_bazel_bootstrap(name = "cargo_bazel_bootstrap", rust_version = rust_common.default_version, **kwargs): """An optional repository which bootstraps `cargo-bazel` for use with `crates_repository` Args: name (str, optional): The name of the `cargo_bootstrap_repository`. rust_version (str, optional): The rust version to use. Defaults to the default of `cargo_bootstrap_repository`. + **kwargs: kwargs to pass through to cargo_bootstrap_repository. """ cargo_bootstrap_repository( name = name, @@ -22,4 +23,5 @@ def cargo_bazel_bootstrap(name = "cargo_bazel_bootstrap", rust_version = rust_co version = rust_version, # The increased timeout helps avoid flakes in CI timeout = 900, + **kwargs ) diff --git a/crate_universe/private/module_extensions/BUILD.bazel b/crate_universe/private/module_extensions/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/crate_universe/private/module_extensions/cargo_bazel_bootstrap.bzl b/crate_universe/private/module_extensions/cargo_bazel_bootstrap.bzl new file mode 100644 index 0000000000..18a46eff25 --- /dev/null +++ b/crate_universe/private/module_extensions/cargo_bazel_bootstrap.bzl @@ -0,0 +1,14 @@ +"""Module extension for bootstrapping cargo-bazel.""" + +load("//crate_universe:deps_bootstrap.bzl", _cargo_bazel_bootstrap_repo_rule = "cargo_bazel_bootstrap") + +def _cargo_bazel_bootstrap_impl(_): + _cargo_bazel_bootstrap_repo_rule( + rust_toolchain_cargo_template = "@rust_host_tools//:bin/{tool}", + rust_toolchain_rustc_template = "@rust_host_tools//:bin/{tool}", + ) + +cargo_bazel_bootstrap = module_extension( + implementation = _cargo_bazel_bootstrap_impl, + doc = """Module extension to generate the cargo_bazel binary.""", +)