Skip to content

Commit 9b19be9

Browse files
authored
CDRIVER-5891 extend C standard coverage up to C23 (#1890)
* Ensure CC and CXX consistency, use CMAKE_GENERATOR for Visual Studio * Use ls_distro to reduce boilerplate * Sort std-matrix tasks by compiler and version * Support /std:clatest with MSVC * Exclude -Wc++98-compat warnings from public-header-warnings * Exclude -Wpre-c2x-compat warnings from public-header-warnings * Exclude -Wunsafe-buffer-usage from public-header-warnings * Address C2X compatibility issues due to _Bool macro expansions
1 parent 33ed617 commit 9b19be9

21 files changed

+1303
-252
lines changed

.evergreen/config_generator/components/c_std_compile.py

+31-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from config_generator.etc.distros import find_large_distro
88
from config_generator.etc.distros import make_distro_str
9-
from config_generator.etc.distros import to_cc
9+
from config_generator.etc.distros import compiler_to_vars
1010
from config_generator.etc.function import Function
1111
from config_generator.etc.utils import bash_exec
1212

@@ -17,14 +17,31 @@
1717
# pylint: disable=line-too-long
1818
# fmt: off
1919
MATRIX = [
20-
('debian92', 'clang', None, [11, ]),
21-
('debian10', 'clang', None, [11, ]),
22-
('debian10', 'gcc', None, [11, 17]),
23-
('debian11', 'clang', None, [11, ]),
24-
('debian11', 'gcc', None, [11, 17]),
25-
('ubuntu2004', 'clang', None, [11, ]),
26-
('ubuntu2004', 'gcc', None, [11, ]),
27-
('windows-vsCurrent', 'vs2017x64', None, [11, 17]),
20+
('rhel80', 'clang', None, [99, 11, 17, ]), # Clang 7.0
21+
('ubuntu2004', 'clang-10', None, [99, 11, 17, 23]), # Clang 10.0 (max: C2x)
22+
('rhel84', 'clang', None, [99, 11, 17, 23]), # Clang 11.0 (max: C2x)
23+
('ubuntu2204', 'clang-12', None, [99, 11, 17, 23]), # Clang 12.0 (max: C2x)
24+
('rhel90', 'clang', None, [99, 11, 17, 23]), # Clang 13.0 (max: C2x)
25+
('rhel91', 'clang', None, [99, 11, 17, 23]), # Clang 14.0 (max: C2x)
26+
('rhel92', 'clang', None, [99, 11, 17, 23]), # Clang 15.0 (max: C2x)
27+
('rhel93', 'clang', None, [99, 11, 17, 23]), # Clang 16.0 (max: C2x)
28+
('rhel94', 'clang', None, [99, 11, 17, 23]), # Clang 17.0 (max: C2x)
29+
('rhel95', 'clang', None, [99, 11, 17, 23]), # Clang 18.0 (max: C23)
30+
31+
('rhel76', 'gcc', None, [99, 11, ]), # GCC 4.8 (max: C11)
32+
('rhel80', 'gcc', None, [99, 11, 17, ]), # GCC 8.2 (max: C17)
33+
('debian10', 'gcc-8', None, [99, 11, 17, ]), # GCC 8.3 (max: C17)
34+
('rhel84', 'gcc', None, [99, 11, 17, ]), # GCC 8.4 (max: C17)
35+
('ubuntu2004', 'gcc-9', None, [99, 11, 17, 23]), # GCC 9.4 (max: C2x)
36+
('debian11', 'gcc-10', None, [99, 11, 17, 23]), # GCC 10.2 (max: C2x)
37+
('rhel90', 'gcc', None, [99, 11, 17, 23]), # GCC 11.2 (max: C2x)
38+
('rhel92', 'gcc', None, [99, 11, 17, 23]), # GCC 11.3 (max: C2x)
39+
('rhel94', 'gcc', None, [99, 11, 17, 23]), # GCC 11.4 (max: C2x)
40+
('rhel95', 'gcc', None, [99, 11, 17, 23]), # GCC 11.5 (max: C2x)
41+
42+
('windows-vsCurrent', 'vs2017x64', None, [99, 11, 17, 'latest']), # Max: C17, clatest (C2x)
43+
('windows-vsCurrent', 'vs2019x64', None, [99, 11, 17, 'latest']), # Max: C17, clatest (C2x)
44+
('windows-vsCurrent', 'vs2022x64', None, [99, 11, 17, 'latest']), # Max: C17, clatest (C2x)
2845
]
2946
# fmt: on
3047
# pylint: enable=line-too-long
@@ -54,18 +71,20 @@ def tasks():
5471
res = []
5572

5673
for distro_name, compiler, arch, stds in MATRIX:
57-
tags = [TAG, distro_name, compiler, 'compile']
74+
compiler_type = compiler.split('-')[0]
75+
76+
tags = [TAG, distro_name, compiler_type, 'compile']
5877

5978
distro = find_large_distro(distro_name)
6079

6180
compile_vars = None
62-
compile_vars = {'CC': to_cc(compiler)}
81+
compile_vars = compiler_to_vars(compiler)
6382

6483
if arch:
6584
tags.append(arch)
6685
compile_vars.update({'MARCH': arch})
6786

68-
distro_str = make_distro_str(distro_name, compiler, arch)
87+
distro_str = make_distro_str(distro_name, compiler_type, arch)
6988

7089
for std in stds:
7190
with_std = {'C_STD_VERSION': std}

.evergreen/config_generator/components/openssl_static_compile.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from config_generator.etc.distros import find_large_distro
88
from config_generator.etc.distros import make_distro_str
9-
from config_generator.etc.distros import to_cc
9+
from config_generator.etc.distros import compiler_to_vars
1010
from config_generator.etc.function import Function
1111
from config_generator.etc.utils import bash_exec
1212

@@ -55,7 +55,7 @@ def tasks():
5555
distro = find_large_distro(distro_name)
5656

5757
compile_vars = None
58-
compile_vars = {'CC': to_cc(compiler)}
58+
compile_vars = compiler_to_vars(compiler)
5959

6060
if arch:
6161
tags.append(arch)
@@ -72,7 +72,7 @@ def tasks():
7272
tags=tags,
7373
commands=[
7474
FindCMakeLatest.call(),
75-
StaticOpenSSLCompile.call(vars=compile_vars),
75+
StaticOpenSSLCompile.call(vars=compile_vars if compile_vars else None),
7676
],
7777
)
7878
)

