From da08f5f9eea8f8bfa0371302f35c011af5767ddb Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Thu, 12 Dec 2024 10:28:00 +0100 Subject: [PATCH] Separate `abs` into `rust/private:compat.bzl` Since repository.bzl cannot load `private:utils.bzl` because of a cyclic dependency for rules_cc. --- rust/private/rustc.bzl | 2 +- rust/private/utils.bzl | 15 +-------------- rust/repositories.bzl | 2 +- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 3a5307d24a..fa0cea5142 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -27,7 +27,6 @@ load("//rust/private:providers.bzl", "RustcOutputDiagnosticsInfo", _BuildInfo = load("//rust/private:stamp.bzl", "is_stamping_enabled") load( "//rust/private:utils.bzl", - "abs", "expand_dict_value_locations", "expand_list_element_locations", "find_cc_toolchain", @@ -39,6 +38,7 @@ load( "make_static_lib_symlink", "relativize", ) +load("//rust/private:compat.bzl", "abs") # This feature is disabled unless one of the dependencies is a cc_library. # Authors of C++ toolchains can place linker flags that should only be applied diff --git a/rust/private/utils.bzl b/rust/private/utils.bzl index 94edb2ee89..84222a4ff8 100644 --- a/rust/private/utils.bzl +++ b/rust/private/utils.bzl @@ -17,6 +17,7 @@ load("@bazel_skylib//lib:paths.bzl", "paths") load("@bazel_tools//tools/cpp:toolchain_utils.bzl", find_rules_cc_toolchain = "find_cpp_toolchain") load(":providers.bzl", "BuildInfo", "CrateGroupInfo", "CrateInfo", "DepInfo", "DepVariantInfo", "RustcOutputDiagnosticsInfo") +load(":compat.bzl", "abs") UNSUPPORTED_FEATURES = [ "thin_lto", @@ -175,20 +176,6 @@ def get_lib_name_for_windows(lib): return libname -# TODO: remove after dropping support for Bazel < 7 when `abs` is a global -def abs(value): - """Returns the absolute value of a number. - - Args: - value (int): A number. - - Returns: - int: The absolute value of the number. - """ - if value < 0: - return -value - return value - def determine_output_hash(crate_root, label): """Generates a hash of the crate root file's path. diff --git a/rust/repositories.bzl b/rust/repositories.bzl index 61b006d9bb..7a9b437b56 100644 --- a/rust/repositories.bzl +++ b/rust/repositories.bzl @@ -5,7 +5,7 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") load("//rust/platform:triple.bzl", "get_host_triple", "triple") load("//rust/platform:triple_mappings.bzl", "triple_to_constraint_set") load("//rust/private:common.bzl", "rust_common") -load("//rust/private:utils.bzl", "abs") +load("//rust/private:compat.bzl", "abs") load( "//rust/private:repository_utils.bzl", "BUILD_for_rust_analyzer_proc_macro_srv",