-
Notifications
You must be signed in to change notification settings - Fork 289
/
conanfile.py
735 lines (658 loc) · 24 KB
/
conanfile.py
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
# pylint: disable=no-member
import os
import platform
import re
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.cmake import CMake
from conan.tools.cmake import cmake_layout
from conan.tools.cmake import CMakeDeps
from conan.tools.cmake import CMakeToolchain
from conan.tools.files import copy
from conan.tools.files import load
required_conan_version = '>=2.8.0' # pylint: disable=invalid-name
class UserverConan(ConanFile):
name = 'userver'
description = 'The C++ Asynchronous Framework'
topics = ('framework', 'coroutines', 'asynchronous')
url = 'https://github.com/userver-framework/userver'
homepage = 'https://userver.tech/'
license = 'Apache-2.0'
package_type = 'static-library'
exports_sources = '*'
settings = 'os', 'arch', 'compiler', 'build_type'
options = {
'fPIC': [True, False],
'lto': [True, False],
'with_jemalloc': [True, False],
'with_mongodb': [True, False],
'with_postgresql': [True, False],
'with_postgresql_extra': [True, False],
'with_redis': [True, False],
'with_grpc': [True, False],
'with_clickhouse': [True, False],
'with_rabbitmq': [True, False],
'with_utest': [True, False],
'with_kafka': [True, False],
'with_otlp': [True, False],
'namespace': ['ANY'],
'namespace_begin': ['ANY'],
'namespace_end': ['ANY'],
'python_path': ['ANY'],
}
default_options = {
'fPIC': True,
'lto': False,
'with_jemalloc': (platform.system() != 'Darwin'),
'with_mongodb': True,
'with_postgresql': True,
'with_postgresql_extra': False,
'with_redis': True,
'with_grpc': True,
'with_clickhouse': True,
'with_rabbitmq': True,
'with_utest': True,
'with_kafka': True,
'with_otlp': True,
'namespace': 'userver',
'namespace_begin': 'namespace userver {',
'namespace_end': '}',
'python_path': 'python3',
'mongo-c-driver/*:with_sasl': 'cyrus',
'grpc/*:php_plugin': False,
'grpc/*:node_plugin': False,
'grpc/*:ruby_plugin': False,
'grpc/*:csharp_plugin': False,
'grpc/*:objective_c_plugin': False,
}
# scm = {
# 'type': 'git',
# 'url': 'https://github.com/userver-framework/userver.git',
# 'revision': 'develop'
# }
def set_version(self):
content = load(
self,
os.path.join(
os.path.dirname(os.path.realpath(__file__)),
'cmake/GetUserverVersion.cmake',
),
)
major_version = (
re.search(r'set\(USERVER_MAJOR_VERSION (.*)\)', content)
.group(1)
.strip()
)
minor_version = (
re.search(r'set\(USERVER_MINOR_VERSION (.*)\)', content)
.group(1)
.strip()
)
self.version = f'{major_version}.{minor_version}'
@property
def _source_subfolder(self):
return 'source'
@property
def _build_subfolder(self):
return os.path.join(self.build_folder)
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires('boost/1.86.0', transitive_headers=True)
self.requires('c-ares/1.33.1')
self.requires('cctz/2.4', transitive_headers=True)
self.requires('concurrentqueue/1.0.3', transitive_headers=True)
self.requires('cryptopp/8.9.0')
self.requires('fmt/8.1.1', transitive_headers=True)
self.requires('libiconv/1.17')
self.requires('libnghttp2/1.61.0')
self.requires('libcurl/7.86.0')
self.requires('libev/4.33')
self.requires('openssl/3.3.2')
self.requires('rapidjson/cci.20220822', transitive_headers=True)
self.requires('yaml-cpp/0.8.0')
self.requires('zlib/1.3.1')
self.requires('zstd/1.5.5')
if self.options.with_jemalloc:
self.requires('jemalloc/5.3.0')
if self.options.with_grpc or self.options.with_clickhouse:
self.requires('abseil/20240116.2', force=True)
if self.options.with_grpc:
self.requires(
'grpc/1.65.0', transitive_headers=True, transitive_libs=True,
)
self.requires(
'protobuf/5.27.0',
transitive_headers=True,
transitive_libs=True,
)
if self.options.with_postgresql:
self.requires('libpq/14.5')
if self.options.with_mongodb or self.options.with_kafka:
self.requires('cyrus-sasl/2.1.28')
if self.options.with_mongodb:
self.requires(
'mongo-c-driver/1.28.0',
transitive_headers=True,
transitive_libs=True,
)
if self.options.with_redis:
self.requires('hiredis/1.2.0')
if self.options.with_rabbitmq:
self.requires('amqp-cpp/4.3.26')
if self.options.with_clickhouse:
self.requires('clickhouse-cpp/2.5.1')
if self.options.with_utest:
self.requires(
'gtest/1.15.0', transitive_headers=True, transitive_libs=True,
)
self.requires(
'benchmark/1.9.0',
transitive_headers=True,
transitive_libs=True,
)
if self.options.with_kafka:
self.requires('librdkafka/2.6.0')
def build_requirements(self):
self.tool_requires('protobuf/5.27.0')
def validate(self):
if self.settings.os == 'Windows':
raise ConanInvalidConfiguration(
'userver cannot be built on Windows',
)
if (
self.options.with_mongodb
and self.dependencies['mongo-c-driver'].options.with_sasl
!= 'cyrus'
):
raise ConanInvalidConfiguration(
f'{self.ref} requires mongo-c-driver with_sasl cyrus',
)
def generate(self):
tool_ch = CMakeToolchain(self)
tool_ch.variables['CMAKE_FIND_DEBUG_MODE'] = False
tool_ch.variables['USERVER_CONAN'] = True
tool_ch.variables['USERVER_DOWNLOAD_PACKAGES'] = True
tool_ch.variables['USERVER_FEATURE_DWCAS'] = True
tool_ch.variables['USERVER_NAMESPACE'] = self.options.namespace
tool_ch.variables['USERVER_NAMESPACE_BEGIN'] = (
self.options.namespace_begin
)
tool_ch.variables['USERVER_NAMESPACE_END'] = self.options.namespace_end
tool_ch.variables['USERVER_PYTHON_PATH'] = self.options.python_path
tool_ch.variables['USERVER_LTO'] = self.options.lto
tool_ch.variables['USERVER_FEATURE_JEMALLOC'] = (
self.options.with_jemalloc
)
tool_ch.variables['USERVER_FEATURE_MONGODB'] = (
self.options.with_mongodb
)
tool_ch.variables['USERVER_FEATURE_POSTGRESQL'] = (
self.options.with_postgresql
)
tool_ch.variables['USERVER_FEATURE_PATCH_LIBPQ'] = (
self.options.with_postgresql_extra
)
tool_ch.variables['USERVER_FEATURE_REDIS'] = self.options.with_redis
tool_ch.variables['USERVER_FEATURE_GRPC'] = self.options.with_grpc
tool_ch.variables['USERVER_FEATURE_CLICKHOUSE'] = (
self.options.with_clickhouse
)
tool_ch.variables['USERVER_FEATURE_RABBITMQ'] = (
self.options.with_rabbitmq
)
tool_ch.variables['USERVER_FEATURE_UTEST'] = self.options.with_utest
tool_ch.variables['USERVER_FEATURE_TESTSUITE'] = (
self.options.with_utest
)
tool_ch.variables['USERVER_FEATURE_KAFKA'] = self.options.with_kafka
tool_ch.variables['USERVER_FEATURE_OTLP'] = self.options.with_otlp
tool_ch.generate()
CMakeDeps(self).generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
@property
def _cmake_subfolder(self):
return os.path.join(self.package_folder, 'cmake')
def package(self):
copy(self, pattern='LICENSE', src=self.source_folder, dst='licenses')
copy(
self,
pattern='*',
dst=os.path.join(self.package_folder, 'scripts'),
src=os.path.join(self.source_folder, 'scripts'),
keep_path=True,
)
copy(
self,
pattern='*',
dst=os.path.join(
self.package_folder, 'include', 'function_backports',
),
src=os.path.join(
self.source_folder,
'third_party',
'function_backports',
'include',
),
keep_path=True,
)
def copy_component(component):
copy(
self,
pattern='*',
dst=os.path.join(self.package_folder, 'include', component),
src=os.path.join(self.source_folder, component, 'include'),
keep_path=True,
)
copy(
self,
pattern='*.a',
dst=os.path.join(self.package_folder, 'lib'),
src=os.path.join(self._build_subfolder, component),
keep_path=False,
)
copy_component('core')
copy_component('universal')
for cmake_file in (
'UserverSetupEnvironment',
'SetupLinker',
'SetupLTO',
'SetupPGO',
'UserverVenv',
):
copy(
self,
pattern=f'{cmake_file}.cmake',
dst=os.path.join(self.package_folder, 'cmake'),
src=os.path.join(self.source_folder, 'cmake'),
keep_path=True,
)
if self.options.with_grpc:
copy_component('grpc')
copy(
self,
pattern='*',
dst=os.path.join(self.package_folder, 'include', 'grpc'),
src=os.path.join(
self.source_folder, 'grpc', 'handlers', 'include',
),
keep_path=True,
)
copy(
self,
pattern='*pb.h',
dst=os.path.join(self.package_folder, 'include'),
src=os.path.join(self._build_subfolder, 'grpc', 'proto'),
keep_path=True,
)
copy(
self,
pattern='UserverGrpcTargets.cmake',
dst=os.path.join(self.package_folder, 'cmake'),
src=os.path.join(self.source_folder, 'cmake'),
keep_path=True,
)
with open(
os.path.join(self.package_folder, 'cmake', 'GrpcConan.cmake'),
'a+',
) as grpc_file:
grpc_file.write('\nset(USERVER_CONAN TRUE)')
if self.options.with_utest:
copy(
self,
pattern='*',
dst=os.path.join(self.package_folder, 'include', 'utest'),
src=os.path.join(
self.source_folder, 'universal', 'utest', 'include',
),
keep_path=True,
)
copy(
self,
pattern='*',
dst=os.path.join(self.package_folder, 'include', 'utest'),
src=os.path.join(
self.source_folder, 'core', 'utest', 'include',
),
keep_path=True,
)
copy(
self,
pattern='*',
dst=os.path.join(self.package_folder, 'testsuite'),
src=os.path.join(self.source_folder, 'testsuite'),
keep_path=True,
)
copy(
self,
pattern='AddGoogleTests.cmake',
dst=os.path.join(self.package_folder, 'cmake'),
src=os.path.join(self.source_folder, 'cmake'),
keep_path=True,
)
if self.options.with_grpc or self.options.with_utest:
copy(
self,
pattern='UserverTestsuite.cmake',
dst=os.path.join(self.package_folder, 'cmake'),
src=os.path.join(self.source_folder, 'cmake'),
keep_path=True,
)
copy(
self,
pattern='SetupProtobuf.cmake',
dst=os.path.join(self.package_folder, 'cmake'),
src=os.path.join(self.source_folder, 'cmake'),
keep_path=True,
)
if self.options.with_postgresql:
copy_component('postgresql')
if self.options.with_mongodb:
copy_component('mongo')
if self.options.with_redis:
copy_component('redis')
if self.options.with_rabbitmq:
copy_component('rabbitmq')
if self.options.with_clickhouse:
copy_component('clickhouse')
if self.options.with_kafka:
copy_component('kafka')
if self.options.with_otlp:
copy_component('otlp')
@property
def _userver_components(self):
def abseil():
return ['abseil::abseil']
def ares():
return ['c-ares::c-ares']
def fmt():
return ['fmt::fmt']
def curl():
return ['libcurl::libcurl']
def cryptopp():
return ['cryptopp::cryptopp']
def cctz():
return ['cctz::cctz']
def boost():
return ['boost::boost']
def concurrentqueue():
return ['concurrentqueue::concurrentqueue']
def yaml():
return ['yaml-cpp::yaml-cpp']
def iconv():
return ['libiconv::libiconv']
def libev():
return ['libev::libev']
def libnghttp2():
return ['libnghttp2::libnghttp2']
def openssl():
return ['openssl::openssl']
def rapidjson():
return ['rapidjson::rapidjson']
def zlib():
return ['zlib::zlib']
def zstd():
# According to https://conan.io/center/recipes/zstd should be
# zstd::libzstd_static, but it does not work that way
return ['zstd::zstd']
def jemalloc():
return ['jemalloc::jemalloc'] if self.options.with_jemalloc else []
def grpc():
return ['grpc::grpc'] if self.options.with_grpc else []
def protobuf():
return ['protobuf::protobuf'] if self.options.with_grpc else []
def postgresql():
return ['libpq::pq'] if self.options.with_postgresql else []
def gtest():
return ['gtest::gtest'] if self.options.with_utest else []
def benchmark():
return ['benchmark::benchmark'] if self.options.with_utest else []
def mongo():
return (
['mongo-c-driver::mongo-c-driver']
if self.options.with_mongodb
else []
)
def cyrussasl():
return (
['cyrus-sasl::cyrus-sasl']
if self.options.with_mongodb or self.options.with_kafka
else []
)
def hiredis():
return ['hiredis::hiredis'] if self.options.with_redis else []
def amqpcpp():
return ['amqp-cpp::amqp-cpp'] if self.options.with_rabbitmq else []
def clickhouse():
return (
['clickhouse-cpp::clickhouse-cpp']
if self.options.with_clickhouse
else []
)
def librdkafka():
return (
['librdkafka::librdkafka'] if self.options.with_kafka else []
)
userver_components = [
{
'target': 'core',
'lib': 'core',
'requires': (
['universal']
+ fmt()
+ cctz()
+ boost()
+ concurrentqueue()
+ yaml()
+ iconv()
+ libev()
+ libnghttp2()
+ curl()
+ cryptopp()
+ jemalloc()
+ ares()
+ rapidjson()
+ zlib()
),
},
]
userver_components.extend([
{
'target': 'universal',
'lib': 'universal',
'requires': (
fmt()
+ cctz()
+ boost()
+ concurrentqueue()
+ yaml()
+ cryptopp()
+ jemalloc()
+ openssl()
+ zstd()
),
},
])
if self.options.with_grpc:
userver_components.extend([
{
'target': 'grpc',
'lib': 'grpc',
'requires': (['core'] + abseil() + grpc() + protobuf()),
},
{
'target': 'grpc-handlers',
'lib': 'grpc-handlers',
'requires': ['core'] + grpc(),
},
{
'target': 'grpc-handlers-proto',
'lib': 'grpc-handlers-proto',
'requires': ['core'] + grpc(),
},
{
'target': 'api-common-protos',
'lib': 'api-common-protos',
'requires': ['grpc'],
},
])
if self.options.with_utest:
userver_components.extend([
{
'target': 'utest',
'lib': 'utest',
'requires': ['core'] + gtest(),
},
{
'target': 'ubench',
'lib': 'ubench',
'requires': ['core'] + benchmark(),
},
])
if self.options.with_postgresql:
userver_components.extend([
{
'target': 'postgresql',
'lib': 'postgresql',
'requires': ['core'] + postgresql(),
},
])
if self.options.with_mongodb:
userver_components.extend([
{
'target': 'mongo',
'lib': 'mongo',
'requires': ['core'] + mongo() + cyrussasl(),
},
])
if self.options.with_redis:
userver_components.extend([
{
'target': 'redis',
'lib': 'redis',
'requires': ['core'] + hiredis(),
},
])
if self.options.with_rabbitmq:
userver_components.extend([
{
'target': 'rabbitmq',
'lib': 'rabbitmq',
'requires': ['core'] + amqpcpp(),
},
])
if self.options.with_clickhouse:
userver_components.extend([
{
'target': 'clickhouse',
'lib': 'clickhouse',
'requires': ['core'] + abseil() + clickhouse(),
},
])
if self.options.with_kafka:
userver_components.extend([
{
'target': 'kafka',
'lib': 'kafka',
'requires': (
['core']
+ cyrussasl()
+ curl()
+ zlib()
+ openssl()
+ librdkafka()
),
},
])
if self.options.with_otlp:
userver_components.extend([
{'target': 'otlp', 'lib': 'otlp', 'requires': ['core']},
])
return userver_components
def package_info(self):
debug = 'd' if self.settings.build_type == 'Debug' else ''
def get_lib_name(module):
return f'userver-{module}{debug}'
def add_components(components):
for component in components:
conan_component = component['target']
cmake_target = component['target']
cmake_component = component['lib']
lib_name = get_lib_name(component['lib'])
requires = component['requires']
# TODO: we should also define COMPONENTS names of each target
# for find_package() but not possible yet in CMakeDeps
# see https://github.com/conan-io/conan/issues/10258
self.cpp_info.components[conan_component].set_property(
'cmake_target_name', 'userver::' + cmake_target,
)
if cmake_component == 'grpc':
self.cpp_info.components[conan_component].libs.append(
get_lib_name('grpc-internal'),
)
self.cpp_info.components[conan_component].libs.append(
get_lib_name('grpc-proto'),
)
self.cpp_info.components[conan_component].libs.append(
get_lib_name('api-common-protos'),
)
else:
self.cpp_info.components[conan_component].libs = [lib_name]
if cmake_component == 'otlp':
self.cpp_info.components[conan_component].libs.append(
get_lib_name('otlp-proto'),
)
if cmake_component == 'universal':
self.cpp_info.components[
cmake_component
].includedirs.append(
os.path.join('include', 'function_backports'),
)
if cmake_component != 'ubench':
self.cpp_info.components[
conan_component
].includedirs.append(
os.path.join('include', cmake_component),
)
self.cpp_info.components[conan_component].requires = requires
self.cpp_info.components['universal'].defines.append(
f'USERVER_NAMESPACE={self.options.namespace}',
)
self.cpp_info.components['universal'].defines.append(
f'USERVER_NAMESPACE_BEGIN={self.options.namespace_begin}',
)
self.cpp_info.components['universal'].defines.append(
f'USERVER_NAMESPACE_END={self.options.namespace_end}',
)
self.cpp_info.set_property('cmake_file_name', 'userver')
add_components(self._userver_components)
with open(
os.path.join(self._cmake_subfolder, 'CallSetupEnv.cmake'), 'w',
) as cmake_file:
cmake_file.write('userver_setup_environment()')
build_modules = [
os.path.join(
self._cmake_subfolder, 'UserverSetupEnvironment.cmake',
),
os.path.join(self._cmake_subfolder, 'CallSetupEnv.cmake'),
os.path.join(self._cmake_subfolder, 'UserverVenv.cmake'),
os.path.join(self._cmake_subfolder, 'UserverTestsuite.cmake'),
]
if self.options.with_utest:
build_modules.append(
os.path.join(self._cmake_subfolder, 'AddGoogleTests.cmake'),
)
if self.options.with_grpc:
build_modules.append(
os.path.join(self._cmake_subfolder, 'SetupProtobuf.cmake'),
)
build_modules.append(
os.path.join(self._cmake_subfolder, 'GrpcConan.cmake'),
)
build_modules.append(
os.path.join(self._cmake_subfolder, 'UserverGrpcTargets.cmake'),
)
self.cpp_info.set_property('cmake_build_modules', build_modules)