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/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,32 @@ +"""LLVM libc starlark rules for tests.""" + +load("@llvm-project//libc:libc_build_rules.bzl", "INTERNAL_SUFFIX") + +def libc_test(name, srcs, libc_function_deps, additional_deps = None, **kw): + """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. + **kw: Attributes relevant for a cc_test. For example, name, srcs, deps. + """ + if "deps" in kw: + fail("A libc_test target should list 'libc_function_deps' and " + + "'additional_deps' instead of 'deps'.") + deps = [ + "@llvm-project//libc:libc_root", + "@llvm-project//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 + **kw + ) 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,118 @@ +# Tests for LLVM libc math.h functions. + +load("@llvm-project//libc:test/libc_test_rules.bzl", "libc_test") + +licenses(["notice"]) + +libc_test( + name = "exception_status_test", + srcs = ["exception_status_test.cpp"], + additional_deps = [ + "@llvm-project//libc:__support_fputil_fenv_impl" + ], + libc_function_deps = [ + "@llvm-project//libc:feclearexcept", + "@llvm-project//libc:feraiseexcept", + "@llvm-project//libc:fetestexcept", + ], +) + +libc_test( + name = "rounding_mode_test", + srcs = ["rounding_mode_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:fegetround", + "@llvm-project//libc:fesetround", + ], +) + +libc_test( + name = "enabled_exceptions_test", + srcs = ["enabled_exceptions_test.cpp"], + additional_deps = [ + "@llvm-project//libc/utils/UnitTest:fp_test_helpers", + "@llvm-project//libc:__support_common", + "@llvm-project//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "@llvm-project//libc:feclearexcept", + "@llvm-project//libc:feraiseexcept", + "@llvm-project//libc:fetestexcept", + ], + tags = ["nosan"], +) + +libc_test( + name = "feholdexcept_test", + srcs = ["feholdexcept_test.cpp"], + additional_deps = [ + "@llvm-project//libc/utils/UnitTest:fp_test_helpers", + "@llvm-project//libc:__support_common", + "@llvm-project//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "@llvm-project//libc:feholdexcept", + ], + tags = ["nosan"], +) + +libc_test( + name = "exception_flags_test", + srcs = ["exception_flags_test.cpp"], + additional_deps = [ + "@llvm-project//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "@llvm-project//libc:fegetexceptflag", + "@llvm-project//libc:fesetexceptflag", + ], +) + +libc_test( + name = "feclearexcept_test", + srcs = ["feclearexcept_test.cpp"], + additional_deps = [ + "@llvm-project//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "@llvm-project//libc:feclearexcept", + ], +) + +libc_test( + name = "feenableexcept_test", + srcs = ["feenableexcept_test.cpp"], + additional_deps = [ + "@llvm-project//libc:__support_common", + ], + libc_function_deps = [ + "@llvm-project//libc:fedisableexcept", + "@llvm-project//libc:feenableexcept", + "@llvm-project//libc:fegetexcept", + ], +) + +libc_test( + name = "feupdateenv_test", + srcs = ["feupdateenv_test.cpp"], + additional_deps = [ + "@llvm-project//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "@llvm-project//libc:feupdateenv", + ], +) + +libc_test( + name = "getenv_and_setenv_test", + srcs = ["getenv_and_setenv_test.cpp"], + additional_deps = [ + "@llvm-project//libc:__support_fputil_fenv_impl", + ], + libc_function_deps = [ + "@llvm-project//libc:fegetenv", + "@llvm-project//libc:fegetround", + "@llvm-project//libc:fesetenv", + "@llvm-project//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,472 @@ +# Tests for LLVM libc math.h functions. + +load("@llvm-project//libc/test/src/math:libc_math_test_rules.bzl", "math_test") + +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 = [ + "@llvm-project//libc:__support_fputil_basic_operations", + "@llvm-project//libc:__support_fputil_fp_bits", + "@llvm-project//libc/utils/MPFRWrapper:mpfr_wrapper", + "@llvm-project//libc/utils/UnitTest:LibcUnitTest", + "@llvm-project//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 = [ + "@llvm-project//libc:__support_cpp_array", + "@llvm-project//libc:__support_cpp_bit", + ], +) + +math_test( + name = "sqrtf", + hdrs = ["SqrtTest.h"], + additional_deps = [ + "@llvm-project//libc:__support_cpp_array", + "@llvm-project//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") + +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 = [ + "@llvm-project//libc:__support_fputil_fp_bits", + "@llvm-project//libc:__support_fputil_manipulation_functions", + "@llvm-project//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 = [ + "@llvm-project//libc:__support_fputil_basic_operations", + "@llvm-project//libc:__support_fputil_fenv_impl", + "@llvm-project//libc:__support_fputil_fp_bits", + "@llvm-project//libc/utils/UnitTest:LibcUnitTest", + "@llvm-project//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 = [ + "@llvm-project//libc:__support_fputil_fp_bits", + "@llvm-project//libc:__support_fputil_normal_float", + "@llvm-project//libc/utils/UnitTest:LibcUnitTest", + "@llvm-project//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 = [ + "@llvm-project//libc:__support_fputil_fenv_impl", + "@llvm-project//libc:__support_fputil_fp_bits", + "@llvm-project//libc/utils/MPFRWrapper:mpfr_wrapper", + "@llvm-project//libc/utils/UnitTest:LibcUnitTest", + "@llvm-project//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 = [ + "@llvm-project//libc:__support_fputil_fenv_impl", + "@llvm-project//libc:__support_fputil_fp_bits", + "@llvm-project//libc/utils/MPFRWrapper:mpfr_wrapper", + "@llvm-project//libc/utils/UnitTest:LibcUnitTest", + "@llvm-project//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 = [ + "@llvm-project//libc:__support_cpp_array", + "@llvm-project//libc:__support_cpp_bit", + "@llvm-project//libc:__support_cpp_type_traits", + "@llvm-project//libc:__support_fputil_basic_operations", + "@llvm-project//libc:__support_fputil_fp_bits", + "@llvm-project//libc/utils/UnitTest:LibcUnitTest", + "@llvm-project//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 = [ + "@llvm-project//libc:__support_cpp_array", + "@llvm-project//libc:libc_root", + ], +) + +math_test( + name = "cosf", + additional_deps = [ + ":sdcomp26094", + "@llvm-project//libc:__support_cpp_array", + ], +) + +math_test( + name = "sincosf", + additional_deps = [ + ":sdcomp26094", + "@llvm-project//libc:__support_cpp_array", + ], +) + +math_test( + name = "sinf", + additional_deps = [ + ":sdcomp26094", + "@llvm-project//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,37 @@ +load("@llvm-project//libc:test/libc_test_rules.bzl", "libc_test") + +def math_test(name, additional_deps = None, need_mpfr = True, hdrs = None): + """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. + """ + test_name = name + "_test" + srcs = [test_name + ".cpp"] + (hdrs or []) + additional_deps = additional_deps or [] + libc_function_deps = ["@llvm-project//libc:" + name] + additional_deps += [ + "@llvm-project//libc:__support_fputil_basic_operations", + "@llvm-project//libc:__support_builtin_wrappers", + "@llvm-project//libc:__support_fputil_fenv_impl", + "@llvm-project//libc:__support_fputil_float_properties", + "@llvm-project//libc:__support_fputil_fp_bits", + "@llvm-project//libc:__support_uint128", + "@llvm-project//libc:__support_fputil_manipulation_functions", + "@llvm-project//libc:__support_fputil_nearest_integer_operations", + "@llvm-project//libc/utils/UnitTest:fp_test_helpers", + ] + if need_mpfr: + additional_deps.append( + "@llvm-project//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. + ) 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,77 @@ +# Tests for LLVM libc stdlib.h functions. + +load("@llvm-project//libc:test/libc_test_rules.bzl", "libc_test") + +licenses(["notice"]) + +libc_test( + name = "atoi_test", + srcs = ["atoi_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:atoi" + ], +) + +libc_test( + name = "atol_test", + srcs = ["atol_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:atol" + ], +) + +libc_test( + name = "atoll_test", + srcs = ["atoll_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:atoll" + ], +) + +libc_test( + name = "bsearch_test", + srcs = ["bsearch_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:bsearch" + ], +) + +libc_test( + name = "qsort_test", + srcs = ["qsort_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:qsort" + ], +) + +libc_test( + name = "strtol_test", + srcs = ["strtol_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strtol" + ], +) + +libc_test( + name = "strtoll_test", + srcs = ["strtoll_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strtoll" + ], +) + +libc_test( + name = "strtoul_test", + srcs = ["strtoul_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strtoul" + ], +) + +libc_test( + name = "strtoull_test", + srcs = ["strtoull_test.cpp"], + libc_function_deps = [ + "@llvm-project//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,168 @@ +# Tests for LLVM libc string.h functions. + +load("@llvm-project//libc:test/libc_test_rules.bzl", "libc_test") + +licenses(["notice"]) + +libc_test( + name = "strlen_test", + srcs = ["strlen_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strlen" + ], +) + +libc_test( + name = "strcpy_test", + srcs = ["strcpy_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strcpy_sanitized", + ], +) + +libc_test( + name = "strcmp_test", + srcs = ["strcmp_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strcmp", + ], +) + +libc_test( + name = "memchr_test", + srcs = ["memchr_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:memchr", + ], +) + +libc_test( + name = "strchr_test", + srcs = ["strchr_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strchr", + ], +) + +libc_test( + name = "strstr_test", + srcs = ["strstr_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strstr", + ], +) + +libc_test( + name = "strnlen_test", + srcs = ["strnlen_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strnlen", + ], +) + +libc_test( + name = "memrchr_test", + srcs = ["memrchr_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:memrchr", + ], +) + +libc_test( + name = "strrchr_test", + srcs = ["strrchr_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strrchr", + ], +) + +libc_test( + name = "strcspn_test", + srcs = ["strcspn_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strcspn", + ], +) + +libc_test( + name = "strspn_test", + srcs = ["strspn_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strspn", + ], +) + +libc_test( + name = "strtok_test", + srcs = ["strtok_test.cpp"], + libc_function_deps = [ + "@llvm-project//libc:strtok", + ], +) + +cc_library( + name = "memory_check_utils", + hdrs = ["memory_utils/memory_check_utils.h"], + deps = [ + "@llvm-project//libc:__support_cpp_span", + "@llvm-project//libc:string_memory_utils", + ], +) + +libc_test( + name = "memcpy_test", + srcs = ["memcpy_test.cpp"], + additional_deps = [":memory_check_utils"], + libc_function_deps = [ + "@llvm-project//libc:memcpy", + ], +) + +libc_test( + name = "memset_test", + srcs = ["memset_test.cpp"], + additional_deps = [":memory_check_utils"], + libc_function_deps = [ + "@llvm-project//libc:memset", + ], +) + +libc_test( + name = "memmove_test", + srcs = ["memmove_test.cpp"], + additional_deps = [ + "@llvm-project//libc:__support_cpp_span", + "@llvm-project//libc/utils/UnitTest:memory_matcher", + ], + libc_function_deps = [ + "@llvm-project//libc:memcmp", + "@llvm-project//libc:memmove", + ], +) + +libc_test( + name = "memcmp_test", + srcs = ["memcmp_test.cpp"], + additional_deps = [":memory_check_utils"], + libc_function_deps = [ + "@llvm-project//libc:memcmp", + ], +) + +libc_test( + name = "bcmp_test", + srcs = ["bcmp_test.cpp"], + additional_deps = [":memory_check_utils"], + libc_function_deps = [ + "@llvm-project//libc:bcmp", + ], +) + +libc_test( + name = "bzero_test", + srcs = ["bzero_test.cpp"], + additional_deps = [":memory_check_utils"], + libc_function_deps = [ + "@llvm-project//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 = [ + "@llvm-project//libc:__support_common", + "@llvm-project//libc:__support_cpp_bit", + "@llvm-project//libc:__support_cpp_bitset", + "@llvm-project//libc:__support_cpp_string_view", + "@llvm-project//libc:__support_cpp_type_traits", + "@llvm-project//libc:__support_fputil_fp_bits", + "@llvm-project//libc:__support_fputil_platform_defs", + "@llvm-project//libc:libc_root", + "@llvm-project//libc/utils/UnitTest:LibcUnitTest", + "@llvm-project//libc/utils/UnitTest:fp_test_helpers", + "@llvm-project//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 = [ + "@llvm-project//libc:__support_cpp_bit", + "@llvm-project//libc:__support_cpp_bitset", + "@llvm-project//libc:__support_cpp_span", + "@llvm-project//libc:__support_cpp_string_view", + "@llvm-project//libc:__support_cpp_type_traits", + "@llvm-project//libc:__support_uint128", + "@llvm-project//libc:libc_root", + "@llvm-project//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", + "@llvm-project//libc:__support_cpp_bit", + "@llvm-project//libc:__support_cpp_bitset", + "@llvm-project//libc:__support_cpp_span", + "@llvm-project//libc:__support_cpp_type_traits", + "@llvm-project//libc:__support_fputil_fenv_impl", + "@llvm-project//libc:__support_fputil_fp_bits", + "@llvm-project//libc:libc_root", + ], +) + +cc_library( + name = "memory_matcher", + srcs = [ + "MemoryMatcher.cpp", + ], + hdrs = [ + "MemoryMatcher.h", + ], + deps = [ + ":LibcUnitTest", + "@llvm-project//libc:__support_cpp_bit", + "@llvm-project//libc:__support_cpp_bitset", + "@llvm-project//libc:__support_cpp_span", + "@llvm-project//libc:__support_cpp_type_traits", + ], +) + +cc_library( + name = "string_utils", + hdrs = [ + "StringUtils.h", + ], + deps = [ + "@llvm-project//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", + "@llvm-project//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"], # ./configure crashes with `-Werror` + lib_name = "libmpfr", + lib_source = ":sources", + visibility = ["//visibility:public"], + deps = ["@gmp//:gmp_"], +)