Skip to content

Commit f9a6ea4

Browse files
authored
[libc][bazel] Add BUILD targets for complex functions and tests. (#129618)
This involved a little bit of yak shaving because one of the new tests depends on MPC, and we didn't have targets for it yet, so I ended up needing to add a similar setup to what we have for MPFR.
1 parent 6f25614 commit f9a6ea4

File tree

8 files changed

+506
-2
lines changed

8 files changed

+506
-2
lines changed

libc/utils/MPCWrapper/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ if(LIBC_TESTS_CAN_USE_MPC)
22
add_library(libcMPCWrapper STATIC
33
MPCUtils.cpp
44
MPCUtils.h
5+
mpc_inc.h
56
)
67
_get_common_test_compile_options(compile_options "" "")
78
list(REMOVE_ITEM compile_options "-ffreestanding")

libc/utils/MPCWrapper/MPCUtils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@
1010

1111
#include "src/__support/CPP/array.h"
1212
#include "src/__support/CPP/stringstream.h"
13+
#include "utils/MPCWrapper/mpc_inc.h"
1314
#include "utils/MPFRWrapper/MPCommon.h"
1415

1516
#include <stdint.h>
1617

17-
#include "mpc.h"
18-
1918
template <typename T> using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
2019

2120
namespace LIBC_NAMESPACE_DECL {

libc/utils/MPCWrapper/mpc_inc.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- MPCUtils.h ----------------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_UTILS_MPCWRAPPER_MPC_INC_H
10+
#define LLVM_LIBC_UTILS_MPCWRAPPER_MPC_INC_H
11+
12+
#ifdef CUSTOM_MPC_INCLUDER
13+
// Some downstream repos are monoliths carrying MPC sources in their third
14+
// party directory. In such repos, including the MPC header as
15+
// `#include <mpc.h>` is either disallowed or not possible. If that is the
16+
// case, a file named `CustomMPCIncluder.h` should be added through which the
17+
// MPC header can be included in manner allowed in that repo.
18+
#include "CustomMPCIncluder.h"
19+
#else
20+
#include <mpc.h>
21+
#endif
22+
23+
#endif // LLVM_LIBC_UTILS_MPCWRAPPER_MPC_INC_H

utils/bazel/WORKSPACE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ maybe(
126126
urls = ["https://www.mpfr.org/mpfr-4.1.1/mpfr-4.1.1.tar.gz"],
127127
)
128128

129+
maybe(
130+
http_archive,
131+
name = "mpc",
132+
build_file = "@llvm-raw//utils/bazel/third_party_build:mpc.BUILD",
133+
sha256 = "ab642492f5cf882b74aa0cb730cd410a81edcdbec895183ce930e706c1c759b8",
134+
strip_prefix = "mpc-1.3.1",
135+
urls = ["https://ftp.gnu.org/gnu/mpc/mpc-1.3.1.tar.gz"],
136+
)
137+
129138
maybe(
130139
http_archive,
131140
name = "pfm",

utils/bazel/llvm-project-overlay/libc/BUILD.bazel

Lines changed: 291 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,34 @@ config_setting(
5252
flag_values = {":mpfr": "system"},
5353
)
5454

55+
# A flag to pick which `mpc` to use for math tests.
56+
# Usage: `--@llvm-project//libc:mpc=<disable|external|system>`.
57+
# Flag documentation: https://bazel.build/extending/config
58+
string_flag(
59+
name = "mpc",
60+
build_setting_default = "external",
61+
values = [
62+
"disable", # Skip tests that need mpc
63+
"external", # Build mpc from source
64+
"system", # Use system mpc (non hermetic)
65+
],
66+
)
67+
68+
config_setting(
69+
name = "mpc_disable",
70+
flag_values = {":mpc": "disable"},
71+
)
72+
73+
config_setting(
74+
name = "mpc_external",
75+
flag_values = {":mpc": "external"},
76+
)
77+
78+
config_setting(
79+
name = "mpc_system",
80+
flag_values = {":mpc": "system"},
81+
)
82+
5583
########################### Header Generation ##################################
5684

5785
py_binary(
@@ -865,6 +893,26 @@ libc_support_library(
865893
],
866894
)
867895

896+
libc_support_library(
897+
name = "__support_complex_type",
898+
hdrs = ["src/__support/complex_type.h"],
899+
deps = [
900+
":__support_macros_config",
901+
":__support_macros_properties_complex_types",
902+
":__support_macros_properties_types",
903+
],
904+
)
905+
906+
libc_support_library(
907+
name = "__support_complex_basic_ops",
908+
hdrs = ["src/__support/complex_basic_ops.h"],
909+
deps = [
910+
":__support_complex_type",
911+
":__support_cpp_bit",
912+
":__support_fputil_fp_bits",
913+
],
914+
)
915+
868916
libc_support_library(
869917
name = "__support_fputil_basic_operations",
870918
hdrs = [
@@ -1890,6 +1938,249 @@ libc_support_library(
18901938
],
18911939
)
18921940

1941+
############################### complex targets ################################
1942+
1943+
libc_function(
1944+
name = "cimag",
1945+
srcs = ["src/complex/generic/cimag.cpp"],
1946+
hdrs = ["src/complex/cimag.h"],
1947+
deps = [
1948+
":__support_common",
1949+
":__support_complex_type",
1950+
":__support_cpp_bit",
1951+
":__support_macros_config",
1952+
],
1953+
)
1954+
1955+
libc_function(
1956+
name = "cimagf",
1957+
srcs = ["src/complex/generic/cimagf.cpp"],
1958+
hdrs = ["src/complex/cimagf.h"],
1959+
deps = [
1960+
":__support_common",
1961+
":__support_complex_type",
1962+
":__support_cpp_bit",
1963+
":__support_macros_config",
1964+
],
1965+
)
1966+
1967+
libc_function(
1968+
name = "cimagf128",
1969+
srcs = ["src/complex/generic/cimagf128.cpp"],
1970+
hdrs = ["src/complex/cimagf128.h"],
1971+
deps = [
1972+
":__support_common",
1973+
":__support_complex_type",
1974+
":__support_cpp_bit",
1975+
":__support_macros_config",
1976+
":__support_macros_properties_complex_types",
1977+
":__support_macros_properties_types",
1978+
],
1979+
)
1980+
1981+
libc_function(
1982+
name = "cimagf16",
1983+
srcs = ["src/complex/generic/cimagf16.cpp"],
1984+
hdrs = ["src/complex/cimagf16.h"],
1985+
deps = [
1986+
":__support_common",
1987+
":__support_complex_type",
1988+
":__support_cpp_bit",
1989+
":__support_macros_config",
1990+
":__support_macros_properties_complex_types",
1991+
":__support_macros_properties_types",
1992+
],
1993+
)
1994+
1995+
libc_function(
1996+
name = "cimagl",
1997+
srcs = ["src/complex/generic/cimagl.cpp"],
1998+
hdrs = ["src/complex/cimagl.h"],
1999+
deps = [
2000+
":__support_common",
2001+
":__support_complex_type",
2002+
":__support_cpp_bit",
2003+
":__support_macros_config",
2004+
],
2005+
)
2006+
2007+
libc_function(
2008+
name = "conj",
2009+
srcs = ["src/complex/generic/conj.cpp"],
2010+
hdrs = ["src/complex/conj.h"],
2011+
deps = [
2012+
":__support_common",
2013+
":__support_complex_basic_ops",
2014+
":__support_macros_config",
2015+
],
2016+
)
2017+
2018+
libc_function(
2019+
name = "conjf",
2020+
srcs = ["src/complex/generic/conjf.cpp"],
2021+
hdrs = ["src/complex/conjf.h"],
2022+
deps = [
2023+
":__support_common",
2024+
":__support_complex_basic_ops",
2025+
":__support_macros_config",
2026+
],
2027+
)
2028+
2029+
libc_function(
2030+
name = "conjf128",
2031+
srcs = ["src/complex/generic/conjf128.cpp"],
2032+
hdrs = ["src/complex/conjf128.h"],
2033+
deps = [
2034+
":__support_common",
2035+
":__support_complex_basic_ops",
2036+
":__support_macros_config",
2037+
":__support_macros_properties_complex_types",
2038+
],
2039+
)
2040+
2041+
libc_function(
2042+
name = "conjf16",
2043+
srcs = ["src/complex/generic/conjf16.cpp"],
2044+
hdrs = ["src/complex/conjf16.h"],
2045+
deps = [
2046+
":__support_common",
2047+
":__support_complex_basic_ops",
2048+
":__support_cpp_bit",
2049+
":__support_macros_config",
2050+
":__support_macros_properties_complex_types",
2051+
],
2052+
)
2053+
2054+
libc_function(
2055+
name = "conjl",
2056+
srcs = ["src/complex/generic/conjl.cpp"],
2057+
hdrs = ["src/complex/conjl.h"],
2058+
deps = [
2059+
":__support_common",
2060+
":__support_complex_basic_ops",
2061+
":__support_macros_config",
2062+
],
2063+
)
2064+
2065+
libc_function(
2066+
name = "cproj",
2067+
srcs = ["src/complex/generic/cproj.cpp"],
2068+
hdrs = ["src/complex/cproj.h"],
2069+
deps = [
2070+
":__support_common",
2071+
":__support_complex_basic_ops",
2072+
":__support_macros_config",
2073+
],
2074+
)
2075+
2076+
libc_function(
2077+
name = "cprojf",
2078+
srcs = ["src/complex/generic/cprojf.cpp"],
2079+
hdrs = ["src/complex/cprojf.h"],
2080+
deps = [
2081+
":__support_common",
2082+
":__support_complex_basic_ops",
2083+
":__support_macros_config",
2084+
],
2085+
)
2086+
2087+
libc_function(
2088+
name = "cprojf128",
2089+
srcs = ["src/complex/generic/cprojf128.cpp"],
2090+
hdrs = ["src/complex/cprojf128.h"],
2091+
deps = [
2092+
":__support_common",
2093+
":__support_complex_basic_ops",
2094+
":__support_macros_config",
2095+
":__support_macros_properties_complex_types",
2096+
],
2097+
)
2098+
2099+
libc_function(
2100+
name = "cprojf16",
2101+
srcs = ["src/complex/generic/cprojf16.cpp"],
2102+
hdrs = ["src/complex/cprojf16.h"],
2103+
deps = [
2104+
":__support_common",
2105+
":__support_complex_basic_ops",
2106+
":__support_macros_config",
2107+
":__support_macros_properties_complex_types",
2108+
],
2109+
)
2110+
2111+
libc_function(
2112+
name = "cprojl",
2113+
srcs = ["src/complex/generic/cprojl.cpp"],
2114+
hdrs = ["src/complex/cprojl.h"],
2115+
deps = [
2116+
":__support_common",
2117+
":__support_complex_basic_ops",
2118+
":__support_macros_config",
2119+
],
2120+
)
2121+
2122+
libc_function(
2123+
name = "creal",
2124+
srcs = ["src/complex/generic/creal.cpp"],
2125+
hdrs = ["src/complex/creal.h"],
2126+
deps = [
2127+
":__support_common",
2128+
":__support_complex_type",
2129+
":__support_cpp_bit",
2130+
":__support_macros_config",
2131+
],
2132+
)
2133+
2134+
libc_function(
2135+
name = "crealf",
2136+
srcs = ["src/complex/generic/crealf.cpp"],
2137+
hdrs = ["src/complex/crealf.h"],
2138+
deps = [
2139+
":__support_common",
2140+
":__support_complex_type",
2141+
":__support_cpp_bit",
2142+
":__support_macros_config",
2143+
],
2144+
)
2145+
2146+
libc_function(
2147+
name = "crealf128",
2148+
srcs = ["src/complex/generic/crealf128.cpp"],
2149+
hdrs = ["src/complex/crealf128.h"],
2150+
deps = [
2151+
":__support_common",
2152+
":__support_complex_type",
2153+
":__support_cpp_bit",
2154+
":__support_macros_config",
2155+
":__support_macros_properties_complex_types",
2156+
],
2157+
)
2158+
2159+
libc_function(
2160+
name = "crealf16",
2161+
srcs = ["src/complex/generic/crealf16.cpp"],
2162+
hdrs = ["src/complex/crealf16.h"],
2163+
deps = [
2164+
":__support_common",
2165+
":__support_complex_type",
2166+
":__support_cpp_bit",
2167+
":__support_macros_config",
2168+
":__support_macros_properties_complex_types",
2169+
],
2170+
)
2171+
2172+
libc_function(
2173+
name = "creall",
2174+
srcs = ["src/complex/generic/creall.cpp"],
2175+
hdrs = ["src/complex/creall.h"],
2176+
deps = [
2177+
":__support_common",
2178+
":__support_complex_type",
2179+
":__support_cpp_bit",
2180+
":__support_macros_config",
2181+
],
2182+
)
2183+
18932184
################################ math targets ##################################
18942185

18952186
libc_math_function(

0 commit comments

Comments
 (0)