forked from microsoft/onnxruntime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvcpkg_helpers.py
562 lines (489 loc) · 25.9 KB
/
vcpkg_helpers.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
import os
from pathlib import Path
# The official vcpkg repository has about 80 different triplets. But ONNX Runtime has many more build variants. For example, in general, for each platform, we need to support builds with C++ exceptions, builds without C++ exceptions, builds with C++ RTTI, builds without C++ RTTI, linking to static C++ runtime, linking to dynamic (shared) C++ runtime, builds with address sanitizer, builds without address sanitizer, etc. Therefore, this script file was created to dynamically generate the triplet files on-the-fly.
# Originally, we tried to check in all the generated files into our repository so that people could build onnxruntime without using build.py or any other Python scripts in the "/tools" directory. However, we encountered an issue when adding support for WASM builds. VCPKG has a limitation that when doing cross-compiling, the triplet file must specify the full path of the chain-loaded toolchain file. The file needs to be located either via environment variables (like ANDROID_NDK_HOME) or via an absolute path. Since environment variables are hard to track, we chose the latter approach. So the generated triplet files may contain absolute file paths that are only valid on the current build machine.
# The compiler flags(CFLAGS/CXXFLAGS/LDFLAGS) settings in this file must be consistent with the cmake code in "cmake/adjust_global_compile_flags.cmake" so that all the statically linked code were compiled by the same set of compile flags.
# This is a way to add customizations to the official VCPKG ports.
def add_port_configs(f, has_exception: bool, is_emscripten: bool) -> None:
"""
Add port-specific configurations to the triplet file.
Args:
f (file object): The file object to write configurations.
has_exception (bool): Flag indicating if exceptions are enabled.
"""
f.write(
r"""if(PORT MATCHES "onnx")
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS
"-DONNX_DISABLE_STATIC_REGISTRATION=ON"
)
endif()
if(PORT MATCHES "benchmark")
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS
"-DBENCHMARK_ENABLE_WERROR=OFF"
)
endif()
"""
)
if is_emscripten:
f.write(
r"""if(PORT MATCHES "gtest")
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS
"-Dgtest_disable_pthreads=ON"
)
endif()
"""
)
if not has_exception:
f.write(
r"""if(PORT MATCHES "onnx")
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS
"-DONNX_DISABLE_EXCEPTIONS=ON"
)
endif()
"""
)
def add_copyright_header(f) -> None:
"""
Add copyright header to the triplet file.
Args:
f (file object): The file object to write the header.
"""
f.write(
r"""# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""
)
def generate_triplet_for_android(
build_dir: str,
target_abi: str,
enable_rtti: bool,
enable_exception: bool,
enable_asan: bool,
use_cpp_shared: bool,
android_api_level: int,
) -> None:
"""
Generate triplet file for Android platform.
Args:
build_dir (str): The directory to save the generated triplet files.
target_abi (str): The target ABI.
enable_rtti (bool): Flag indicating if RTTI is enabled.
enable_exception (bool): Flag indicating if exceptions are enabled.
enable_asan (bool): Flag indicating if AddressSanitizer is enabled.
use_cpp_shared(bool): The type of C++ Runtime to use. If it is false, use "c++_static" which is the default for most CMake projects. Otherwise set the runtime to c++_shared.
android_api_level(int): android_api_level
"""
folder_name_parts = []
if enable_asan:
folder_name_parts.append("asan")
if not enable_rtti:
folder_name_parts.append("nortti")
if not enable_exception:
folder_name_parts.append("noexception")
folder_name = "default" if len(folder_name_parts) == 0 else "_".join(folder_name_parts)
file_name = f"{target_abi}-android.cmake"
dest_path = Path(build_dir) / folder_name / file_name
os.makedirs(dest_path.parent, exist_ok=True)
with open(dest_path, "w", encoding="utf-8") as f:
add_copyright_header(f)
# Set target architecture for Android
if target_abi == "arm-neon":
f.write("set(VCPKG_TARGET_ARCHITECTURE arm)\n")
f.write("set(VCPKG_MAKE_BUILD_TRIPLET --host=armv7a-linux-androideabi)\n")
f.write(
"list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=armeabi-v7a -DANDROID_ARM_NEON=ON -DCMAKE_ANDROID_ARM_NEON=ON)\n"
)
elif target_abi == "arm64":
f.write("set(VCPKG_TARGET_ARCHITECTURE arm64)\n")
f.write("set(VCPKG_MAKE_BUILD_TRIPLET --host=aarch64-linux-android)\n")
f.write("list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=arm64-v8a)\n")
elif target_abi == "x64":
f.write("set(VCPKG_TARGET_ARCHITECTURE x64)\n")
f.write("set(VCPKG_MAKE_BUILD_TRIPLET --host=x86_64-linux-android)\n")
f.write("list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=x86_64)\n")
elif target_abi == "x86":
f.write("set(VCPKG_TARGET_ARCHITECTURE x86)\n")
f.write("set(VCPKG_MAKE_BUILD_TRIPLET --host=i686-linux-android)\n")
f.write("list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_ABI=x86)\n")
f.write(
f"list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS -DANDROID_USE_LEGACY_TOOLCHAIN_FILE=false -DANDROID_PLATFORM=android-{android_api_level} -DANDROID_MIN_SDK={android_api_level})\n"
)
# Set CRT linkage
# VCPKG_CRT_LINKAGE specifies the desired CRT linkage (for MSVC).
# Valid options are dynamic and static.
crt_linkage = "static"
f.write(f"set(VCPKG_CRT_LINKAGE {crt_linkage})\n")
# Set library linkage
# VCPKG_LIBRARY_LINKAGE specifies the preferred library linkage.
# Valid options are dynamic and static. Libraries can ignore this setting if they do not support the preferred linkage type. In our case, we prefer to use static libs.
f.write("set(VCPKG_LIBRARY_LINKAGE static)\n")
if not enable_rtti:
f.write("set(CMAKE_ANDROID_RTTI OFF)\n")
if not enable_exception:
f.write("set(CMAKE_ANDROID_EXCEPTIONS OFF)\n")
if use_cpp_shared:
f.write("set(ANDROID_STL c++_shared)\n")
ldflags = []
cflags = ["-g", "-ffunction-sections", "-fdata-sections"]
cflags_release = ["-DNDEBUG", "-O3"]
if enable_asan:
cflags += ["-fsanitize=address"]
ldflags += ["-fsanitize=address"]
ldflags.append("-g")
cxxflags = cflags.copy()
if not enable_rtti:
cxxflags.append("-fno-rtti")
if not enable_exception:
cxxflags += ["-fno-exceptions", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables"]
if cflags:
f.write(f'set(VCPKG_C_FLAGS "{" ".join(cflags)}")\n')
if cxxflags:
f.write(f'set(VCPKG_CXX_FLAGS "{" ".join(cxxflags)}")\n')
if cflags_release:
f.write(f'set(VCPKG_C_FLAGS_RELEASE "{" ".join(cflags_release)}")\n')
f.write(f'set(VCPKG_CXX_FLAGS_RELEASE "{" ".join(cflags_release)}")\n')
f.write(f'set(VCPKG_C_FLAGS_RELWITHDEBINFO "{" ".join(cflags_release)}")\n')
f.write(f'set(VCPKG_CXX_FLAGS_RELWITHDEBINFO "{" ".join(cflags_release)}")\n')
# Set target platform
# VCPKG_CMAKE_SYSTEM_NAME specifies the target platform.
f.write("set(VCPKG_CMAKE_SYSTEM_NAME Android)\n")
f.write("set(CMAKE_POSITION_INDEPENDENT_CODE ON)\n")
f.write(
"list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS --compile-no-warning-as-error -DBENCHMARK_ENABLE_WERROR=OFF)\n"
)
if ldflags:
f.write(f'set(VCPKG_LINKER_FLAGS "{" ".join(ldflags)}")\n')
f.write("list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS -DCMAKE_CXX_STANDARD=17)\n")
add_port_configs(f, enable_exception, False)
def generate_android_triplets(build_dir: str, use_cpp_shared: bool, android_api_level: int) -> None:
"""
Generate triplet files for POSIX platforms (Linux, macOS, Android).
Args:
build_dir (str): The directory to save the generated triplet files.
"""
target_abis = ["x64", "arm64", "arm-neon", "x86"]
for enable_asan in [True, False]:
for enable_rtti in [True, False]:
for enable_exception in [True, False]:
for target_abi in target_abis:
generate_triplet_for_android(
build_dir,
target_abi,
enable_rtti,
enable_exception,
enable_asan,
use_cpp_shared,
android_api_level,
)
def generate_triplet_for_posix_platform(
build_dir: str,
os_name: str,
enable_rtti: bool,
enable_exception: bool,
enable_binskim: bool,
enable_asan: bool,
crt_linkage: str,
target_abi: str,
osx_deployment_target: str,
) -> None:
"""
Generate triplet file for POSIX platforms (Linux, macOS).
Args:
build_dir (str): The directory to save the generated triplet files.
os_name (str): The name of the operating system.
enable_rtti (bool): Flag indicating if RTTI is enabled.
enable_exception (bool): Flag indicating if exceptions are enabled.
enable_binskim (bool): Flag indicating if BinSkim is enabled.
enable_asan (bool): Flag indicating if AddressSanitizer is enabled.
crt_linkage (str): The CRT linkage type ("static" or "dynamic").
target_abi (str): The target ABI, which maps to the VCPKG_TARGET_ARCHITECTURE variable. Valid options include x86, x64, arm, arm64, arm64ec, s390x, ppc64le, riscv32, riscv64, loongarch32, loongarch64, mips64.
osx_deployment_target (str, optional): The macOS deployment target version. The parameter sets the minimum macOS version for compiled binaries. It also changes what versions of the macOS platform SDK CMake will search for. See the CMake documentation for CMAKE_OSX_DEPLOYMENT_TARGET for more information.
"""
folder_name_parts = []
if enable_asan:
folder_name_parts.append("asan")
if enable_binskim:
folder_name_parts.append("binskim")
if not enable_rtti:
folder_name_parts.append("nortti")
if not enable_exception:
folder_name_parts.append("noexception")
folder_name = "default" if len(folder_name_parts) == 0 else "_".join(folder_name_parts)
file_name = f"{target_abi}-{os_name}.cmake"
dest_path = Path(build_dir) / folder_name / file_name
os.makedirs(dest_path.parent, exist_ok=True)
with open(dest_path, "w", encoding="utf-8") as f:
add_copyright_header(f)
# Set target architecture based on `os_name` and `target_abi`.
#
# In most cases VCPKG itself can help automatically detect the target architecture, but sometimes it is not as what we want. The following code process the special cases.
if target_abi == "universal2":
# Assume the host machine is Intel based
f.write("set(VCPKG_TARGET_ARCHITECTURE x64)\n")
else:
f.write(f"set(VCPKG_TARGET_ARCHITECTURE {target_abi})\n")
# Set CRT linkage
# VCPKG_CRT_LINKAGE specifies the desired CRT linkage (for MSVC).
# Valid options are dynamic and static.
f.write(f"set(VCPKG_CRT_LINKAGE {crt_linkage})\n")
# Set library linkage
# VCPKG_LIBRARY_LINKAGE specifies the preferred library linkage.
# Valid options are dynamic and static. Libraries can ignore this setting if they do not support the preferred linkage type.
f.write("set(VCPKG_LIBRARY_LINKAGE static)\n")
ldflags = []
if enable_binskim and os_name == "linux":
# BinSkim rule 3005: Enable stack clash protection
# This check ensures that stack clash protection is enabled. Each program running on a computer uses a special memory region called the stack.
# This memory region is special because it grows automatically when the program needs more stack memory. But if it grows too much and gets too close to another memory region,
# the program may confuse the stack with the other memory region. An attacker can exploit this confusion to overwrite the stack with the other memory region, or the other way around.
# Use the compiler flags '-fstack-clash-protection' to enable this.
# BinSkim rule BA3011: Enable BIND_NOW
# This check ensures that some relocation data is marked as read-only after the executable is loaded, and moved below the '.data' section in memory.
# This prevents them from being overwritten, which can redirect control flow. Use the compiler flags '-Wl,-z,now' to enable this.
ldflags = ["-Wl,-Bsymbolic-functions", "-Wl,-z,relro", "-Wl,-z,now", "-Wl,-z,noexecstack"]
cflags = ["-g", "-ffunction-sections", "-fdata-sections"]
cflags_release = ["-DNDEBUG", "-O3"]
if enable_binskim:
cflags_release += ["-Wp,-D_FORTIFY_SOURCE=2", "-Wp,-D_GLIBCXX_ASSERTIONS", "-fstack-protector-strong"]
if target_abi == "x64":
cflags_release += ["-fstack-clash-protection", "-fcf-protection"]
elif enable_asan:
cflags += ["-fsanitize=address"]
ldflags += ["-fsanitize=address"]
ldflags.append("-g")
if not enable_rtti:
cflags.append("-DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0")
cxxflags = cflags.copy()
if os_name == "osx":
cxxflags += ["-fvisibility=hidden", "-fvisibility-inlines-hidden"]
if not enable_rtti:
cxxflags.append("-fno-rtti")
if not enable_exception:
cxxflags += ["-fno-exceptions", "-fno-unwind-tables", "-fno-asynchronous-unwind-tables"]
if cflags:
f.write(f'set(VCPKG_C_FLAGS "{" ".join(cflags)}")\n')
if cxxflags:
f.write(f'set(VCPKG_CXX_FLAGS "{" ".join(cxxflags)}")\n')
if cflags_release:
f.write(f'set(VCPKG_C_FLAGS_RELEASE "{" ".join(cflags_release)}")\n')
f.write(f'set(VCPKG_CXX_FLAGS_RELEASE "{" ".join(cflags_release)}")\n')
f.write(f'set(VCPKG_C_FLAGS_RELWITHDEBINFO "{" ".join(cflags_release)}")\n')
f.write(f'set(VCPKG_CXX_FLAGS_RELWITHDEBINFO "{" ".join(cflags_release)}")\n')
# Set target platform
# VCPKG_CMAKE_SYSTEM_NAME specifies the target platform.
if os_name == "linux":
f.write("set(VCPKG_CMAKE_SYSTEM_NAME Linux)\n")
else:
f.write("set(VCPKG_CMAKE_SYSTEM_NAME Darwin)\n")
osx_abi = None
if target_abi == "x64":
osx_abi = "x86_64"
elif target_abi == "universal2":
osx_abi = "x86_64;arm64"
else:
osx_abi = target_abi
f.write(f'set(VCPKG_OSX_ARCHITECTURES "{osx_abi}")\n')
if osx_deployment_target:
f.write(f'set(VCPKG_OSX_DEPLOYMENT_TARGET "{osx_deployment_target}")\n')
f.write("set(CMAKE_POSITION_INDEPENDENT_CODE ON)\n")
f.write(
"list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS --compile-no-warning-as-error -DBENCHMARK_ENABLE_WERROR=OFF)\n"
)
if ldflags:
f.write(f'set(VCPKG_LINKER_FLAGS "{" ".join(ldflags)}")\n')
if os_name == "osx":
f.write("list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS -DCMAKE_CXX_STANDARD=20)\n")
else:
f.write("list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS -DCMAKE_CXX_STANDARD=17)\n")
add_port_configs(f, enable_exception, False)
def generate_vcpkg_triplets_for_emscripten(build_dir: str, emscripten_root: str) -> None:
"""
Generate triplet files for Emscripten (WASM).
Args:
build_dir (str): The directory to save the generated triplet files.
emscripten_root (str): The root path of Emscripten.
"""
for enable_rtti in [True, False]:
for enable_asan in [True, False]:
for target_abi in ["wasm32", "wasm64"]:
folder_name_parts = []
if enable_asan:
folder_name_parts.append("asan")
folder_name = "default" if len(folder_name_parts) == 0 else "_".join(folder_name_parts)
os_name = "emscripten"
folder_name_parts = []
if enable_asan:
folder_name_parts.append("asan")
if not enable_rtti:
folder_name_parts.append("nortti")
folder_name = "default" if len(folder_name_parts) == 0 else "_".join(folder_name_parts)
file_name = f"{target_abi}-{os_name}.cmake"
dest_path = Path(build_dir) / folder_name / file_name
os.makedirs(dest_path.parent, exist_ok=True)
with open(dest_path, "w", encoding="utf-8") as f:
add_copyright_header(f)
f.write(r"""
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_CMAKE_SYSTEM_NAME Emscripten)
""")
f.write(f"set(VCPKG_TARGET_ARCHITECTURE {target_abi})\n")
emscripten_root_path_cmake_path = emscripten_root.replace("\\", "/")
f.write(f'set(EMSCRIPTEN_ROOT_PATH "{emscripten_root_path_cmake_path}")\n')
vcpkg_toolchain_file = (Path(build_dir) / "emsdk_vcpkg_toolchain.cmake").absolute()
vcpkg_toolchain_file_cmake_path = str(vcpkg_toolchain_file).replace("\\", "/")
f.write(f'set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "{vcpkg_toolchain_file_cmake_path}")\n')
cflags_release = ["-DNDEBUG", "-O3", "-pthread"]
ldflags = []
cflags = [
"-ffunction-sections",
"-fdata-sections",
"-msimd128",
"-pthread",
"-Wno-pthreads-mem-growth",
"-sDISABLE_EXCEPTION_CATCHING=0",
]
if enable_asan:
cflags += ["-fsanitize=address"]
ldflags += ["-fsanitize=address"]
if target_abi == "wasm64":
cflags.append("-sMEMORY64")
ldflags.append("-sMEMORY64")
if len(ldflags) >= 1:
f.write('set(VCPKG_LINKER_FLAGS "{}")\n'.format(" ".join(ldflags)))
cxxflags = cflags.copy()
if cflags:
f.write(f'set(VCPKG_C_FLAGS "{" ".join(cflags)}")\n')
if cxxflags:
f.write(f'set(VCPKG_CXX_FLAGS "{" ".join(cxxflags)}")\n')
if cflags_release:
cflags_release += cflags
f.write(f'set(VCPKG_C_FLAGS_RELEASE "{" ".join(cflags_release)}")\n')
f.write(f'set(VCPKG_CXX_FLAGS_RELEASE "{" ".join(cflags_release)}")\n')
f.write(f'set(VCPKG_C_FLAGS_RELWITHDEBINFO "{" ".join(cflags_release)}")\n')
f.write(f'set(VCPKG_CXX_FLAGS_RELWITHDEBINFO "{" ".join(cflags_release)}")\n')
add_port_configs(f, True, True)
def generate_windows_triplets(build_dir: str) -> None:
"""
Generate triplet files for Windows platforms.
Args:
build_dir (str): The directory to save the generated triplet files.
"""
# Below are all the CPU ARCHs we support on Windows.
# ARM64 is for ARM64 processes that contains traditional ARM64 code.
# ARM64EC is a different ABI that utilizes a subset of the ARM64 register set to provide interoperability with x64 code.
# Both ARM64 and ARM64EC for are AArch64 CPUs.
# We have dropped the support for ARM32.
target_abis = ["x86", "x64", "arm64", "arm64ec"]
crt_linkages = ["static", "dynamic"]
for enable_rtti in [True, False]:
for enable_exception in [True, False]:
for enable_binskim in [True, False]:
for enable_asan in [True, False]:
for crt_linkage in crt_linkages:
# Address Sanitizer libs do not have a Qspectre version. So they two cannot be both enabled.
if enable_asan and enable_binskim:
continue
for target_abi in target_abis:
folder_name_parts = []
if enable_asan:
folder_name_parts.append("asan")
if enable_binskim:
folder_name_parts.append("binskim")
if not enable_rtti:
folder_name_parts.append("nortti")
if not enable_exception:
folder_name_parts.append("noexception")
folder_name = "default" if len(folder_name_parts) == 0 else "_".join(folder_name_parts)
file_name_parts = [target_abi, "windows", "static"]
if crt_linkage == "dynamic":
file_name_parts.append("md")
file_name = "-".join(file_name_parts) + ".cmake"
dest_path = Path(build_dir) / folder_name / file_name
os.makedirs(dest_path.parent, exist_ok=True)
with open(dest_path, "w", encoding="utf-8") as f:
add_copyright_header(f)
f.write(f"set(VCPKG_TARGET_ARCHITECTURE {target_abi})\n")
f.write(f"set(VCPKG_CRT_LINKAGE {crt_linkage})\n")
f.write("set(VCPKG_LIBRARY_LINKAGE static)\n")
cflags = ["/MP", "/DWIN32", "/D_WINDOWS"]
if enable_binskim:
cflags += [
"/DWINAPI_FAMILY=100",
"/DWINVER=0x0A00",
"/D_WIN32_WINNT=0x0A00",
"/DNTDDI_VERSION=0x0A000000",
]
ldflags = []
if enable_binskim:
cflags += ["/guard:cf", "/Qspectre", "/W3"]
ldflags = ["/profile", "/DYNAMICBASE"]
elif enable_asan:
cflags.append("/fsanitize=address")
cxxflags = cflags.copy()
cxxflags.append("/Zc:__cplusplus")
if enable_exception:
cxxflags.append("/EHsc")
if not enable_rtti:
cxxflags += ["/GR-", "/we4541"]
if cflags:
f.write(f'set(VCPKG_C_FLAGS "{" ".join(cflags)}")\n')
if cxxflags:
f.write(f'set(VCPKG_CXX_FLAGS "{" ".join(cxxflags)}")\n')
f.write(
"list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS --compile-no-warning-as-error -DCMAKE_CXX_STANDARD=17)\n"
)
if ldflags:
f.write(f'set(VCPKG_LINKER_FLAGS "{" ".join(ldflags)}")\n')
add_port_configs(f, enable_exception, False)
def generate_linux_triplets(build_dir: str) -> None:
"""
Generate triplet files for Linux platforms.
Args:
build_dir (str): The directory to save the generated triplet files.
"""
target_abis = ["x86", "x64", "arm", "arm64", "s390x", "ppc64le", "riscv64", "loongarch64", "mips64"]
for enable_rtti in [True, False]:
for enable_exception in [True, False]:
for enable_binskim in [True, False]:
for enable_asan in [True, False]:
if enable_asan and enable_binskim:
continue
for target_abi in target_abis:
generate_triplet_for_posix_platform(
build_dir,
"linux",
enable_rtti,
enable_exception,
enable_binskim,
enable_asan,
"dynamic",
target_abi,
None,
)
def generate_macos_triplets(build_dir: str, osx_deployment_target: str) -> None:
"""
Generate triplet files for macOS platforms.
Args:
build_dir (str): The directory to save the generated triplet files.
osx_deployment_target (str, optional): The macOS deployment target version.
"""
target_abis = ["x64", "arm64", "universal2"]
for enable_rtti in [True, False]:
for enable_exception in [True, False]:
for enable_binskim in [True, False]:
for enable_asan in [True, False]:
if enable_asan and enable_binskim:
continue
for target_abi in target_abis:
generate_triplet_for_posix_platform(
build_dir,
"osx",
enable_rtti,
enable_exception,
enable_binskim,
enable_asan,
"dynamic",
target_abi,
osx_deployment_target,
)