-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathconfigure.py
More file actions
executable file
·382 lines (324 loc) · 15.6 KB
/
Copy pathconfigure.py
File metadata and controls
executable file
·382 lines (324 loc) · 15.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#!/usr/bin/env python3
#
# This file is open source software, licensed to you under the terms
# of the Apache License, Version 2.0 (the "License"). See the NOTICE file
# distributed with this work for additional information regarding copyright
# ownership. You may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
import argparse
import os
import re
import seastar_cmake
from shutil import which
import subprocess
import sys
import tempfile
tempfile.tempdir = "./build/tmp"
def add_tristate(arg_parser, name, dest, help, default=None):
arg_parser.add_argument('--enable-' + name, dest=dest, action='store_true', default=default,
help='Enable ' + help + ' [default]' if default else '')
arg_parser.add_argument('--disable-' + name, dest=dest, action='store_false', default=None,
help='Disable ' + help)
def try_compile(compiler, source='', flags=[]):
return try_compile_and_link(compiler, source, flags=flags + ['-c'])
def ensure_tmp_dir_exists():
if not os.path.exists(tempfile.tempdir):
os.makedirs(tempfile.tempdir)
def try_compile_and_link(compiler, source='', flags=[]):
ensure_tmp_dir_exists()
with tempfile.NamedTemporaryFile() as sfile:
ofd, ofile = tempfile.mkstemp()
os.close(ofd)
try:
sfile.file.write(bytes(source, 'utf-8'))
sfile.file.flush()
# We can't write to /dev/null, since in some cases (-ftest-coverage) gcc will create an auxiliary
# output file based on the name of the output file, and "/dev/null.gcsa" is not a good name
return subprocess.call([compiler, '-x', 'c++', '-o', ofile, sfile.name] + flags,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL) == 0
finally:
if os.path.exists(ofile):
os.unlink(ofile)
def standard_supported(standard, compiler='g++'):
return try_compile(compiler=compiler, source='', flags=['-std=' + standard])
def find_compiler_cache(preference):
"""
Find a compiler cache based on the preference.
Args:
preference: One of 'auto', 'sccache', 'ccache', 'none', or a path to a binary.
Returns:
Path to the compiler cache binary, or empty string if not found/disabled.
"""
if preference == 'none':
return ''
if preference == 'auto':
# Prefer sccache over ccache
for cache in ['sccache', 'ccache']:
path = which(cache)
if path:
return path
return ''
if preference in ('sccache', 'ccache'):
path = which(preference)
if path:
return path
print(f"Warning: {preference} not found on PATH, disabling compiler cache")
return ''
# Assume it's a path to a binary
if os.path.isfile(preference) and os.access(preference, os.X_OK):
return preference
print(f"Warning: compiler cache '{preference}' not found or not executable, disabling compiler cache")
return ''
def find_compiler(name):
"""
Find a compiler by name, skipping ccache wrapper directories.
This is useful when using sccache to avoid double-caching through ccache.
Args:
name: The compiler name (e.g., 'clang++', 'clang', 'gcc')
Returns:
Path to the compiler, skipping ccache directories, or None if not found.
"""
ccache_dirs = {'/usr/lib/ccache', '/usr/lib64/ccache'}
for path_dir in os.environ.get('PATH', '').split(os.pathsep):
# Skip ccache wrapper directories
if os.path.realpath(path_dir) in ccache_dirs or path_dir in ccache_dirs:
continue
candidate = os.path.join(path_dir, name)
if os.path.isfile(candidate) and os.access(candidate, os.X_OK):
return candidate
return None
def resolve_compilers_for_compiler_cache(args, compiler_cache):
"""
When using a compiler cache, resolve compiler paths to avoid ccache directories.
This prevents double-caching when ccache symlinks are in PATH.
Args:
args: The argument namespace with cc and cxx attributes.
compiler_cache: Path to the compiler cache binary, or empty string.
"""
if not compiler_cache:
return
if not os.path.isabs(args.cxx):
real_cxx = find_compiler(args.cxx)
if real_cxx:
args.cxx = real_cxx
if not os.path.isabs(args.cc):
real_cc = find_compiler(args.cc)
if real_cc:
args.cc = real_cc
arg_parser = argparse.ArgumentParser('Configure seastar')
arg_parser.add_argument('--mode', action='store', choices=seastar_cmake.SUPPORTED_MODES + ['all'], default='all')
arg_parser.add_argument('--build-root', action='store', default=seastar_cmake.DEFAULT_BUILD_ROOT, type=str,
help='The name of the build root build directoy: using a different name allows multiple '
'configurations to co-exist in the same repository')
arg_parser.add_argument('--cflags', action = 'store', dest='user_cflags', default='',
help='Extra flags for the C++ compiler')
arg_parser.add_argument('--ldflags', action='store', dest='user_ldflags', default='',
help='Extra flags for the linker')
arg_parser.add_argument('--optflags', action='store', dest='user_optflags', default='',
help='Extra optimization flags for the release mode')
arg_parser.add_argument('--api-level', action='store', dest='api_level', default='10',
help='Compatibility API level (10=latest)')
arg_parser.add_argument('--compiler', action='store', dest='cxx', default='g++',
help='C++ compiler path')
arg_parser.add_argument('--c-compiler', action='store', dest='cc', default='gcc',
help='C compiler path (for bundled libraries such as dpdk)')
arg_parser.add_argument('--compiler-cache', dest='compiler_cache', default='auto',
help="Use a compiler cache: 'auto' (prefer sccache over ccache), 'sccache', 'ccache', 'none' to disable, or a path to a compiler cache binary")
arg_parser.add_argument('--c++-standard', action='store', dest='cpp_standard', default='',
help='C++ standard to build with')
arg_parser.add_argument('--cook', action='append', dest='cook', default=[],
help='Supply this dependency locally for development via `cmake-cooking` (can be repeated)')
arg_parser.add_argument('--verbose', dest='verbose', action='store_true', help='Make configure output more verbose.')
arg_parser.add_argument('--scheduling-groups-count', action='store', dest='scheduling_groups_count', default='16',
help='Number of available scheduling groups in the reactor')
add_tristate(
arg_parser,
name='dpdk',
dest='dpdk',
help='DPDK support')
add_tristate(
arg_parser,
name='cxx-modules',
dest='cxx_modules',
help='build as C++20 module')
add_tristate(
arg_parser,
name='hwloc',
dest='hwloc',
help='hwloc support')
add_tristate(
arg_parser,
name='alloc-failure-injector',
dest='alloc_failure_injection',
help='allocation failure injection')
add_tristate(
arg_parser,
name='task-backtrace',
dest='task_backtrace',
help='Collect backtrace at deferring points')
add_tristate(
arg_parser,
name='unused-result-error',
dest="unused_result_error",
help='Make [[nodiscard]] violations an error')
add_tristate(
arg_parser,
name='debug-shared-ptr',
dest="debug_shared_ptr",
help='Debug shared_ptr')
add_tristate(
arg_parser,
name='io_uring',
dest='io_uring',
help='Support io_uring via liburing')
add_tristate(
arg_parser,
name='gnutls',
dest='gnutls',
help='the GnuTLS TLS/crypto backend')
add_tristate(
arg_parser,
name='openssl',
dest='openssl',
help='the OpenSSL TLS/crypto backend')
add_tristate(
arg_parser,
name='lttng',
dest='lttng',
help='LTTng-UST tracepoint support for IO tracing')
arg_parser.add_argument('--allocator-page-size', dest='alloc_page_size', type=int, help='override allocator page size')
arg_parser.add_argument('--without-tests', dest='exclude_tests', action='store_true', help='Do not build tests by default')
arg_parser.add_argument('--without-apps', dest='exclude_apps', action='store_true', help='Do not build applications by default')
arg_parser.add_argument('--without-demos', dest='exclude_demos', action='store_true', help='Do not build demonstrations by default')
arg_parser.add_argument('--split-dwarf', dest='split_dwarf', action='store_true', default=False,
help='use of split dwarf (https://gcc.gnu.org/wiki/DebugFission) to speed up linking')
arg_parser.add_argument('--compile-commands-json', dest='cc_json', action='store_true',
help='Generate a compile_commands.json file for integration with clangd and other tools.')
arg_parser.add_argument('--heap-profiling', dest='heap_profiling', action='store_true', default=False, help='Enable heap profiling')
arg_parser.add_argument('--dpdk-machine', default='native', help='Specify the target architecture')
add_tristate(arg_parser, name='deferred-action-require-noexcept', dest='deferred_action_require_noexcept', help='noexcept requirement for deferred actions', default=True)
arg_parser.add_argument('--prefix', dest='install_prefix', default='/usr/local', help='Root installation path of Seastar files')
args = arg_parser.parse_args()
def identify_best_standard(cpp_standards, compiler):
"""Returns the first C++ standard accepted by the compiler in the sequence,
assuming the "best" standards appear first.
If no standards are accepted, we fail configure.py. There is not point
of letting the user attempt to build with a standard that is known not
to be supported.
"""
for std in cpp_standards:
if standard_supported('c++{}'.format(std), compiler):
return std
raise Exception(f"{compiler} does not seem to support any of Seastar's preferred C++ standards - {cpp_standards}. Please upgrade your compiler.")
if not args.cpp_standard:
cpp_standards = ['26', '23']
args.cpp_standard = identify_best_standard(cpp_standards, compiler=args.cxx)
# Resolve compiler cache
compiler_cache = find_compiler_cache(args.compiler_cache)
resolve_compilers_for_compiler_cache(args, compiler_cache)
MODES = seastar_cmake.SUPPORTED_MODES if args.mode == 'all' else [args.mode]
# For convenience.
tr = seastar_cmake.translate_arg
MODE_TO_CMAKE_BUILD_TYPE = {'release': 'RelWithDebInfo', 'debug': 'Debug', 'dev': 'Dev', 'sanitize': 'Sanitize', 'fuzz': 'Fuzz'}
def get_valid_ingredients():
"""Extract valid ingredient names from cooking_recipe.cmake."""
recipe_path = os.path.join(seastar_cmake.ROOT_PATH, 'cooking_recipe.cmake')
with open(recipe_path, 'r') as f:
content = f.read()
# Match cooking_ingredient(name or cooking_ingredient (name
matches = re.findall(r'cooking_ingredient\s*\(\s*([\w-]+)', content)
return set(matches)
def configure_mode(mode):
BUILD_PATH = seastar_cmake.build_path(mode, build_root=args.build_root)
CFLAGS = seastar_cmake.convert_strings_to_cmake_list(
args.user_cflags,
args.user_optflags if seastar_cmake.is_release_mode(mode) else '')
LDFLAGS = seastar_cmake.convert_strings_to_cmake_list(args.user_ldflags)
TRANSLATED_ARGS = [
'-DCMAKE_BUILD_TYPE={}'.format(MODE_TO_CMAKE_BUILD_TYPE[mode]),
'-DCMAKE_CXX_COMPILER={}'.format(args.cxx),
'-DCMAKE_CXX_STANDARD={}'.format(args.cpp_standard),
'-DCMAKE_CXX_COMPILER_LAUNCHER={}'.format(compiler_cache),
'-DCMAKE_INSTALL_PREFIX={}'.format(args.install_prefix),
'-DCMAKE_EXPORT_COMPILE_COMMANDS={}'.format('yes' if args.cc_json else 'no'),
'-DBUILD_SHARED_LIBS={}'.format('yes' if mode in ('debug', 'dev') else 'no'),
'-DSeastar_API_LEVEL={}'.format(args.api_level),
'-DSeastar_SCHEDULING_GROUPS_COUNT={}'.format(args.scheduling_groups_count),
tr(args.exclude_tests, 'EXCLUDE_TESTS_FROM_ALL'),
tr(args.exclude_apps, 'EXCLUDE_APPS_FROM_ALL'),
tr(args.exclude_demos, 'EXCLUDE_DEMOS_FROM_ALL'),
tr(CFLAGS, 'CXX_FLAGS'),
tr(LDFLAGS, 'LD_FLAGS'),
tr(args.cxx_modules, 'MODULE'),
tr(args.dpdk, 'DPDK'),
tr(args.dpdk_machine, 'DPDK_MACHINE'),
tr(args.hwloc, 'HWLOC', value_when_none='yes'),
tr(args.io_uring, 'IO_URING', value_when_none=None),
tr(args.gnutls, 'GNUTLS', value_when_none=None),
tr(args.openssl, 'OPENSSL', value_when_none=None),
tr(args.lttng, 'LTTNG', value_when_none='yes'),
tr(args.alloc_failure_injection, 'ALLOC_FAILURE_INJECTION', value_when_none='DEFAULT'),
tr(args.task_backtrace, 'TASK_BACKTRACE'),
tr(args.alloc_page_size, 'ALLOC_PAGE_SIZE'),
tr(args.split_dwarf, 'SPLIT_DWARF'),
tr(args.heap_profiling, 'HEAP_PROFILING'),
tr(args.deferred_action_require_noexcept, 'DEFERRED_ACTION_REQUIRE_NOEXCEPT'),
tr(args.unused_result_error, 'UNUSED_RESULT_ERROR'),
tr(args.debug_shared_ptr, 'DEBUG_SHARED_PTR', value_when_none='default'),
]
if not which('ninja-build') and which('ninja'):
TRANSLATED_ARGS.append('-DCMAKE_MAKE_PROGRAM=ninja')
ingredients_to_cook = set(args.cook)
if ingredients_to_cook:
valid_ingredients = get_valid_ingredients()
invalid = ingredients_to_cook - valid_ingredients
if invalid:
print(f"error: unknown ingredient(s): {', '.join(sorted(invalid))}")
print(f"valid ingredients: {', '.join(sorted(valid_ingredients))}")
sys.exit(1)
if args.dpdk:
ingredients_to_cook.add('dpdk')
# Generate a new build by pointing to the source directory.
if ingredients_to_cook:
# the C compiler is only used when building ingredients.
TRANSLATED_ARGS.append(f'-DCMAKE_C_COMPILER={args.cc}')
# We need to use cmake-cooking for some dependencies.
inclusion_arguments = []
for ingredient in ingredients_to_cook:
inclusion_arguments.extend(['-i', ingredient])
ARGS = seastar_cmake.COOKING_BASIC_ARGS + inclusion_arguments
if args.user_cflags:
ARGS += ['-s', f'CXXFLAGS={args.user_cflags}']
if args.user_ldflags:
ARGS += ['-s', f'LDFLAGS={args.user_ldflags}']
ARGS += ['-d', BUILD_PATH, '--']
dir = seastar_cmake.ROOT_PATH
else:
# When building without cooked dependencies, we can invoke cmake directly. We can't call
# cooking.sh, because without any -i parameters, it will try to build
# everything.
root_relative_to_build = os.path.relpath(seastar_cmake.ROOT_PATH, BUILD_PATH)
ARGS = ['cmake', '-G', 'Ninja', root_relative_to_build]
dir = BUILD_PATH
# filter out empty args, their values are actually "guess",
# CMake should be able to figure it out.
ARGS += filter(lambda arg: arg, TRANSLATED_ARGS)
if args.verbose:
print("Running CMake in '{}' ...".format(dir))
print(" \\\n ".join(ARGS))
os.makedirs(BUILD_PATH, exist_ok=True)
subprocess.check_call(ARGS, shell=False, cwd=dir)
for mode in MODES:
configure_mode(mode)