Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use abs from utils instead of the global #3075

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cargo/private/cargo_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

load("//rust/platform:triple_mappings.bzl", "system_to_binary_ext")

# TODO: remove after dropping support for Bazel < 7 when `abs` is a global
illicitonion marked this conversation as resolved.
Show resolved Hide resolved
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 _resolve_repository_template(
*,
template,
Expand Down
29 changes: 29 additions & 0 deletions rust/private/compat.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2015 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Compatibility functions for older Bazel versions."""

# 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
4 changes: 2 additions & 2 deletions rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ load(
"CPP_LINK_STATIC_LIBRARY_ACTION_NAME",
)
load("//rust/private:common.bzl", "rust_common")
load("//rust/private:compat.bzl", "abs")
load("//rust/private:providers.bzl", "RustcOutputDiagnosticsInfo", _BuildInfo = "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",
"get_lib_name_default",
"get_lib_name_for_windows",
"get_preferred_artifact",
"is_exec_configuration",
"is_std_dylib",
"make_static_lib_symlink",
"relativize",
)
load(":utils.bzl", "is_std_dylib")

# 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
14 changes: 1 addition & 13 deletions rust/private/utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", find_rules_cc_toolchain = "find_cpp_toolchain")
load(":compat.bzl", "abs")
load(":providers.bzl", "BuildInfo", "CrateGroupInfo", "CrateInfo", "DepInfo", "DepVariantInfo", "RustcOutputDiagnosticsInfo")

UNSUPPORTED_FEATURES = [
Expand Down Expand Up @@ -175,19 +176,6 @@ def get_lib_name_for_windows(lib):

return libname

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
1 change: 1 addition & 0 deletions rust/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +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:compat.bzl", "abs")
load(
"//rust/private:repository_utils.bzl",
"BUILD_for_rust_analyzer_proc_macro_srv",
Expand Down
Loading