Skip to content

Commit 2c12a85

Browse files
committed
feat(repo_utils.arch): use rctx.os.arch where available
Available in Bazel 5.1.1+, it exposes the JVM `os.arch` string as lower case. When available this allows avoiding execution of `uname`. There _could_ be a possibility of `rctx.os.arch` not aligning with `uname -m` in all cases. For the common CPU architectures, it does. If there are cases where it diverges, new aliases can be added to align.
1 parent 814beca commit 2c12a85

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

lib/private/repo_utils.bzl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ def _arch(rctx):
8282
Returns:
8383
The normalized host CPU architecture string.
8484
"""
85-
86-
# NB: in bazel 5.1.1 rctx.os.arch was added which https://github.com/bazelbuild/bazel/commit/32d1606dac2fea730abe174c41870b7ee70ae041.
87-
# Once we drop support for anything older than Bazel 5.1.1 than we can simplify
88-
# this function.
89-
if _os(rctx) == "windows":
85+
if hasattr(rctx.os, "arch"):
86+
arch = rctx.os.arch
87+
elif _os(rctx) == "windows":
9088
proc_arch = (_get_env_var(rctx, "PROCESSOR_ARCHITECTURE", "") or
9189
_get_env_var(rctx, "PROCESSOR_ARCHITEW6432", ""))
9290
if proc_arch == "ARM64":

0 commit comments

Comments
 (0)