Skip to content

Commit

Permalink
Separate abs into rust/private:compat.bzl
Browse files Browse the repository at this point in the history
Since repository.bzl cannot load `private:utils.bzl` because of a cyclic dependency for rules_cc.
  • Loading branch information
avdv committed Dec 12, 2024
1 parent 9934f64 commit da08f5f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 16 deletions.
2 changes: 1 addition & 1 deletion rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down
15 changes: 1 addition & 14 deletions rust/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion rust/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit da08f5f

Please sign in to comment.