.evergreen/config_generator/components/scan_build.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from config_generator.etc.distros import find_large_distro
99
from config_generator.etc.distros import make_distro_str
10-
from config_generator.etc.distros import to_cc
10+
from config_generator.etc.distros import compiler_to_vars
1111
from config_generator.etc.function import Function
1212
from config_generator.etc.utils import bash_exec
1313

@@ -56,7 +56,7 @@ def tasks():
5656
distro = find_large_distro(distro_name)
5757

5858
compile_vars = None
59-
compile_vars = {'CC': to_cc(compiler)}
59+
compile_vars = compiler_to_vars(compiler)
6060

6161
if arch:
6262
tags.append(arch)
@@ -73,7 +73,7 @@ def tasks():
7373
tags=tags,
7474
commands=[
7575
FindCMakeLatest.call(),
76-
ScanBuild.call(vars=compile_vars),
76+
ScanBuild.call(vars=compile_vars if compile_vars else None),
7777
FunctionCall(func='upload scan artifacts'),
7878
],
7979
)

.evergreen/config_generator/etc/compile.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from config_generator.etc.distros import find_large_distro
44
from config_generator.etc.distros import make_distro_str
5-
from config_generator.etc.distros import to_cc
5+
from config_generator.etc.distros import compiler_to_vars
66

