diff --git a/crate_universe/extensions.bzl b/crate_universe/extensions.bzl index a732426381..3327bbede6 100644 --- a/crate_universe/extensions.bzl +++ b/crate_universe/extensions.bzl @@ -1377,6 +1377,7 @@ Environment Variables: | `CARGO_BAZEL_ISOLATED` | An authoritative flag as to whether or not the `CARGO_HOME` environment variable should be isolated from the host configuration | | `CARGO_BAZEL_REPIN` | An indicator that the dependencies represented by the rule should be regenerated. `REPIN` may also be used. See [Repinning / Updating Dependencies](crate_universe_workspace.html#repinning--updating-dependencies) for more details. | | `CARGO_BAZEL_REPIN_ONLY` | A comma-delimited allowlist for rules to execute repinning. Can be useful if multiple instances of the repository rule are used in a Bazel workspace, but repinning should be limited to one of them. | +| `CARGO_BAZEL_TIMEOUT` | An integer value to override the default timeout setting when running the cargo-bazel binary. This value must be in seconds. | """, implementation = _crate_impl, diff --git a/crate_universe/private/common_utils.bzl b/crate_universe/private/common_utils.bzl index 816deddcff..4c4af014d6 100644 --- a/crate_universe/private/common_utils.bzl +++ b/crate_universe/private/common_utils.bzl @@ -9,6 +9,7 @@ get_host_triple = _get_host_triple CARGO_BAZEL_ISOLATED = "CARGO_BAZEL_ISOLATED" CARGO_BAZEL_REPIN = "CARGO_BAZEL_REPIN" CARGO_BAZEL_DEBUG = "CARGO_BAZEL_DEBUG" +CARGO_BAZEL_TIMEOUT = "CARGO_BAZEL_TIMEOUT" REPIN = "REPIN" CARGO_BAZEL_REPIN_ONLY = "CARGO_BAZEL_REPIN_ONLY" @@ -45,10 +46,15 @@ def execute(repository_ctx, args, env = {}, allow_fail = False, quiet = True): if repository_ctx.os.environ.get(CARGO_BAZEL_DEBUG, None): quiet = False + exec_kwargs = dict(environment = env, quiet = quiet) + + timeout = repository_ctx.os.environ.get(CARGO_BAZEL_TIMEOUT, None) + if timeout: + exec_kwargs.update(timeout = int(timeout)) + result = repository_ctx.execute( args, - environment = env, - quiet = quiet, + **exec_kwargs ) if result.return_code and not allow_fail: diff --git a/crate_universe/private/crates_repository.bzl b/crate_universe/private/crates_repository.bzl index 58d887cf43..64d6e3802e 100644 --- a/crate_universe/private/crates_repository.bzl +++ b/crate_universe/private/crates_repository.bzl @@ -161,6 +161,7 @@ Environment Variables: | `CARGO_BAZEL_ISOLATED` | An authoritative flag as to whether or not the `CARGO_HOME` environment variable should be isolated from the host configuration | | `CARGO_BAZEL_REPIN` | An indicator that the dependencies represented by the rule should be regenerated. `REPIN` may also be used. See [Repinning / Updating Dependencies](#repinning--updating-dependencies) for more details. | | `CARGO_BAZEL_REPIN_ONLY` | A comma-delimited allowlist for rules to execute repinning. Can be useful if multiple instances of the repository rule are used in a Bazel workspace, but repinning should be limited to one of them. | +| `CARGO_BAZEL_TIMEOUT` | An integer value to override the default timeout setting when running the cargo-bazel binary. This value must be in seconds. | Example: diff --git a/crate_universe/private/generate_utils.bzl b/crate_universe/private/generate_utils.bzl index 15b94fa512..e69014e78b 100644 --- a/crate_universe/private/generate_utils.bzl +++ b/crate_universe/private/generate_utils.bzl @@ -4,6 +4,7 @@ load( ":common_utils.bzl", "CARGO_BAZEL_DEBUG", "CARGO_BAZEL_ISOLATED", + "CARGO_BAZEL_TIMEOUT", "REPIN_ALLOWLIST_ENV_VAR", "REPIN_ENV_VARS", "parse_alias_rule", @@ -21,6 +22,7 @@ CRATES_REPOSITORY_ENVIRON = GENERATOR_ENV_VARS + REPIN_ENV_VARS + [ REPIN_ALLOWLIST_ENV_VAR, CARGO_BAZEL_ISOLATED, CARGO_BAZEL_DEBUG, + CARGO_BAZEL_TIMEOUT, ] def get_generator(repository_ctx, host_triple):