Skip to content

Commit f48bbd2

Browse files
committed
build: bootstrap enables libcxx hardening mode
1 parent 08b5707 commit f48bbd2

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

CMakeUserPresets.json.example

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@
133133
"MRDOCS_BUILD_DOCS": false,
134134
"MRDOCS_GENERATE_REFERENCE": false,
135135
"MRDOCS_GENERATE_ANTORA_REFERENCE": false,
136-
"CMAKE_MAKE_PROGRAM": "${sourceDir}/build/third-party/ninja/ninja"
136+
"CMAKE_MAKE_PROGRAM": "${sourceDir}/build/third-party/ninja/ninja",
137+
"CMAKE_CXX_FLAGS": "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE"
137138
},
138139
"condition": {
139140
"type": "equals",
@@ -163,7 +164,8 @@
163164
"MRDOCS_BUILD_DOCS": false,
164165
"MRDOCS_GENERATE_REFERENCE": false,
165166
"MRDOCS_GENERATE_ANTORA_REFERENCE": false,
166-
"CMAKE_MAKE_PROGRAM": "${sourceDir}/build/third-party/ninja/ninja"
167+
"CMAKE_MAKE_PROGRAM": "${sourceDir}/build/third-party/ninja/ninja",
168+
"CMAKE_CXX_FLAGS": "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE"
167169
},
168170
"warnings": {
169171
"unusedCli": false
@@ -360,9 +362,9 @@
360362
"Clang_ROOT": "${sourceDir}/build/third-party/llvm-project/install/debug-clang-asan",
361363
"duktape_ROOT": "${sourceDir}/build/third-party/duktape/install/debug-clang-asan",
362364
"Duktape_ROOT": "${sourceDir}/build/third-party/duktape/install/debug-clang-asan",
363-
"libxml2_ROOT": "",
364-
"LibXml2_ROOT": "",
365-
"MRDOCS_BUILD_TESTS": false,
365+
"libxml2_ROOT": "${sourceDir}/build/third-party/libxml2/install/release-clang",
366+
"LibXml2_ROOT": "${sourceDir}/build/third-party/libxml2/install/release-clang",
367+
"MRDOCS_BUILD_TESTS": true,
366368
"MRDOCS_BUILD_DOCS": false,
367369
"MRDOCS_GENERATE_REFERENCE": false,
368370
"MRDOCS_GENERATE_ANTORA_REFERENCE": false,

bootstrap.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,22 @@ def create_cmake_presets(self):
14121412
if cxx_flags:
14131413
new_preset["cacheVariables"]['CMAKE_CXX_FLAGS'] = cxx_flags.strip()
14141414

1415+
# if build type is debug and compiler is clang (default macos or explicitly clang),
1416+
# add "CMAKE_CXX_FLAGS": "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE"
1417+
# or append it to existing CMAKE_CXX_FLAGS
1418+
if self.options.mrdocs_build_type.lower() == "debug":
1419+
is_clang = False
1420+
if self.options.cxx and "clang" in os.path.basename(self.options.cxx).lower():
1421+
is_clang = True
1422+
elif "CMAKE_CXX_COMPILER_ID" in self.compiler_info and self.compiler_info["CMAKE_CXX_COMPILER_ID"].lower() == "clang":
1423+
is_clang = True
1424+
if is_clang:
1425+
hardening_flag = "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_EXTENSIVE"
1426+
if "CMAKE_CXX_FLAGS" in new_preset["cacheVariables"]:
1427+
new_preset["cacheVariables"]["CMAKE_CXX_FLAGS"] += " " + hardening_flag
1428+
else:
1429+
new_preset["cacheVariables"]["CMAKE_CXX_FLAGS"] = hardening_flag
1430+
14151431
if self.is_windows():
14161432
if self.options.python_path:
14171433
new_preset["cacheVariables"]["PYTHON_EXECUTABLE"] = self.options.python_path

0 commit comments

Comments
 (0)