Skip to content

Commit e7ae03a

Browse files
K-ballomizvekov
authored andcommitted
use system libs by default
1 parent adb6821 commit e7ae03a

File tree

21 files changed

+84
-52
lines changed

21 files changed

+84
-52
lines changed

.clang-format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,7 @@ IncludeCategories:
227227
# Comments
228228
FixNamespaceComments: true
229229
CommentPragmas: '^ clang-format'
230+
231+
---
232+
Language: Json
233+
BasedOnStyle: llvm

CMakeLists.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,6 @@ if (NOT EXISTS "${LIBCXX_DIR}")
261261
"Please provide a LLVM with libc++ enabled\n")
262262
endif()
263263

264-
set(STDLIB_INCLUDE_DIR "${LLVM_BINARY_DIR}/lib/clang/${Clang_VERSION_MAJOR}/include"
265-
CACHE PATH "Path to the clang headers include directory")
266-
message(STATUS "STDLIB_INCLUDE_DIR: ${STDLIB_INCLUDE_DIR}")
267-
if (NOT EXISTS "${STDLIB_INCLUDE_DIR}")
268-
message(FATAL_ERROR
269-
"STDLIB_INCLUDE_DIR (${STDLIB_INCLUDE_DIR}) does not exist.\n"
270-
"Missing clang headers\n")
271-
endif()
272-
273264
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
274265
include(HandleLLVMOptions)
275266
add_definitions(${LLVM_DEFINITIONS})
@@ -388,6 +379,7 @@ if (WIN32)
388379
mrdocs-core
389380
PUBLIC
390381
/permissive- # strict C++
382+
/Zc:__cplusplus # report C++ standard support
391383
/W4 # enable all warnings
392384
/MP # multi-processor compilation
393385
/EHs # C++ Exception handling
@@ -490,7 +482,6 @@ if (MRDOCS_BUILD_TESTS)
490482
"--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
491483
--generator=${testgenerator}
492484
"--stdlib-includes=${LIBCXX_DIR}"
493-
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
494485
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
495486
--log-level=warn
496487
)
@@ -505,7 +496,6 @@ if (MRDOCS_BUILD_TESTS)
505496
"--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
506497
--generator=${testgenerator}
507498
"--stdlib-includes=${LIBCXX_DIR}"
508-
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
509499
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
510500
--log-level=warn
511501
DEPENDS mrdocs-test
@@ -703,9 +693,6 @@ if (MRDOCS_INSTALL)
703693
install(DIRECTORY ${LIBCXX_DIR}/
704694
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/libcxx
705695
FILES_MATCHING PATTERN "*")
706-
install(DIRECTORY ${STDLIB_INCLUDE_DIR}/
707-
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/clang
708-
FILES_MATCHING PATTERN "*")
709696
install(DIRECTORY ${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs/
710697
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/libc-stubs
711698
FILES_MATCHING PATTERN "*")

docs/modules/ROOT/pages/usage.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ It's also common for libraries to depend on the C++ standard library, the C stan
278278

279279
That means unless `-nostdinc` is defined, all systems include paths are included. This is what allows the user to also use headers like `<Windows.h>` or `<linux/version.h>` without explicitly including anything else, even though they are not part of the C standard library. This is often seen as a convenience but can lead to portability issues.
280280

281-
In this context, MrDocs provides the `use-system-stdlib` and `use-system-libc` options. Both are set as `false` by default, meaning MrDocs will compile the code as if the `-nostdinc&plus;&plus; -nostdlib&plus;&plus;` and `-nostdinc` flags were passed to Clang. Additionally:
281+
In this context, MrDocs provides the `use-system-stdlib` and `use-system-libc` options. Both are set as `true` by default; setting both to `false` results in MrDocs compiling the code as if the `-nostdinc&plus;&plus; -nostdlib&plus;&plus;` and `-nostdinc` flags were passed to Clang. Additionally:
282282

283283
- When `use-system-stdlib` is `false`, MrDocs will use the bundled libc&plus;&plus; headers available in `<mrdocs-root>/share/mrdocs/headers/libcxx` and `<mrdocs-root>/share/mrdocs/headers/clang`. These paths can be adjusted with the `stdlib-includes` option.
284284
- When `use-system-libc` is `false`, MrDocs will use the bundled libc stubs available in `<mrdocs-root>/share/mrdocs/headers/libc-stubs`. This path can be adjusted with the `libc-includes` option.

docs/mrdocs.schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@
557557
"type": "string"
558558
},
559559
"use-system-libc": {
560-
"default": false,
560+
"default": true,
561561
"description": "To achieve reproducible results, MrDocs bundles the LibC headers with its definitions. To use the C standard library available in the system instead, set this option to true.",
562562
"enum": [
563563
true,
@@ -567,7 +567,7 @@
567567
"type": "boolean"
568568
},
569569
"use-system-stdlib": {
570-
"default": false,
570+
"default": true,
571571
"description": "To achieve reproducible results, MrDocs bundles the LibC++ headers. To use the C++ standard library available in the system instead, set this option to true.",
572572
"enum": [
573573
true,

docs/website/snippets/sqrt.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <type_traits>
2-
#include <stdexcept>
32

43
/** Computes the square root of an integral value.
54

src/lib/AST/ASTVisitor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,8 @@ extractSFINAEInfo(clang::QualType const T)
23782378
Result.Type = resultType->getAsType();
23792379
for (std::size_t I = 0; I < Args.size(); ++I)
23802380
{
2381-
if (SFINAEControl->ControllingParams[I])
2381+
if (I < SFINAEControl->ControllingParams.size()
2382+
&& SFINAEControl->ControllingParams[I])
23822383
{
23832384
MRDOCS_SYMBOL_TRACE(Args[I], context_);
23842385
clang::TemplateArgument ArgsI = Args[I];

src/lib/ConfigOptions.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,16 +493,15 @@
493493
"brief": "Use the system C++ standard library",
494494
"details": "To achieve reproducible results, MrDocs bundles the LibC++ headers. To use the C++ standard library available in the system instead, set this option to true.",
495495
"type": "bool",
496-
"default": false
496+
"default": true
497497
},
498498
{
499499
"name": "stdlib-includes",
500500
"brief": "C++ Standard Library include paths",
501501
"details": "When `use-system-stdlib` is disabled, the C++ standard library headers are available in these paths.",
502502
"type": "list<path>",
503503
"default": [
504-
"<mrdocs-root>/share/mrdocs/headers/libcxx",
505-
"<mrdocs-root>/share/mrdocs/headers/clang"
504+
"<mrdocs-root>/share/mrdocs/headers/libcxx"
506505
],
507506
"relative-to": "<config-dir>",
508507
"must-exist": false,
@@ -513,7 +512,7 @@
513512
"brief": "Use the system C standard library",
514513
"details": "To achieve reproducible results, MrDocs bundles the LibC headers with its definitions. To use the C standard library available in the system instead, set this option to true.",
515514
"type": "bool",
516-
"default": false
515+
"default": true
517516
},
518517
{
519518
"name": "libc-includes",
@@ -672,4 +671,4 @@
672671
}
673672
]
674673
}
675-
]
674+
]

src/lib/MrDocsCompilationDatabase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ adjustCommandLine(
406406

407407
if (!(*config)->useSystemLibc)
408408
{
409-
new_cmdline.emplace_back("-nostdinc");
409+
new_cmdline.emplace_back(is_clang_cl ? "-X" : "-nostdlibinc");
410410
for (auto const& inc : (*config)->libcIncludes)
411411
{
412412
new_cmdline.emplace_back(systemIncludeFlag);

src/lib/MrDocsSettingsDB.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "MrDocsSettingsDB.hpp"
1313
#include <mrdocs/Support/Path.hpp>
14+
#include <llvm/Support/Program.h>
1415

1516

1617
namespace mrdocs {
@@ -60,17 +61,18 @@ MrDocsSettingsDB::MrDocsSettingsDB(ConfigImpl const& config)
6061
});
6162
}
6263

64+
llvm::ErrorOr<std::string> clangPath = llvm::sys::findProgramByName(
65+
"clang");
66+
6367
for (auto const& pathName: sourceFiles)
6468
{
6569
// auto fileName = files::getFileName(pathName);
6670
auto parentDir = files::getParentDir(pathName);
6771

6872
std::vector<std::string> cmds;
69-
cmds.emplace_back("clang");
73+
cmds.emplace_back(clangPath ? *clangPath : "clang");
7074
cmds.emplace_back("-fsyntax-only");
7175
cmds.emplace_back("-std=c++23");
72-
cmds.emplace_back("-pedantic-errors");
73-
cmds.emplace_back("-Werror");
7476
cmds.emplace_back("-x");
7577
cmds.emplace_back("c++");
7678
cmds.emplace_back(pathName);

src/test/TestRunner.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,10 @@ handleFile(
125125

126126
auto parentDir = files::getParentDir(filePath);
127127
std::unordered_map<std::string, std::vector<std::string>>
128-
defaultIncludePaths;
128+
defaultIncludePaths = {
129+
{ "clang", { MRDOCS_TEST_FILES_DIR "/include" } },
130+
{ "clang-cl", { MRDOCS_TEST_FILES_DIR "/include" } },
131+
};
129132

130133
// Test normally
131134
{

0 commit comments

Comments
 (0)