brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.8 KiB · e35913d Raw
88 lines · plain
1# This file is licensed under the Apache License v2.0 with LLVM Exceptions.2# See https://llvm.org/LICENSE.txt for license information.3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception4 5"""LLVM libc starlark rules for tests.6 7libc functions are created though the libc_build_rules.bzl:libc_function.8They come in two flavors:9 - the internal one that is scoped into the `LIBC_NAMESPACE` namespace.10 - the libc one that is the regular C function.11 12When performing tests we make sure to always use the internal version.13"""14 15load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")16load("//libc:libc_build_rules.bzl", "libc_common_copts")17load("//libc:libc_configure_options.bzl", "LIBC_CONFIGURE_OPTIONS")18 19_FULL_BUILD_COPTS = [20    "-nostdlib++",21    "-nostdlib",22    "-DLIBC_FULL_BUILD",23    "-DLIBC_COPT_USE_C_ASSERT",24]25 26def libc_test(27        name,28        copts = [],29        deps = [],30        local_defines = [],31        use_test_framework = True,32        full_build = False,33        **kwargs):34    """Add target for a libc test.35 36    Args:37      name: Test target name38      copts: The list of options to add to the C++ compilation command.39      deps: The list of libc functions and libraries to be linked in.40      local_defines: The list of target local_defines if any.41      use_test_framework: Whether to use the libc unit test `main` function.42      full_build: Whether to compile with LIBC_FULL_BUILD and disallow43          use of system headers. This is useful for tests that include both44          LLVM libc headers and proxy headers to avoid conflicting definitions.45      **kwargs: Attributes relevant for a cc_test.46    """47    deps = deps + [48        "//libc:hdr_stdint_proxy",49        "//libc:__support_macros_config",50        "//libc:__support_libc_errno",51        "//libc:errno",52        "//libc:func_aligned_alloc",53        "//libc:func_free",54        "//libc:func_malloc",55        "//libc:func_realloc",56    ]57    if use_test_framework:58        deps = deps + ["//libc/test/UnitTest:LibcUnitTest"]59 60    if full_build:61        copts = copts + _FULL_BUILD_COPTS62    cc_test(63        name = name,64        local_defines = local_defines + LIBC_CONFIGURE_OPTIONS,65        deps = deps,66        copts = copts + libc_common_copts(),67        linkstatic = 1,68        **kwargs69    )70 71def libc_test_library(name, copts = [], local_defines = [], **kwargs):72    """Add target for library used in libc tests.73 74    Args:75      name: Library target name.76      copts: See cc_library.copts.77      local_defines: See cc_library.local_defines.78      **kwargs: Other attributes relevant to cc_library (e.g. "deps").79    """80    cc_library(81        name = name,82        testonly = True,83        copts = copts + libc_common_copts(),84        local_defines = local_defines + LIBC_CONFIGURE_OPTIONS,85        linkstatic = 1,86        **kwargs87    )88