# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
# LLVM libc project.
-load(":libc_build_rules.bzl", "libc_function", "libc_math_function")
+load(":libc_build_rules.bzl", "libc_function", "libc_math_function",
+ "libc_support_library")
load(":platforms.bzl", "PLATFORM_CPU_ARM64", "PLATFORM_CPU_X86_64")
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
############################## Support libraries #############################
-cc_library(
+libc_support_library(
name = "__support_common",
hdrs = [
"src/__support/architectures.h",
],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_array",
hdrs = ["src/__support/CPP/array.h"],
deps = [":libc_root"],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_bit",
hdrs = ["src/__support/CPP/bit.h"],
deps = [":libc_root"],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_bitset",
hdrs = ["src/__support/CPP/bitset.h"],
deps = [":libc_root"],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_cstddef",
hdrs = ["src/__support/CPP/cstddef.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_functional",
hdrs = ["src/__support/CPP/functional.h"],
deps = [":libc_root"],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_limits",
hdrs = ["src/__support/CPP/limits.h"],
deps = [":libc_root"],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_optional",
hdrs = ["src/__support/CPP/optional.h"],
deps = [":libc_root"],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_span",
hdrs = ["src/__support/CPP/span.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_string_view",
hdrs = ["src/__support/CPP/string_view.h"],
deps = [":libc_root"],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_type_traits",
hdrs = ["src/__support/CPP/type_traits.h"],
deps = [":libc_root"],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_utility",
hdrs = ["src/__support/CPP/utility.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_vector",
hdrs = ["src/__support/CPP/vector.h"],
deps = [":libc_root"],
)
-cc_library(
+libc_support_library(
name = "__support_cpp_atomic",
hdrs = ["src/__support/CPP/atomic.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_number_pair",
hdrs = ["src/__support/number_pair.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_integer_utils",
hdrs = ["src/__support/integer_utils.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_uint",
hdrs = ["src/__support/UInt.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_uint128",
hdrs = ["src/__support/UInt128.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_str_to_num_result",
hdrs = ["src/__support/str_to_num_result.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_integer_operations",
hdrs = ["src/__support/integer_operations.h"],
deps = [":__support_cpp_type_traits"],
)
-cc_library(
+libc_support_library(
name = "__support_ctype_utils",
hdrs = ["src/__support/ctype_utils.h"],
)
-cc_library(
+libc_support_library(
name = "__support_str_to_integer",
hdrs = ["src/__support/str_to_integer.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_basic_operations",
hdrs = ["src/__support/FPUtil/BasicOperations.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_named_pair",
hdrs = ["src/__support/named_pair.h"],
deps = [":libc_root"],
)
-cc_library(
+libc_support_library(
name = "__support_builtin_wrappers",
hdrs = ["src/__support/builtin_wrappers.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_division_and_remainder_operations",
hdrs = ["src/__support/FPUtil/DivisionAndRemainderOperations.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_except_value_utils",
hdrs = ["src/__support/FPUtil/except_value_utils.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_fenv_impl",
hdrs = ["src/__support/FPUtil/FEnvImpl.h"],
textual_hdrs = [
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_float_properties",
hdrs = ["src/__support/FPUtil/FloatProperties.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_fp_bits",
hdrs = ["src/__support/FPUtil/FPBits.h"],
textual_hdrs = ["src/__support/FPUtil/x86_64/LongDoubleBits.h"],
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_hypot",
hdrs = ["src/__support/FPUtil/Hypot.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_manipulation_functions",
hdrs = ["src/__support/FPUtil/ManipulationFunctions.h"],
textual_hdrs = ["src/__support/FPUtil/x86_64/NextAfterLongDouble.h"],
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_nearest_integer_operations",
hdrs = ["src/__support/FPUtil/NearestIntegerOperations.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_normal_float",
hdrs = ["src/__support/FPUtil/NormalFloat.h"],
deps = [
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_platform_defs",
hdrs = ["src/__support/FPUtil/PlatformDefs.h"],
deps = [
],
})
-cc_library(
+libc_support_library(
name = "__support_fputil_sqrt",
hdrs = sqrt_hdrs,
deps = [
"src/__support/FPUtil/aarch64/FMA.h",
]
-cc_library(
+libc_support_library(
name = "__support_fputil_fma",
hdrs = fma_common_hdrs,
# These are conditionally included and will #error out if the platform
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_multiply_add",
hdrs = [
"src/__support/FPUtil/multiply_add.h",
],
)
-cc_library(
+libc_support_library(
name = "__support_fputil_polyeval",
hdrs = [
"src/__support/FPUtil/PolyEval.h",
"src/__support/FPUtil/aarch64/nearest_integer.h",
]
-cc_library(
+libc_support_library(
name = "__support_fputil_nearest_integer",
hdrs = nearest_integer_common_hdrs,
# These are conditionally included and will #error out if the platform
],
)
-cc_library(
+libc_support_library(
name = "__support_osutil",
hdrs = ["src/__support/OSUtil/syscall.h"],
textual_hdrs = [
################################ math targets ################################
-cc_library(
+libc_support_library(
name = "math_utils",
srcs = ["src/math/generic/math_utils.cpp"],
hdrs = ["src/math/generic/math_utils.h"],
],
)
-cc_library(
+libc_support_library(
name = "common_constants",
srcs = ["src/math/generic/common_constants.cpp"],
hdrs = ["src/math/generic/common_constants.h"],
],
)
-cc_library(
+libc_support_library(
name = "range_reduction",
hdrs = [
"src/math/generic/range_reduction.h",
],
)
-cc_library(
+libc_support_library(
name = "sincosf_utils",
hdrs = ["src/math/generic/sincosf_utils.h"],
deps = [
"-ubsan",
]
-cc_library(
+libc_support_library(
name = "string_memory_utils",
hdrs = [
"src/string/memory_utils/op_aarch64.h",
],
)
-cc_library(
+libc_support_library(
name = "string_utils",
hdrs = ["src/string/string_utils.h"],
deps = [
LIBC_ROOT_TARGET = ":libc_root"
INTERNAL_SUFFIX = ".__internal__"
-def libc_function(name, srcs, weak = False, deps = None, copts = None, **kwargs):
+def _libc_library(name, copts = None, **kwargs):
+ """Internal macro to serve as a base for all other libc library rules.
+
+ Args:
+ name: Target name.
+ copts: The special compiler options for the target.
+ **kwargs: All other attributes relevant for the cc_library rule.
+ """
+ copts = copts or []
+ # We want all libc sources to be compiled with "hidden" visibility.
+ # The public symbols will be given "default" visibility explicitly.
+ # See src/__support/common.h for more information.
+ copts.append("-fvisibility=hidden")
+ native.cc_library(
+ name = name,
+ copts = copts,
+ linkstatic = 1,
+ **kwargs
+ )
+
+# A convenience var which should be used to list all libc support libraries.
+# Any library which does not define a public function should be listed with
+# libc_support_library.
+libc_support_library = _libc_library
+
+def libc_function(name, srcs, weak = False, deps = None, copts = None,
+ local_defines = None, **kwargs):
"""Add target for a libc function.
The libc function is eventually available as a cc_library target by name
name: Target name. It is normally the name of the function this target is
for.
srcs: The .cpp files which contain the function implementation.
- weak: Whether the symbol is marked weak.
+ weak: Make the symbol corresponding to the libc function "weak".
deps: The list of target dependencies if any.
copts: The list of options to add to the C++ compilation command.
+ local_defines: The preprocessor defines which will be prepended with -D
+ and passed to the compile command of this target but not
+ its deps.
**kwargs: Other attributes relevant for a cc_library. For example, deps.
"""
deps = deps or []
)
# This second target is the llvm libc C function.
- copts.append("-DLLVM_LIBC_PUBLIC_PACKAGING")
+
+ func_attrs = ["__attribute__((visibility(\"default\")))"]
if weak:
- copts.append("-DLLVM_LIBC_FUNCTION_ATTR=__attribute__((weak))")
- native.cc_library(
+ func_attrs.append("__attribute__((weak))")
+ local_defines = local_defines or ["LLVM_LIBC_PUBLIC_PACKAGING"]
+ local_defines.append("LLVM_LIBC_FUNCTION_ATTR='%s'" % ' '.join(func_attrs))
+ _libc_library(
name = name,
srcs = srcs,
deps = deps,
copts = copts,
- linkstatic = 1,
+ local_defines = local_defines,
**kwargs
)