]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/dev/archery/archery/lang/cpp.py
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / dev / archery / archery / lang / cpp.py
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17
18 import os
19
20 from ..utils.cmake import CMakeDefinition
21
22
23 def truthifier(value):
24 return "ON" if value else "OFF"
25
26
27 def or_else(value, default):
28 return value if value else default
29
30
31 def coalesce(value, fallback):
32 return fallback if value is None else value
33
34
35 LLVM_VERSION = 7
36
37
38 class CppConfiguration:
39 def __init__(self,
40
41 # toolchain
42 cc=None, cxx=None, cxx_flags=None,
43 build_type=None, warn_level=None,
44 cpp_package_prefix=None, install_prefix=None, use_conda=None,
45 build_static=False, build_shared=True, build_unity=True,
46 # tests & examples
47 with_tests=None, with_benchmarks=None, with_examples=None,
48 with_integration=None,
49 # static checks
50 use_asan=None, use_tsan=None, use_ubsan=None,
51 with_fuzzing=None,
52 # Components
53 with_compute=None, with_csv=None, with_cuda=None,
54 with_dataset=None, with_filesystem=None, with_flight=None,
55 with_gandiva=None, with_hdfs=None, with_hiveserver2=None,
56 with_ipc=True, with_json=None, with_jni=None,
57 with_mimalloc=None,
58 with_parquet=None, with_plasma=None, with_python=True,
59 with_r=None, with_s3=None,
60 # Compressions
61 with_brotli=None, with_bz2=None, with_lz4=None,
62 with_snappy=None, with_zlib=None, with_zstd=None,
63 # extras
64 with_lint_only=False,
65 use_gold_linker=True,
66 simd_level="SSE4_2",
67 cmake_extras=None):
68 self._cc = cc
69 self._cxx = cxx
70 self.cxx_flags = cxx_flags
71
72 self._build_type = build_type
73 self.warn_level = warn_level
74 self._install_prefix = install_prefix
75 self._package_prefix = cpp_package_prefix
76 self._use_conda = use_conda
77 self.build_static = build_static
78 self.build_shared = build_shared
79 self.build_unity = build_unity
80
81 self.with_tests = with_tests
82 self.with_benchmarks = with_benchmarks
83 self.with_examples = with_examples
84 self.with_integration = with_integration
85
86 self.use_asan = use_asan
87 self.use_tsan = use_tsan
88 self.use_ubsan = use_ubsan
89 self.with_fuzzing = with_fuzzing
90
91 self.with_compute = with_compute
92 self.with_csv = with_csv
93 self.with_cuda = with_cuda
94 self.with_dataset = with_dataset
95 self.with_filesystem = with_filesystem
96 self.with_flight = with_flight
97 self.with_gandiva = with_gandiva
98 self.with_hdfs = with_hdfs
99 self.with_hiveserver2 = with_hiveserver2
100 self.with_ipc = with_ipc
101 self.with_json = with_json
102 self.with_jni = with_jni
103 self.with_mimalloc = with_mimalloc
104 self.with_parquet = with_parquet
105 self.with_plasma = with_plasma
106 self.with_python = with_python
107 self.with_r = with_r
108 self.with_s3 = with_s3
109
110 self.with_brotli = with_brotli
111 self.with_bz2 = with_bz2
112 self.with_lz4 = with_lz4
113 self.with_snappy = with_snappy
114 self.with_zlib = with_zlib
115 self.with_zstd = with_zstd
116
117 self.with_lint_only = with_lint_only
118 self.use_gold_linker = use_gold_linker
119 self.simd_level = simd_level
120
121 self.cmake_extras = cmake_extras
122
123 # Fixup required dependencies by providing sane defaults if the caller
124 # didn't specify the option.
125 if self.with_r:
126 self.with_csv = coalesce(with_csv, True)
127 self.with_dataset = coalesce(with_dataset, True)
128 self.with_filesystem = coalesce(with_filesystem, True)
129 self.with_ipc = coalesce(with_ipc, True)
130 self.with_json = coalesce(with_json, True)
131 self.with_parquet = coalesce(with_parquet, True)
132
133 if self.with_python:
134 self.with_zlib = coalesce(with_zlib, True)
135 self.with_lz4 = coalesce(with_lz4, True)
136
137 if self.with_dataset:
138 self.with_filesystem = coalesce(with_filesystem, True)
139 self.with_parquet = coalesce(with_parquet, True)
140
141 if self.with_parquet:
142 self.with_snappy = coalesce(with_snappy, True)
143
144 @property
145 def build_type(self):
146 if self._build_type:
147 return self._build_type
148
149 if self.with_fuzzing:
150 return "relwithdebinfo"
151
152 return "release"
153
154 @property
155 def cc(self):
156 if self._cc:
157 return self._cc
158
159 if self.with_fuzzing:
160 return "clang-{}".format(LLVM_VERSION)
161
162 return None
163
164 @property
165 def cxx(self):
166 if self._cxx:
167 return self._cxx
168
169 if self.with_fuzzing:
170 return "clang++-{}".format(LLVM_VERSION)
171
172 return None
173
174 def _gen_defs(self):
175 if self.cxx_flags:
176 yield ("ARROW_CXXFLAGS", self.cxx_flags)
177
178 yield ("CMAKE_EXPORT_COMPILE_COMMANDS", truthifier(True))
179 yield ("CMAKE_BUILD_TYPE", self.build_type)
180
181 if not self.with_lint_only:
182 yield ("BUILD_WARNING_LEVEL",
183 or_else(self.warn_level, "production"))
184
185 # if not ctx.quiet:
186 # yield ("ARROW_VERBOSE_THIRDPARTY_BUILD", "ON")
187
188 maybe_prefix = self.install_prefix
189 if maybe_prefix:
190 yield ("CMAKE_INSTALL_PREFIX", maybe_prefix)
191
192 if self._package_prefix is not None:
193 yield ("ARROW_DEPENDENCY_SOURCE", "SYSTEM")
194 yield ("ARROW_PACKAGE_PREFIX", self._package_prefix)
195
196 yield ("ARROW_BUILD_STATIC", truthifier(self.build_static))
197 yield ("ARROW_BUILD_SHARED", truthifier(self.build_shared))
198 yield ("CMAKE_UNITY_BUILD", truthifier(self.build_unity))
199
200 # Tests and benchmarks
201 yield ("ARROW_BUILD_TESTS", truthifier(self.with_tests))
202 yield ("ARROW_BUILD_BENCHMARKS", truthifier(self.with_benchmarks))
203 yield ("ARROW_BUILD_EXAMPLES", truthifier(self.with_examples))
204 yield ("ARROW_BUILD_INTEGRATION", truthifier(self.with_integration))
205
206 # Static checks
207 yield ("ARROW_USE_ASAN", truthifier(self.use_asan))
208 yield ("ARROW_USE_TSAN", truthifier(self.use_tsan))
209 yield ("ARROW_USE_UBSAN", truthifier(self.use_ubsan))
210 yield ("ARROW_FUZZING", truthifier(self.with_fuzzing))
211
212 # Components
213 yield ("ARROW_COMPUTE", truthifier(self.with_compute))
214 yield ("ARROW_CSV", truthifier(self.with_csv))
215 yield ("ARROW_CUDA", truthifier(self.with_cuda))
216 yield ("ARROW_DATASET", truthifier(self.with_dataset))
217 yield ("ARROW_FILESYSTEM", truthifier(self.with_filesystem))
218 yield ("ARROW_FLIGHT", truthifier(self.with_flight))
219 yield ("ARROW_GANDIVA", truthifier(self.with_gandiva))
220 yield ("ARROW_PARQUET", truthifier(self.with_parquet))
221 yield ("ARROW_HDFS", truthifier(self.with_hdfs))
222 yield ("ARROW_HIVESERVER2", truthifier(self.with_hiveserver2))
223 yield ("ARROW_IPC", truthifier(self.with_ipc))
224 yield ("ARROW_JSON", truthifier(self.with_json))
225 yield ("ARROW_JNI", truthifier(self.with_jni))
226 yield ("ARROW_MIMALLOC", truthifier(self.with_mimalloc))
227 yield ("ARROW_PLASMA", truthifier(self.with_plasma))
228 yield ("ARROW_PYTHON", truthifier(self.with_python))
229 yield ("ARROW_S3", truthifier(self.with_s3))
230
231 # Compressions
232 yield ("ARROW_WITH_BROTLI", truthifier(self.with_brotli))
233 yield ("ARROW_WITH_BZ2", truthifier(self.with_bz2))
234 yield ("ARROW_WITH_LZ4", truthifier(self.with_lz4))
235 yield ("ARROW_WITH_SNAPPY", truthifier(self.with_snappy))
236 yield ("ARROW_WITH_ZLIB", truthifier(self.with_zlib))
237 yield ("ARROW_WITH_ZSTD", truthifier(self.with_zstd))
238
239 yield ("ARROW_LINT_ONLY", truthifier(self.with_lint_only))
240
241 # Some configurations don't like gnu gold linker.
242 broken_with_gold_ld = [self.with_fuzzing, self.with_gandiva]
243 if self.use_gold_linker and not any(broken_with_gold_ld):
244 yield ("ARROW_USE_LD_GOLD", truthifier(self.use_gold_linker))
245 yield ("ARROW_SIMD_LEVEL", or_else(self.simd_level, "SSE4_2"))
246
247 # Detect custom conda toolchain
248 if self.use_conda:
249 for d, v in [('CMAKE_AR', 'AR'), ('CMAKE_RANLIB', 'RANLIB')]:
250 v = os.environ.get(v)
251 if v:
252 yield (d, v)
253
254 @property
255 def install_prefix(self):
256 if self._install_prefix:
257 return self._install_prefix
258
259 if self.use_conda:
260 return os.environ.get("CONDA_PREFIX")
261
262 return None
263
264 @property
265 def use_conda(self):
266 # If the user didn't specify a preference, guess via environment
267 if self._use_conda is None:
268 return os.environ.get("CONDA_PREFIX") is not None
269
270 return self._use_conda
271
272 @property
273 def definitions(self):
274 extras = list(self.cmake_extras) if self.cmake_extras else []
275 definitions = ["-D{}={}".format(d[0], d[1]) for d in self._gen_defs()]
276 return definitions + extras
277
278 @property
279 def environment(self):
280 env = os.environ.copy()
281
282 if self.cc:
283 env["CC"] = self.cc
284
285 if self.cxx:
286 env["CXX"] = self.cxx
287
288 return env
289
290
291 class CppCMakeDefinition(CMakeDefinition):
292 def __init__(self, source, conf, **kwargs):
293 self.configuration = conf
294 super().__init__(source, **kwargs,
295 definitions=conf.definitions, env=conf.environment,
296 build_type=conf.build_type)