From 89e82966eb76d6c59da1d891ef4f30c2d44ba87c Mon Sep 17 00:00:00 2001 From: Sinan Nalkaya Date: Fri, 27 Jun 2025 15:13:14 +0200 Subject: [PATCH 1/2] Allow setting timeout for cargo-bazel. --- crate_universe/private/common_utils.bzl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crate_universe/private/common_utils.bzl b/crate_universe/private/common_utils.bzl index 816deddcff..5beb9b626f 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: From ac55af4e8d4dd52348b06255dcf2de8bef5fe266 Mon Sep 17 00:00:00 2001 From: Sinan Nalkaya Date: Mon, 28 Jul 2025 15:41:25 +0200 Subject: [PATCH 2/2] Add CARGO_BAZEL_TIMEOUT to CRATES_REPOSITORY_ENVIRON list. --- crate_universe/extensions.bzl | 1 + crate_universe/private/crates_repository.bzl | 1 + crate_universe/private/generate_utils.bzl | 2 ++ 3 files changed, 4 insertions(+) diff --git a/crate_universe/extensions.bzl b/crate_universe/extensions.bzl index 37fa4d1993..34dec44c3a 100644 --- a/crate_universe/extensions.bzl +++ b/crate_universe/extensions.bzl @@ -1362,6 +1362,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. | """, implementation = _crate_impl, diff --git a/crate_universe/private/crates_repository.bzl b/crate_universe/private/crates_repository.bzl index 394f45927c..732ee92f4b 100644 --- a/crate_universe/private/crates_repository.bzl +++ b/crate_universe/private/crates_repository.bzl @@ -159,6 +159,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 54517fb0d1..3ae0d0db86 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):