77
from config_generator.components.funcs.find_cmake_latest import FindCMakeLatest
88
from config_generator.components.funcs.upload_build import UploadBuild
@@ -20,7 +20,7 @@ def generate_compile_tasks(SSL, TAG, SASL_TO_FUNC, MATRIX, MORE_TAGS=None, MORE_
2020
distro = find_large_distro(distro_name)
2121

2222
compile_vars = None
23-
compile_vars = {'CC': to_cc(compiler)}
23+
compile_vars = compiler_to_vars(compiler)
2424

2525
if arch:
2626
tags.append(arch)
@@ -38,7 +38,7 @@ def generate_compile_tasks(SSL, TAG, SASL_TO_FUNC, MATRIX, MORE_TAGS=None, MORE_
3838

3939
commands = []
4040
commands.append(FindCMakeLatest.call())
41-
commands.append(SASL_TO_FUNC[sasl].call(vars=compile_vars))
41+
commands.append(SASL_TO_FUNC[sasl].call(vars=compile_vars if compile_vars else None))
4242
commands.append(UploadBuild.call())
4343

4444
res.append(

.evergreen/config_generator/etc/cse/test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from config_generator.etc.distros import find_small_distro
88
from config_generator.etc.distros import make_distro_str
9-
from config_generator.etc.distros import to_cc
9+
from config_generator.etc.distros import compiler_to_vars
1010

1111
from config_generator.components.funcs.bootstrap_mongo_orchestration import BootstrapMongoOrchestration
1212
from config_generator.components.funcs.fetch_build import FetchBuild
@@ -29,7 +29,7 @@ def generate_test_tasks(SSL, TAG, MATRIX):
2929
test_distro = find_small_distro(distro_name)
3030

3131
compile_vars = []
32-
compile_vars.append(KeyValueParam(key='CC', value=to_cc(compiler)))
32+
compile_vars = [KeyValueParam(key=key, value=value) for key, value in compiler_to_vars(compiler).items()]
3333

3434
if arch:
3535
tags.append(arch)

.evergreen/config_generator/etc/distros.py

+96-78
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ class Distro(BaseModel):
3939
def validate_os_ver(cls, value):
4040
return Version(value)
4141

42-
# See: https://evergreen.mongodb.com/distros
43-
# pylint: disable=line-too-long
44-
#fmt: off
42+
43+
def ls_distro(name, **kwargs):
44+
return [
45+
Distro(name=f'{name}-large', size='large', **kwargs),
46+
Distro(name=f'{name}-small', size='small', **kwargs),
47+
]
48+
49+
4550
DEBIAN_DISTROS = [
46-
Distro(name='debian92-large', os='debian', os_type='linux', os_ver='9.2', size='large'), # CDRIVER-5873
47-
Distro(name='debian92-small', os='debian', os_type='linux', os_ver='9.2', size='small'), # CDRIVER-5873
48-
Distro(name='debian10-large', os='debian', os_type='linux', os_ver='10', size='large'), # CDRIVER-5874
49-
Distro(name='debian10-small', os='debian', os_type='linux', os_ver='10', size='small'), # CDRIVER-5874
50-
Distro(name='debian11-large', os='debian', os_type='linux', os_ver='11', size='large'),
51-
Distro(name='debian11-small', os='debian', os_type='linux', os_ver='11', size='small'),
52-
Distro(name='debian92-large', os='debian', os_type='linux', os_ver='9.2', size='large'),
53-
Distro(name='debian92-small', os='debian', os_type='linux', os_ver='9.2', size='small'),
51+
*ls_distro(name='debian92', os='debian', os_type='linux', os_ver='9.2'), # CDRIVER-5873
52+
*ls_distro(name='debian10', os='debian', os_type='linux', os_ver='10'), # CDRIVER-5874
53+
*ls_distro(name='debian11', os='debian', os_type='linux', os_ver='11'),
5454
]
5555

5656
MACOS_DISTROS = [
@@ -63,89 +63,57 @@ def validate_os_ver(cls, value):
6363
]
6464

6565
RHEL_DISTROS = [
66-
Distro(name='rhel80-large', os='rhel', os_type='linux', os_ver='8.0', size='large'),
67-
Distro(name='rhel80-small', os='rhel', os_type='linux', os_ver='8.0', size='small'),
68-
Distro(name='rhel84-large', os='rhel', os_type='linux', os_ver='8.4', size='large'),
69-
Distro(name='rhel84-small', os='rhel', os_type='linux', os_ver='8.4', size='small'),
70-
Distro(name='rhel8.9-large', os='rhel', os_type='linux', os_ver='8.7', size='large'),
71-
Distro(name='rhel8.9-small', os='rhel', os_type='linux', os_ver='8.7', size='small'),
72-
Distro(name='rhel92-large', os='rhel', os_type='linux', os_ver='9.0', size='large'),
73-
Distro(name='rhel92-small', os='rhel', os_type='linux', os_ver='9.0', size='small'),
74-
]
75-
76-
RHEL_ARM64_DISTROS = [
77-
Distro(name='rhel82-arm64-large', os='rhel', os_type='linux', os_ver='8.2', size='large', arch='arm64'),
78-
Distro(name='rhel82-arm64-small', os='rhel', os_type='linux', os_ver='8.2', size='small', arch='arm64'),
79-
Distro(name='rhel92-arm64-large', os='rhel', os_type='linux', os_ver='9.0', size='large', arch='arm64'),
80-
Distro(name='rhel92-arm64-small', os='rhel', os_type='linux', os_ver='9.0', size='small', arch='arm64'),
66+
*ls_distro(name='rhel76', os='rhel', os_type='linux', os_ver='7.6'),
67+
*ls_distro(name='rhel80', os='rhel', os_type='linux', os_ver='8.0'),
68+
*ls_distro(name='rhel84', os='rhel', os_type='linux', os_ver='8.4'),
69+
*ls_distro(name='rhel90', os='rhel', os_type='linux', os_ver='9.0'),
70+
*ls_distro(name='rhel91', os='rhel', os_type='linux', os_ver='9.1'),
71+
*ls_distro(name='rhel92', os='rhel', os_type='linux', os_ver='9.2'),
72+
*ls_distro(name='rhel93', os='rhel', os_type='linux', os_ver='9.3'),
73+
*ls_distro(name='rhel94', os='rhel', os_type='linux', os_ver='9.4'),
74+
*ls_distro(name='rhel95', os='rhel', os_type='linux', os_ver='9.5'),
75+
*ls_distro(name='rhel8.9', os='rhel', os_type='linux', os_ver='8.7'),
76+
*ls_distro(name='rhel92', os='rhel', os_type='linux', os_ver='9.0'),
8177
]
8278

8379
RHEL_POWER_DISTROS = [
84-
Distro(name='rhel8-power-large', os='rhel', os_type='linux', os_ver='8', size='large', arch='power'),
85-
Distro(name='rhel8-power-small', os='rhel', os_type='linux', os_ver='8', size='small', arch='power'),
86-
Distro(name='rhel9-power-large', os='rhel', os_type='linux', os_ver='9', size='large', arch='power'),
87-
Distro(name='rhel9-power-small', os='rhel', os_type='linux', os_ver='9', size='small', arch='power'),
80+
*ls_distro(name='rhel8-power', os='rhel', os_type='linux', os_ver='8', arch='power'),
8881
]
8982

9083
RHEL_ZSERIES_DISTROS = [
91-
Distro(name='rhel8-zseries-large', os='rhel', os_type='linux', os_ver='8', size='large', arch='zseries'),
92-
Distro(name='rhel8-zseries-small', os='rhel', os_type='linux', os_ver='8', size='small', arch='zseries'),
93-
Distro(name='rhel9-zseries-large', os='rhel', os_type='linux', os_ver='9', size='large', arch='zseries'),
94-
Distro(name='rhel9-zseries-small', os='rhel', os_type='linux', os_ver='9', size='small', arch='zseries'),
84+
*ls_distro(name='rhel8-zseries', os='rhel', os_type='linux', os_ver='8', arch='zseries'),
9585
]
9686

9787
UBUNTU_DISTROS = [
98-
Distro(name='ubuntu2004-large', os='ubuntu', os_type='linux', os_ver='20.04', size='large'),
99-
Distro(name='ubuntu2004-small', os='ubuntu', os_type='linux', os_ver='20.04', size='small'),
100-
Distro(name='ubuntu2204-large', os='ubuntu', os_type='linux', os_ver='22.04', size='large'),
101-
Distro(name='ubuntu2204-small', os='ubuntu', os_type='linux', os_ver='22.04', size='small'),
88+
*ls_distro(name='ubuntu2004', os='ubuntu', os_type='linux', os_ver='20.04'),
89+
*ls_distro(name='ubuntu2204', os='ubuntu', os_type='linux', os_ver='22.04'),
10290
]
10391

10492
UBUNTU_ARM64_DISTROS = [
105-
Distro(name='ubuntu2004-arm64-large', os='ubuntu', os_type='linux', os_ver='20.04', size='large', arch='arm64'),
106-
Distro(name='ubuntu2004-arm64-small', os='ubuntu', os_type='linux', os_ver='20.04', size='small', arch='arm64'),
107-
Distro(name='ubuntu2204-arm64-large', os='ubuntu', os_type='linux', os_ver='22.04', size='large', arch='arm64'),
108-
Distro(name='ubuntu2204-arm64-small', os='ubuntu', os_type='linux', os_ver='22.04', size='small', arch='arm64'),
93+
*ls_distro(name='ubuntu2004-arm64', os='ubuntu', os_type='linux', os_ver='20.04', arch='arm64'),
10994
]
11095

11196
WINDOWS_DISTROS = [
112-
Distro(name='windows-64-vs2013-large', os='windows', os_type='windows', vs_ver='2013', size='large'),
113-
Distro(name='windows-64-vs2013-small', os='windows', os_type='windows', vs_ver='2013', size='small'),
114-
Distro(name='windows-64-vs2015-large', os='windows', os_type='windows', vs_ver='2015', size='large'),
115-
Distro(name='windows-64-vs2015-small', os='windows', os_type='windows', vs_ver='2015', size='small'),
116-
Distro(name='windows-64-vs2017-large', os='windows', os_type='windows', vs_ver='2017', size='large'),
117-
Distro(name='windows-64-vs2017-small', os='windows', os_type='windows', vs_ver='2017', size='small'),
118-
Distro(name='windows-64-vs2019-large', os='windows', os_type='windows', vs_ver='2019', size='large'),
119-
Distro(name='windows-64-vs2019-small', os='windows', os_type='windows', vs_ver='2019', size='small'),
120-
121-
Distro(name='windows-2022-large', os='windows', os_type='windows', os_ver='2022'),
122-
Distro(name='windows-2022-small', os='windows', os_type='windows', os_ver='2022'),
123-
124-
Distro(name='windows-64-2019', os='windows', os_type='windows', os_ver='2019'),
125-
126-
Distro(name='windows-64-vsMulti-small', os='windows', os_type='windows', vs_ver='vsMulti', size='small'),
97+
*ls_distro(name='windows-64-vs2015', os='windows', os_type='windows', vs_ver='2015'),
98+
*ls_distro(name='windows-64-vs2017', os='windows', os_type='windows', vs_ver='2017'),
99+
*ls_distro(name='windows-64-vs2019', os='windows', os_type='windows', vs_ver='2019'),
127100

128-
Distro(name='windows-vsCurrent-2022-large', os='windows', os_type='windows', os_ver='2022', vs_ver='vsCurrent', size='large'),
129-
Distro(name='windows-vsCurrent-2022-small', os='windows', os_type='windows', os_ver='2022', vs_ver='vsCurrent', size='small'),
130-
131-
Distro(name='windows-vsCurrent-large', os='windows', os_type='windows', vs_ver='vsCurrent', size='large'), # Windows Server 2019
132-
Distro(name='windows-vsCurrent-small', os='windows', os_type='windows', vs_ver='vsCurrent', size='small'), # Windows Server 2019
101+
*ls_distro(name='windows-vsCurrent', os='windows', os_type='windows', vs_ver='vsCurrent'), # Windows Server 2019
133102
]
134-
#fmt: on
135-
# pylint: enable=line-too-long
136103

104+
# See: https://evergreen.mongodb.com/distros
137105
# Ensure no-arch distros are ordered before arch-specific distros.
138-
ALL_DISTROS = [] + \
139-
DEBIAN_DISTROS + \
140-
MACOS_DISTROS + \
141-
MACOS_ARM64_DISTROS + \
142-
RHEL_DISTROS + \
143-
RHEL_ARM64_DISTROS + \
144-
RHEL_POWER_DISTROS + \
145-
RHEL_ZSERIES_DISTROS + \
146-
UBUNTU_DISTROS + \
147-
UBUNTU_ARM64_DISTROS + \
148-
WINDOWS_DISTROS
106+
ALL_DISTROS = [
107+
*DEBIAN_DISTROS,
108+
*MACOS_DISTROS,
109+
*MACOS_ARM64_DISTROS,
110+
*RHEL_DISTROS,
111+
*RHEL_POWER_DISTROS,
112+
*RHEL_ZSERIES_DISTROS,
113+
*UBUNTU_DISTROS,
114+
*UBUNTU_ARM64_DISTROS,
115+
*WINDOWS_DISTROS,
116+
]
149117

150118

151119
def find_distro(name) -> Distro:
@@ -205,6 +173,10 @@ def make_distro_str(distro_name, compiler, arch) -> str:
205173
'vs2015x86': '-x86',
206174
'vs2017x64': '-x64',
207175
'vs2017x86': '-x86',
176+
'vs2019x64': '-x64',
177+
'vs2019x86': '-x86',
178+
'vs2022x64': '-x64',
179+
'vs2022x86': '-x86',
208180
}.get(compiler, f'-{compiler}')
209181
else:
210182
distro_str = distro_name
@@ -219,10 +191,56 @@ def make_distro_str(distro_name, compiler, arch) -> str:
219191

220192
def to_cc(compiler):
221193
return {
222-
'vs2013x64': 'Visual Studio 12 2013 Win64',
194+
'vs2013x64': 'Visual Studio 12 2013',
223195
'vs2013x86': 'Visual Studio 12 2013',
224-
'vs2015x64': 'Visual Studio 14 2015 Win64',
196+
'vs2015x64': 'Visual Studio 14 2015',
225197
'vs2015x86': 'Visual Studio 14 2015',
226-
'vs2017x64': 'Visual Studio 15 2017 Win64',
198+
'vs2017x64': 'Visual Studio 15 2017',
227199
'vs2017x86': 'Visual Studio 15 2017',
200+
'vs2019x64': 'Visual Studio 16 2019',
201+
'vs2019x86': 'Visual Studio 16 2019',
202+
'vs2022x64': 'Visual Studio 17 2022',
203+
'vs2022x86': 'Visual Studio 17 2022',
228204
}.get(compiler, compiler)
205+
206+
207+
def to_platform(compiler):
208+
return {
209+
'vs2013x64': 'x64',
210+
'vs2013x86': 'Win32',
211+
'vs2015x64': 'x64',
212+
'vs2015x86': 'Win32',
213+
'vs2017x64': 'x64',
214+
'vs2017x86': 'Win32',
215+
'vs2019x64': 'x64',
216+
'vs2019x86': 'Win32',
217+
'vs2022x64': 'x64',
218+
'vs2022x86': 'Win32',
219+
}.get(compiler, compiler)
220+
221+
222+
def compiler_to_vars(compiler):
223+
match compiler, compiler.split('-'):
224+
case _, ['gcc', *rest]:
225+
return {
226+
'CC': '-'.join(['gcc'] + rest),
227+
'CXX': '-'.join(['g++'] + rest),
228+
}
229+
230+
case _, ['clang', *rest]:
231+
return {
232+
'CC': '-'.join(['clang'] + rest),
233+
'CXX': '-'.join(['clang++'] + rest),
234+
}
235+
236+
case str(vs), _ if 'vs' in vs:
237+
return {
238+
'CMAKE_GENERATOR': to_cc(vs),
239+
'CMAKE_GENERATOR_PLATFORM': to_platform(vs),
240+
}
241+
242+
case compiler, _:
243+
return {
244+
'CC': compiler,
245+
'CXX': compiler,
246+
}

0 commit comments

Comments
 (0)