diff --git a/utils/bazel/WORKSPACE b/utils/bazel/WORKSPACE --- a/utils/bazel/WORKSPACE +++ b/utils/bazel/WORKSPACE @@ -4,6 +4,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") +load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository") SKYLIB_VERSION = "1.3.0" @@ -71,3 +72,42 @@ name = "vulkan_sdk", ) +git_repository( + name = "bazel_toolchains", + tag = "5.1.2", + remote = "https://github.com/bazelbuild/bazel-toolchains.git" +) + +git_repository( + name = "rules_foreign_cc", + tag = "0.9.0", + remote = "https://github.com/bazelbuild/rules_foreign_cc.git" +) + +load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies") + +# We set register_built_tools to False to prevent building make from source. +# Building make from source fails because of "-Wall -Werror" (.blazerc). +rules_foreign_cc_dependencies(register_built_tools = False) + +maybe( + http_archive, + name = "gmp", + build_file = "@llvm-raw//utils/bazel/third_party_build:gmp.BUILD", + sha256 = "fd4829912cddd12f84181c3451cc752be224643e87fac497b69edddadc49b4f2", + strip_prefix = "gmp-6.2.1", + urls = [ + "https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz", + "https://ftp.gnu.org/gnu/gmp/gmp-6.2.1.tar.xz", + ], +) + +maybe( + http_archive, + name = "mpfr", + build_file = "@llvm-raw//utils/bazel/third_party_build:mpfr.BUILD", + sha256 = "3127fe813218f3a1f0adf4e8899de23df33b4cf4b4b3831a5314f78e65ffa2d6", + strip_prefix = "mpfr-4.1.0", + urls = ["https://www.mpfr.org/mpfr-current/mpfr-4.1.0.tar.gz"], +) + diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -14,6 +14,15 @@ licenses(["notice"]) +# From https://youtu.be/01BHJT7GL9o +# Used to disable target building. +constraint_setting(name = "not_compatible_setting") +constraint_value( + name = "not_compatible", + constraint_setting = ":not_compatible_setting", + visibility = ["//visibility:public"], +) + # This empty root library helps us add an include path to this directory # using the 'includes' attribute. The strings listed in the includes attribute # are relative paths wrt this library but are inherited by the dependents diff --git a/utils/bazel/llvm-project-overlay/libc/test/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/BUILD.bazel new file mode 100644 diff --git a/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/libc/test/libc_test_rules.bzl @@ -0,0 +1,36 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +"""LLVM libc starlark rules for tests.""" + +load("//libc:libc_build_rules.bzl", "INTERNAL_SUFFIX") + +def libc_test(name, srcs, libc_function_deps, additional_deps = None, **kwargs): + """Add target for a libc test. + + Args: + name: Test target name + srcs: List of sources for the test. + libc_function_deps: List of libc_function targets used by this test. + additional_deps: List of additional targets used by this test. + **kwargs: Attributes relevant for a cc_test. For example, name, srcs, deps. + """ + if "deps" in kwargs: + fail("A libc_test target should list 'libc_function_deps' and " + + "'additional_deps' instead of 'deps'.") + deps = [ + "//libc:libc_root", + "//libc/utils/UnitTest:LibcUnitTest", + ] + for d in libc_function_deps: + deps.append(d + INTERNAL_SUFFIX) + if additional_deps: + deps.extend(additional_deps) + native.cc_test( + name = name, + srcs = srcs, + deps = deps, + features = ["-link_llvmlibc"], # Do not link libllvmlibc.a + **kwargs + ) diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/libc/test/src/fenv/BUILD.bazel @@ -0,0 +1,120 @@ +# Tests for LLVM libc math.h functions. + +load("//libc/test:libc_test_rules.bzl", "libc_test") + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +libc_test( + name = "exception_status_test", + srcs = ["exception_status_test.cpp"], + additional_deps = [ + "//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "//libc:feclearexcept", + "//libc:feraiseexcept", + "//libc:fetestexcept", + ], +) + +libc_test( + name = "rounding_mode_test", + srcs = ["rounding_mode_test.cpp"], + libc_function_deps = [ + "//libc:fegetround", + "//libc:fesetround", + ], +) + +libc_test( + name = "enabled_exceptions_test", + srcs = ["enabled_exceptions_test.cpp"], + additional_deps = [ + "//libc/utils/UnitTest:fp_test_helpers", + "//libc:__support_common", + "//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "//libc:feclearexcept", + "//libc:feraiseexcept", + "//libc:fetestexcept", + ], + tags = ["nosan"], +) + +libc_test( + name = "feholdexcept_test", + srcs = ["feholdexcept_test.cpp"], + additional_deps = [ + "//libc/utils/UnitTest:fp_test_helpers", + "//libc:__support_common", + "//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "//libc:feholdexcept", + ], + tags = ["nosan"], +) + +libc_test( + name = "exception_flags_test", + srcs = ["exception_flags_test.cpp"], + additional_deps = [ + "//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "//libc:fegetexceptflag", + "//libc:fesetexceptflag", + ], +) + +libc_test( + name = "feclearexcept_test", + srcs = ["feclearexcept_test.cpp"], + additional_deps = [ + "//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "//libc:feclearexcept", + ], +) + +libc_test( + name = "feenableexcept_test", + srcs = ["feenableexcept_test.cpp"], + additional_deps = [ + "//libc:__support_common", + ], + libc_function_deps = [ + "//libc:fedisableexcept", + "//libc:feenableexcept", + "//libc:fegetexcept", + ], +) + +libc_test( + name = "feupdateenv_test", + srcs = ["feupdateenv_test.cpp"], + additional_deps = [ + "//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "//libc:feupdateenv", + ], +) + +libc_test( + name = "getenv_and_setenv_test", + srcs = ["getenv_and_setenv_test.cpp"], + additional_deps = [ + "//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "//libc:fegetenv", + "//libc:fegetround", + "//libc:fesetenv", + "//libc:fesetround", + ], +) diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/BUILD.bazel @@ -0,0 +1,483 @@ +# Tests for LLVM libc math.h functions. + +load("//libc/test/src/math:libc_math_test_rules.bzl", "math_test") +load("//libc:platforms.bzl", "PLATFORM_CPU_ARM64") +load("@bazel_skylib//lib:selects.bzl", "selects") + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +math_test( + name = "fabs", + hdrs = ["FAbsTest.h"], +) + +math_test( + name = "fabsf", + hdrs = ["FAbsTest.h"], +) + +math_test( + name = "fabsl", + hdrs = ["FAbsTest.h"], +) + +math_test( + name = "ceil", + hdrs = ["CeilTest.h"], +) + +math_test( + name = "ceilf", + hdrs = ["CeilTest.h"], +) + +math_test( + name = "ceill", + hdrs = ["CeilTest.h"], +) + +math_test( + name = "floor", + hdrs = ["FloorTest.h"], +) + +math_test( + name = "floorf", + hdrs = ["FloorTest.h"], +) + +math_test( + name = "floorl", + hdrs = ["FloorTest.h"], +) + +math_test( + name = "trunc", + hdrs = ["TruncTest.h"], +) + +math_test( + name = "truncf", + hdrs = ["TruncTest.h"], +) + +math_test( + name = "truncl", + hdrs = ["TruncTest.h"], +) + +math_test( + name = "round", + hdrs = ["RoundTest.h"], +) + +math_test( + name = "roundf", + hdrs = ["RoundTest.h"], +) + +math_test( + name = "roundl", + hdrs = ["RoundTest.h"], +) + +math_test( + name = "frexp", + hdrs = ["FrexpTest.h"], +) + +math_test( + name = "frexpf", + hdrs = ["FrexpTest.h"], +) + +math_test( + name = "frexpl", + hdrs = ["FrexpTest.h"], +) + +math_test( + name = "hypot", + hdrs = ["HypotTest.h"], +) + +math_test( + name = "hypotf", + hdrs = [ + "HypotTest.h", + "hypotf_hard_to_round.h", + ], +) + +math_test( + name = "logb", + hdrs = ["LogbTest.h"], +) + +math_test( + name = "logbf", + hdrs = ["LogbTest.h"], +) + +math_test( + name = "logbl", + hdrs = ["LogbTest.h"], +) + +math_test( + name = "modf", + hdrs = ["ModfTest.h"], +) + +math_test( + name = "modff", + hdrs = ["ModfTest.h"], +) + +math_test( + name = "modfl", + hdrs = ["ModfTest.h"], +) + +cc_library( + name = "remquo_test_template", + hdrs = ["RemQuoTest.h"], + deps = [ + "//libc:__support_fputil_basic_operations", + "//libc:__support_fputil_fp_bits", + "//libc/utils/MPFRWrapper:mpfr_wrapper", + "//libc/utils/UnitTest:LibcUnitTest", + "//libc/utils/UnitTest:fp_test_helpers", + ], +) + +math_test( + name = "remquo", + additional_deps = [":remquo_test_template"], +) + +math_test( + name = "remquof", + additional_deps = [":remquo_test_template"], +) + +math_test( + name = "remquol", + additional_deps = [":remquo_test_template"], +) + +math_test( + name = "fmin", + hdrs = ["FMinTest.h"], +) + +math_test( + name = "fminf", + hdrs = ["FMinTest.h"], +) + +math_test( + name = "fminl", + hdrs = ["FMinTest.h"], +) + +math_test( + name = "fmax", + hdrs = ["FMaxTest.h"], +) + +math_test( + name = "fmaxf", + hdrs = ["FMaxTest.h"], +) + +math_test( + name = "fmaxl", + hdrs = ["FMaxTest.h"], +) + +math_test( + name = "sqrt", + hdrs = ["SqrtTest.h"], + additional_deps = [ + "//libc:__support_cpp_array", + "//libc:__support_cpp_bit", + ], +) + +math_test( + name = "sqrtf", + hdrs = ["SqrtTest.h"], + additional_deps = [ + "//libc:__support_cpp_array", + "//libc:__support_cpp_bit", + ], +) + +# TODO(sivachandra): sqrtl test currently fails on Aarch64 because of +# insufficient precision in MPFR leading to https://hal.archives-ouvertes.fr/hal-01091186/document +# We will comment it out for now and wait for it to get fixed upstream. +math_test( + name = "sqrtl", + hdrs = ["SqrtTest.h"], + target_compatible_with = selects.with_or({ + "//conditions:default": [], + PLATFORM_CPU_ARM64: ["//libc:not_compatible"], + }), +) + +math_test( + name = "copysign", + hdrs = ["CopySignTest.h"], +) + +math_test( + name = "copysignf", + hdrs = ["CopySignTest.h"], +) + +math_test( + name = "copysignl", + hdrs = ["CopySignTest.h"], +) + +cc_library( + name = "ilogb_test_template", + hdrs = ["ILogbTest.h"], + deps = [ + "//libc:__support_fputil_fp_bits", + "//libc:__support_fputil_manipulation_functions", + "//libc/utils/UnitTest:LibcUnitTest", + ], +) + +math_test( + name = "ilogb", + additional_deps = [":ilogb_test_template"], +) + +math_test( + name = "ilogbf", + additional_deps = [":ilogb_test_template"], +) + +math_test( + name = "ilogbl", + additional_deps = [":ilogb_test_template"], +) + +cc_library( + name = "fdim_test_template", + hdrs = ["FDimTest.h"], + deps = [ + "//libc:__support_fputil_basic_operations", + "//libc:__support_fputil_fenv_impl", + "//libc:__support_fputil_fp_bits", + "//libc/utils/UnitTest:LibcUnitTest", + "//libc/utils/UnitTest:fp_test_helpers", + ], +) + +math_test( + name = "fdim", + additional_deps = [":fdim_test_template"], +) + +math_test( + name = "fdimf", + additional_deps = [":fdim_test_template"], +) + +math_test( + name = "fdiml", + additional_deps = [":fdim_test_template"], +) + +cc_library( + name = "ldexp_test_template", + hdrs = ["LdExpTest.h"], + deps = [ + "//libc:__support_fputil_fp_bits", + "//libc:__support_fputil_normal_float", + "//libc/utils/UnitTest:LibcUnitTest", + "//libc/utils/UnitTest:fp_test_helpers", + ], +) + +math_test( + name = "ldexp", + additional_deps = [":ldexp_test_template"], +) + +math_test( + name = "ldexpf", + additional_deps = [":ldexp_test_template"], +) + +math_test( + name = "ldexpl", + additional_deps = [":ldexp_test_template"], +) + +cc_library( + name = "rint_test_template", + hdrs = ["RIntTest.h"], + deps = [ + "//libc:__support_fputil_fenv_impl", + "//libc:__support_fputil_fp_bits", + "//libc/utils/MPFRWrapper:mpfr_wrapper", + "//libc/utils/UnitTest:LibcUnitTest", + "//libc/utils/UnitTest:fp_test_helpers", + ], +) + +math_test( + name = "rint", + additional_deps = [":rint_test_template"], +) + +math_test( + name = "rintf", + additional_deps = [":rint_test_template"], +) + +math_test( + name = "rintl", + additional_deps = [":rint_test_template"], +) + +cc_library( + name = "round_to_integer_test_template", + hdrs = ["RoundToIntegerTest.h"], + deps = [ + "//libc:__support_fputil_fenv_impl", + "//libc:__support_fputil_fp_bits", + "//libc/utils/MPFRWrapper:mpfr_wrapper", + "//libc/utils/UnitTest:LibcUnitTest", + "//libc/utils/UnitTest:fp_test_helpers", + ], +) + +math_test( + name = "lrint", + additional_deps = [":round_to_integer_test_template"], +) + +math_test( + name = "lrintf", + additional_deps = [":round_to_integer_test_template"], +) + +math_test( + name = "lrintl", + additional_deps = [":round_to_integer_test_template"], +) + +math_test( + name = "llrint", + additional_deps = [":round_to_integer_test_template"], +) + +math_test( + name = "llrintf", + additional_deps = [":round_to_integer_test_template"], +) + +math_test( + name = "llrintl", + additional_deps = [":round_to_integer_test_template"], +) + +math_test( + name = "lround", + additional_deps = [":round_to_integer_test_template"], +) + +math_test( + name = "lroundf", + additional_deps = [":round_to_integer_test_template"], +) + +math_test( + name = "lroundl", + additional_deps = [":round_to_integer_test_template"], +) + +math_test( + name = "llround", + additional_deps = [":round_to_integer_test_template"], +) + +math_test( + name = "llroundf", + additional_deps = [":round_to_integer_test_template"], +) + +math_test( + name = "llroundl", + additional_deps = [":round_to_integer_test_template"], +) + +cc_library( + name = "nextafter_test_template", + hdrs = ["NextAfterTest.h"], + deps = [ + "//libc:__support_cpp_array", + "//libc:__support_cpp_bit", + "//libc:__support_cpp_type_traits", + "//libc:__support_fputil_basic_operations", + "//libc:__support_fputil_fp_bits", + "//libc/utils/UnitTest:LibcUnitTest", + "//libc/utils/UnitTest:fp_test_helpers", + ], +) + +math_test( + name = "nextafter", + additional_deps = [":nextafter_test_template"], +) + +math_test( + name = "nextafterf", + additional_deps = [":nextafter_test_template"], +) + +math_test( + name = "nextafterl", + additional_deps = [":nextafter_test_template"], +) + +cc_library( + name = "sdcomp26094", + hdrs = ["sdcomp26094.h"], + deps = [ + "//libc:__support_cpp_array", + "//libc:libc_root", + ], +) + +math_test( + name = "cosf", + additional_deps = [ + ":sdcomp26094", + "//libc:__support_cpp_array", + ], +) + +math_test( + name = "sincosf", + additional_deps = [ + ":sdcomp26094", + "//libc:__support_cpp_array", + ], +) + +math_test( + name = "sinf", + additional_deps = [ + ":sdcomp26094", + "//libc:__support_cpp_array", + ], +) diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/math/libc_math_test_rules.bzl b/utils/bazel/llvm-project-overlay/libc/test/src/math/libc_math_test_rules.bzl new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/libc/test/src/math/libc_math_test_rules.bzl @@ -0,0 +1,39 @@ +load("//libc/test:libc_test_rules.bzl", "libc_test") + +def math_test(name, additional_deps = None, need_mpfr = True, hdrs = None, **kwargs): + """Add a target for the unittest of a math function. + + Args: + name: The name of the function being tested. + additional_deps: List of additional depenencies required by the test. + need_mpfr: True if the test uses mpfr_wrappper, False otherwise. + hdrs: List of headers to add. + **kwargs: Attributes relevant for a cc_test. For example, name, srcs, deps. + """ + test_name = name + "_test" + srcs = [test_name + ".cpp"] + (hdrs or []) + additional_deps = additional_deps or [] + libc_function_deps = ["//libc:" + name] + additional_deps += [ + "//libc:__support_fputil_basic_operations", + "//libc:__support_builtin_wrappers", + "//libc:__support_fputil_fenv_impl", + "//libc:__support_fputil_float_properties", + "//libc:__support_fputil_fp_bits", + "//libc:__support_uint128", + "//libc:__support_fputil_manipulation_functions", + "//libc:__support_fputil_nearest_integer_operations", + "//libc/utils/UnitTest:fp_test_helpers", + ] + if need_mpfr: + additional_deps.append( + "//libc/utils/MPFRWrapper:mpfr_wrapper", + ) + libc_test( + name = test_name, + srcs = srcs, + libc_function_deps = libc_function_deps, + additional_deps = additional_deps, + size = "enormous", # Some tests are emulated and take very long. + **kwargs + ) diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel @@ -0,0 +1,79 @@ +# Tests for LLVM libc stdlib.h functions. + +load("//libc/test:libc_test_rules.bzl", "libc_test") + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +libc_test( + name = "atoi_test", + srcs = ["atoi_test.cpp"], + libc_function_deps = [ + "//libc:atoi" + ], +) + +libc_test( + name = "atol_test", + srcs = ["atol_test.cpp"], + libc_function_deps = [ + "//libc:atol" + ], +) + +libc_test( + name = "atoll_test", + srcs = ["atoll_test.cpp"], + libc_function_deps = [ + "//libc:atoll" + ], +) + +libc_test( + name = "bsearch_test", + srcs = ["bsearch_test.cpp"], + libc_function_deps = [ + "//libc:bsearch" + ], +) + +libc_test( + name = "qsort_test", + srcs = ["qsort_test.cpp"], + libc_function_deps = [ + "//libc:qsort" + ], +) + +libc_test( + name = "strtol_test", + srcs = ["strtol_test.cpp"], + libc_function_deps = [ + "//libc:strtol" + ], +) + +libc_test( + name = "strtoll_test", + srcs = ["strtoll_test.cpp"], + libc_function_deps = [ + "//libc:strtoll" + ], +) + +libc_test( + name = "strtoul_test", + srcs = ["strtoul_test.cpp"], + libc_function_deps = [ + "//libc:strtoul" + ], +) + +libc_test( + name = "strtoull_test", + srcs = ["strtoull_test.cpp"], + libc_function_deps = [ + "//libc:strtoull" + ], +) diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/string/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/string/BUILD.bazel new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/libc/test/src/string/BUILD.bazel @@ -0,0 +1,170 @@ +# Tests for LLVM libc string.h functions. + +load("//libc/test:libc_test_rules.bzl", "libc_test") + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +libc_test( + name = "strlen_test", + srcs = ["strlen_test.cpp"], + libc_function_deps = [ + "//libc:strlen" + ], +) + +libc_test( + name = "strcpy_test", + srcs = ["strcpy_test.cpp"], + libc_function_deps = [ + "//libc:strcpy_sanitized", + ], +) + +libc_test( + name = "strcmp_test", + srcs = ["strcmp_test.cpp"], + libc_function_deps = [ + "//libc:strcmp", + ], +) + +libc_test( + name = "memchr_test", + srcs = ["memchr_test.cpp"], + libc_function_deps = [ + "//libc:memchr", + ], +) + +libc_test( + name = "strchr_test", + srcs = ["strchr_test.cpp"], + libc_function_deps = [ + "//libc:strchr", + ], +) + +libc_test( + name = "strstr_test", + srcs = ["strstr_test.cpp"], + libc_function_deps = [ + "//libc:strstr", + ], +) + +libc_test( + name = "strnlen_test", + srcs = ["strnlen_test.cpp"], + libc_function_deps = [ + "//libc:strnlen", + ], +) + +libc_test( + name = "memrchr_test", + srcs = ["memrchr_test.cpp"], + libc_function_deps = [ + "//libc:memrchr", + ], +) + +libc_test( + name = "strrchr_test", + srcs = ["strrchr_test.cpp"], + libc_function_deps = [ + "//libc:strrchr", + ], +) + +libc_test( + name = "strcspn_test", + srcs = ["strcspn_test.cpp"], + libc_function_deps = [ + "//libc:strcspn", + ], +) + +libc_test( + name = "strspn_test", + srcs = ["strspn_test.cpp"], + libc_function_deps = [ + "//libc:strspn", + ], +) + +libc_test( + name = "strtok_test", + srcs = ["strtok_test.cpp"], + libc_function_deps = [ + "//libc:strtok", + ], +) + +cc_library( + name = "memory_check_utils", + hdrs = ["memory_utils/memory_check_utils.h"], + deps = [ + "//libc:__support_cpp_span", + "//libc:string_memory_utils", + ], +) + +libc_test( + name = "memcpy_test", + srcs = ["memcpy_test.cpp"], + additional_deps = [":memory_check_utils"], + libc_function_deps = [ + "//libc:memcpy", + ], +) + +libc_test( + name = "memset_test", + srcs = ["memset_test.cpp"], + additional_deps = [":memory_check_utils"], + libc_function_deps = [ + "//libc:memset", + ], +) + +libc_test( + name = "memmove_test", + srcs = ["memmove_test.cpp"], + additional_deps = [ + "//libc:__support_cpp_span", + "//libc/utils/UnitTest:memory_matcher", + ], + libc_function_deps = [ + "//libc:memcmp", + "//libc:memmove", + ], +) + +libc_test( + name = "memcmp_test", + srcs = ["memcmp_test.cpp"], + additional_deps = [":memory_check_utils"], + libc_function_deps = [ + "//libc:memcmp", + ], +) + +libc_test( + name = "bcmp_test", + srcs = ["bcmp_test.cpp"], + additional_deps = [":memory_check_utils"], + libc_function_deps = [ + "//libc:bcmp", + ], +) + +libc_test( + name = "bzero_test", + srcs = ["bzero_test.cpp"], + additional_deps = [":memory_check_utils"], + libc_function_deps = [ + "//libc:bzero", + ], +) diff --git a/utils/bazel/llvm-project-overlay/libc/utils/MPFRWrapper/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/utils/MPFRWrapper/BUILD.bazel new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/libc/utils/MPFRWrapper/BUILD.bazel @@ -0,0 +1,25 @@ +# A wrapper library over MPFR for use with LLVM libc math unittests. + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +cc_library( + name = "mpfr_wrapper", + srcs = ["MPFRUtils.cpp"], + hdrs = ["MPFRUtils.h"], + deps = [ + "//libc:__support_common", + "//libc:__support_cpp_bit", + "//libc:__support_cpp_bitset", + "//libc:__support_cpp_string_view", + "//libc:__support_cpp_type_traits", + "//libc:__support_fputil_fp_bits", + "//libc:__support_fputil_platform_defs", + "//libc:libc_root", + "//libc/utils/UnitTest:LibcUnitTest", + "//libc/utils/UnitTest:fp_test_helpers", + "//libc/utils/testutils:libc_test_utils", + "@mpfr//:mpfr_", + ], +) diff --git a/utils/bazel/llvm-project-overlay/libc/utils/UnitTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/utils/UnitTest/BUILD.bazel new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/libc/utils/UnitTest/BUILD.bazel @@ -0,0 +1,79 @@ +# LLVM libc unittest library. + +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +cc_library( + name = "LibcUnitTest", + srcs = [ + "LibcTest.cpp", + "LibcTestMain.cpp", + ], + hdrs = [ + "LibcTest.h", + "PlatformDefs.h", + "Test.h", + ], + deps = [ + "//libc:__support_cpp_bit", + "//libc:__support_cpp_bitset", + "//libc:__support_cpp_span", + "//libc:__support_cpp_string_view", + "//libc:__support_cpp_type_traits", + "//libc:__support_uint128", + "//libc:libc_root", + "//libc/utils/testutils:libc_test_utils", + "//llvm:Support", + ], +) + +cc_library( + name = "fp_test_helpers", + srcs = [ + "FPExceptMatcher.cpp", + "FPMatcher.cpp", + ], + hdrs = [ + "FPExceptMatcher.h", + "FPMatcher.h", + ], + deps = [ + ":LibcUnitTest", + ":string_utils", + "//libc:__support_cpp_bit", + "//libc:__support_cpp_bitset", + "//libc:__support_cpp_span", + "//libc:__support_cpp_type_traits", + "//libc:__support_fputil_fenv_impl", + "//libc:__support_fputil_fp_bits", + "//libc:libc_root", + ], +) + +cc_library( + name = "memory_matcher", + srcs = [ + "MemoryMatcher.cpp", + ], + hdrs = [ + "MemoryMatcher.h", + ], + deps = [ + ":LibcUnitTest", + "//libc:__support_cpp_bit", + "//libc:__support_cpp_bitset", + "//libc:__support_cpp_span", + "//libc:__support_cpp_type_traits", + ], +) + +cc_library( + name = "string_utils", + hdrs = [ + "StringUtils.h", + ], + deps = [ + "//libc:__support_cpp_type_traits", + ], +) diff --git a/utils/bazel/llvm-project-overlay/libc/utils/testutils/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/utils/testutils/BUILD.bazel new file mode 100644 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/libc/utils/testutils/BUILD.bazel @@ -0,0 +1,23 @@ +package(default_visibility = ["//visibility:public"]) + +licenses(["notice"]) + +cc_library( + name = "libc_test_utils", + srcs = [ + "ExecuteFunctionUnix.cpp", + "FDReaderUnix.cpp", + "RoundingModeUtils.cpp", + "StreamWrapper.cpp", + ], + hdrs = [ + "ExecuteFunction.h", + "FDReader.h", + "RoundingModeUtils.h", + "StreamWrapper.h", + ], + deps = [ + "//llvm:Support", + "//libc:libc_root", + ], +) diff --git a/utils/bazel/third_party_build/gmp.BUILD b/utils/bazel/third_party_build/gmp.BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/third_party_build/gmp.BUILD @@ -0,0 +1,15 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make_variant") + +filegroup( + name = "sources", + srcs = glob(["**"]), +) + +configure_make_variant( + name = "gmp", + toolchain = "@rules_foreign_cc//toolchains:preinstalled_autoconf_toolchain", + copts = ["-Wno-error"], # ./configure crashes with `-Werror` + lib_name = "libgmp", + lib_source = ":sources", + visibility = ["//visibility:public"], +) diff --git a/utils/bazel/third_party_build/mpfr.BUILD b/utils/bazel/third_party_build/mpfr.BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/third_party_build/mpfr.BUILD @@ -0,0 +1,16 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make_variant") + +filegroup( + name = "sources", + srcs = glob(["**"]), +) + +configure_make_variant( + name = "mpfr", + toolchain = "@rules_foreign_cc//toolchains:preinstalled_autoconf_toolchain", + copts = ["-Wno-error", "-w"], # ./configure crashes with `-Werror` + lib_name = "libmpfr", + lib_source = ":sources", + visibility = ["//visibility:public"], + deps = ["@gmp//:gmp_"], +)