]>
git.proxmox.com Git - ceph.git/blob - 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
9 # http://www.apache.org/licenses/LICENSE-2.0
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
20 from ..utils
.cmake
import CMakeDefinition
23 def truthifier(value
):
24 return "ON" if value
else "OFF"
27 def or_else(value
, default
):
28 return value
if value
else default
31 def coalesce(value
, fallback
):
32 return fallback
if value
is None else value
38 class CppConfiguration
:
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,
47 with_tests
=None, with_benchmarks
=None, with_examples
=None,
48 with_integration
=None,
50 use_asan
=None, use_tsan
=None, use_ubsan
=None,
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,
58 with_parquet
=None, with_plasma
=None, with_python
=True,
59 with_r
=None, with_s3
=None,
61 with_brotli
=None, with_bz2
=None, with_lz4
=None,
62 with_snappy
=None, with_zlib
=None, with_zstd
=None,
70 self
.cxx_flags
= cxx_flags
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
81 self
.with_tests
= with_tests
82 self
.with_benchmarks
= with_benchmarks
83 self
.with_examples
= with_examples
84 self
.with_integration
= with_integration
86 self
.use_asan
= use_asan
87 self
.use_tsan
= use_tsan
88 self
.use_ubsan
= use_ubsan
89 self
.with_fuzzing
= with_fuzzing
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
108 self
.with_s3
= with_s3
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
117 self
.with_lint_only
= with_lint_only
118 self
.use_gold_linker
= use_gold_linker
119 self
.simd_level
= simd_level
121 self
.cmake_extras
= cmake_extras
123 # Fixup required dependencies by providing sane defaults if the caller
124 # didn't specify the option.
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)
134 self
.with_zlib
= coalesce(with_zlib
, True)
135 self
.with_lz4
= coalesce(with_lz4
, True)
137 if self
.with_dataset
:
138 self
.with_filesystem
= coalesce(with_filesystem
, True)
139 self
.with_parquet
= coalesce(with_parquet
, True)
141 if self
.with_parquet
:
142 self
.with_snappy
= coalesce(with_snappy
, True)
145 def build_type(self
):
147 return self
._build
_type
149 if self
.with_fuzzing
:
150 return "relwithdebinfo"
159 if self
.with_fuzzing
:
160 return "clang-{}".format(LLVM_VERSION
)
169 if self
.with_fuzzing
:
170 return "clang++-{}".format(LLVM_VERSION
)
176 yield ("ARROW_CXXFLAGS", self
.cxx_flags
)
178 yield ("CMAKE_EXPORT_COMPILE_COMMANDS", truthifier(True))
179 yield ("CMAKE_BUILD_TYPE", self
.build_type
)
181 if not self
.with_lint_only
:
182 yield ("BUILD_WARNING_LEVEL",
183 or_else(self
.warn_level
, "production"))
186 # yield ("ARROW_VERBOSE_THIRDPARTY_BUILD", "ON")
188 maybe_prefix
= self
.install_prefix
190 yield ("CMAKE_INSTALL_PREFIX", maybe_prefix
)
192 if self
._package
_prefix
is not None:
193 yield ("ARROW_DEPENDENCY_SOURCE", "SYSTEM")
194 yield ("ARROW_PACKAGE_PREFIX", self
._package
_prefix
)
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
))
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
))
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
))
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
))
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
))
239 yield ("ARROW_LINT_ONLY", truthifier(self
.with_lint_only
))
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"))
247 # Detect custom conda toolchain
249 for d
, v
in [('CMAKE_AR', 'AR'), ('CMAKE_RANLIB', 'RANLIB')]:
250 v
= os
.environ
.get(v
)
255 def install_prefix(self
):
256 if self
._install
_prefix
:
257 return self
._install
_prefix
260 return os
.environ
.get("CONDA_PREFIX")
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
270 return self
._use
_conda
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
279 def environment(self
):
280 env
= os
.environ
.copy()
286 env
["CXX"] = self
.cxx
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
)