Skip to content

Commit a44ac6e

Browse files
sardokillicitonion
andauthored
Allow setting timeout for cargo-bazel. (#3485)
This PR introduces `CARGO_BAZEL_TIMEOUT` env variable to set timeout value for `cargo-bazel` invocation. --------- Co-authored-by: Daniel Wagner-Hall <[email protected]>
1 parent c7d8b15 commit a44ac6e

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

crate_universe/extensions.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,6 +1377,7 @@ Environment Variables:
13771377
| `CARGO_BAZEL_ISOLATED` | An authoritative flag as to whether or not the `CARGO_HOME` environment variable should be isolated from the host configuration |
13781378
| `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. |
13791379
| `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. |
1380+
| `CARGO_BAZEL_TIMEOUT` | An integer value to override the default timeout setting when running the cargo-bazel binary. This value must be in seconds. |
13801381
13811382
""",
13821383
implementation = _crate_impl,

crate_universe/private/common_utils.bzl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ get_host_triple = _get_host_triple
99
CARGO_BAZEL_ISOLATED = "CARGO_BAZEL_ISOLATED"
1010
CARGO_BAZEL_REPIN = "CARGO_BAZEL_REPIN"
1111
CARGO_BAZEL_DEBUG = "CARGO_BAZEL_DEBUG"
12+
CARGO_BAZEL_TIMEOUT = "CARGO_BAZEL_TIMEOUT"
1213
REPIN = "REPIN"
1314

1415
CARGO_BAZEL_REPIN_ONLY = "CARGO_BAZEL_REPIN_ONLY"
@@ -45,10 +46,15 @@ def execute(repository_ctx, args, env = {}, allow_fail = False, quiet = True):
4546
if repository_ctx.os.environ.get(CARGO_BAZEL_DEBUG, None):
4647
quiet = False
4748

49+
exec_kwargs = dict(environment = env, quiet = quiet)
50+
51+
timeout = repository_ctx.os.environ.get(CARGO_BAZEL_TIMEOUT, None)
52+
if timeout:
53+
exec_kwargs.update(timeout = int(timeout))
54+
4855
result = repository_ctx.execute(
4956
args,
50-
environment = env,
51-
quiet = quiet,
57+
**exec_kwargs
5258
)
5359

5460
if result.return_code and not allow_fail:

crate_universe/private/crates_repository.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Environment Variables:
161161
| `CARGO_BAZEL_ISOLATED` | An authoritative flag as to whether or not the `CARGO_HOME` environment variable should be isolated from the host configuration |
162162
| `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. |
163163
| `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. |
164+
| `CARGO_BAZEL_TIMEOUT` | An integer value to override the default timeout setting when running the cargo-bazel binary. This value must be in seconds. |
164165
165166
Example:
166167

crate_universe/private/generate_utils.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ load(
44
":common_utils.bzl",
55
"CARGO_BAZEL_DEBUG",
66
"CARGO_BAZEL_ISOLATED",
7+
"CARGO_BAZEL_TIMEOUT",
78
"REPIN_ALLOWLIST_ENV_VAR",
89
"REPIN_ENV_VARS",
910
"parse_alias_rule",
@@ -21,6 +22,7 @@ CRATES_REPOSITORY_ENVIRON = GENERATOR_ENV_VARS + REPIN_ENV_VARS + [
2122
REPIN_ALLOWLIST_ENV_VAR,
2223
CARGO_BAZEL_ISOLATED,
2324
CARGO_BAZEL_DEBUG,
25+
CARGO_BAZEL_TIMEOUT,
2426
]
2527

2628
def get_generator(repository_ctx, host_triple):

0 commit comments

Comments
 (0)