Skip to content

Commit 10a3d3c

Browse files
committed
Separate abs into rust/private:compat.bzl
Since repository.bzl cannot load `private:utils.bzl` because of a cyclic dependency for rules_cc.
1 parent 9934f64 commit 10a3d3c

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

rust/private/compat.bzl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2015 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Compatibility functions for older Bazel versions."""
16+
17+
# TODO: remove after dropping support for Bazel < 7 when `abs` is a global
18+
def abs(value):
19+
"""Returns the absolute value of a number.
20+
21+
Args:
22+
value (int): A number.
23+
24+
Returns:
25+
int: The absolute value of the number.
26+
"""
27+
if value < 0:
28+
return -value
29+
return value

rust/private/rustc.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ load("//rust/private:providers.bzl", "RustcOutputDiagnosticsInfo", _BuildInfo =
2727
load("//rust/private:stamp.bzl", "is_stamping_enabled")
2828
load(
2929
"//rust/private:utils.bzl",
30-
"abs",
3130
"expand_dict_value_locations",
3231
"expand_list_element_locations",
3332
"find_cc_toolchain",
@@ -39,6 +38,7 @@ load(
3938
"make_static_lib_symlink",
4039
"relativize",
4140
)
41+
load("//rust/private:compat.bzl", "abs")
4242

4343
# This feature is disabled unless one of the dependencies is a cc_library.
4444
# Authors of C++ toolchains can place linker flags that should only be applied

rust/private/utils.bzl

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
load("@bazel_skylib//lib:paths.bzl", "paths")
1818
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", find_rules_cc_toolchain = "find_cpp_toolchain")
1919
load(":providers.bzl", "BuildInfo", "CrateGroupInfo", "CrateInfo", "DepInfo", "DepVariantInfo", "RustcOutputDiagnosticsInfo")
20+
load(":compat.bzl", "abs")
2021

2122
UNSUPPORTED_FEATURES = [
2223
"thin_lto",
@@ -175,20 +176,6 @@ def get_lib_name_for_windows(lib):
175176

176177
return libname
177178

178-
# TODO: remove after dropping support for Bazel < 7 when `abs` is a global
179-
def abs(value):
180-
"""Returns the absolute value of a number.
181-
182-
Args:
183-
value (int): A number.
184-
185-
Returns:
186-
int: The absolute value of the number.
187-
"""
188-
if value < 0:
189-
return -value
190-
return value
191-
192179
def determine_output_hash(crate_root, label):
193180
"""Generates a hash of the crate root file's path.
194181

rust/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
55
load("//rust/platform:triple.bzl", "get_host_triple", "triple")
66
load("//rust/platform:triple_mappings.bzl", "triple_to_constraint_set")
77
load("//rust/private:common.bzl", "rust_common")
8-
load("//rust/private:utils.bzl", "abs")
8+
load("//rust/private:compat.bzl", "abs")
99
load(
1010
"//rust/private:repository_utils.bzl",
1111
"BUILD_for_rust_analyzer_proc_macro_srv",

0 commit comments

Comments
 (0)