Skip to content

Commit a91595e

Browse files
K-ballomizvekov
authored andcommitted
feat: use system libs by default
WIP
1 parent 92491de commit a91595e

File tree

25 files changed

+134
-71
lines changed

25 files changed

+134
-71
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

.github/workflows/ci.yml

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ jobs:
101101
common-flags-base: {{#if (ieq compiler 'clang')}}-gz=zstd {{/if}}
102102
common-flags: {{{ common-flags-base }}}{{#if msan }}-fsanitize-memory-track-origins {{/if}}
103103
common-ccflags: {{{ ccflags }}} {{{ common-flags }}}
104-
mrdocs-flags: {{{ warning-flags }}}{{#if (and (eq compiler 'gcc') (not asan)) }}-static {{/if}}
104+
mrdocs-flags: {{{ warning-flags }}}
105105
mrdocs-ccflags: {{{ common-ccflags }}} {{{ mrdocs-flags }}}
106106
mrdocs-package-generators: {{#if (ieq os 'windows') }}7Z ZIP WIX{{else}}TGZ TXZ{{/if}}
107107
mrdocs-release-package-artifact: release-packages-{{{ lowercase os }}}
@@ -563,8 +563,7 @@ jobs:
563563
- name: CMake Workflow
564564
uses: alandefreitas/cpp-actions/[email protected]
565565
env:
566-
# Bump per-test timeout on Windows to avoid CTest default (1500s) killing slow golden suites.
567-
CTEST_TEST_TIMEOUT: ${{ runner.os == 'Windows' && '3600' || '' }}
566+
CTEST_TEST_TIMEOUT: 3600
568567
with:
569568
cmake-version: '>=3.26'
570569
cxxstd: ${{ matrix.cxxstd }}
@@ -743,6 +742,22 @@ jobs:
743742
contents: write
744743

745744
steps:
745+
# This calculates a bunch of variables, which would normally go in to the regular matrix extra-values
746+
# section, but which depend on paths not known at that point.
747+
- name: Resolved Matrix
748+
id: rmatrix
749+
run: |
750+
set -euvx
751+
752+
third_party_dir="$(realpath $(pwd)/..)/third-party"
753+
if [[ "${{ runner.os }}" == 'Windows' ]]; then
754+
third_party_dir="$(echo "$third_party_dir" | sed 's/\\/\//g; s|^/d/|D:/|')"
755+
fi
756+
echo "third-party-dir=$third_party_dir" >> $GITHUB_OUTPUT
757+
758+
llvm_path="$third_party_dir/llvm"
759+
echo "llvm-path=$llvm_path" >> $GITHUB_OUTPUT
760+
746761
- name: Ensure Node
747762
if: matrix.container != '' && env.ACT == 'true'
748763
run: |
@@ -802,12 +817,10 @@ jobs:
802817
find packages -print | sed 's;[^/]*/;|____;g;s;____|; |;g'
803818
804819
if [[ ${{ runner.os }} != 'Windows' ]]; then
805-
dest_dir="$HOME/local"
806-
mkdir -p "$dest_dir"
820+
dest_dir="${{ steps.rmatrix.outputs.llvm-path }}"
807821
find packages -maxdepth 1 -name 'MrDocs-*.tar.gz' -exec tar -vxzf {} -C $dest_dir --strip-components=1 \;
808822
else
809-
dest_dir="$GITHUB_WORKSPACE/usr/local"
810-
dest_dir=$(echo "$dest_dir" | sed 's/\\/\//g')
823+
dest_dir="${{ steps.rmatrix.outputs.llvm-path }}"
811824
find packages -maxdepth 1 -name "MrDocs-*.7z" -exec 7z x {} -o$dest_dir \;
812825
if [[ $(ls -1 $dest_dir | wc -l) -eq 1 ]]; then
813826
single_dir=$(ls -1 $dest_dir)

CMakeLists.txt

Lines changed: 8 additions & 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
@@ -411,6 +403,13 @@ if (MRDOCS_DOCUMENTATION_BUILD)
411403
return()
412404
endif()
413405

406+
# Replicate the clang resource directory structure within our own build,
407+
# so that libclang will find it when executing directly from the build directory.
408+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
409+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib/clang")
410+
set(RESOURCE_DIR "lib/clang/${Clang_VERSION_MAJOR}")
411+
file(CREATE_LINK "${LLVM_BINARY_DIR}/${RESOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/${RESOURCE_DIR}" SYMBOLIC)
412+
414413
#-------------------------------------------------
415414
#
416415
# Tool
@@ -490,7 +489,6 @@ if (MRDOCS_BUILD_TESTS)
490489
"--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
491490
--generator=${testgenerator}
492491
"--stdlib-includes=${LIBCXX_DIR}"
493-
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
494492
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
495493
--log-level=warn
496494
)
@@ -505,7 +503,6 @@ if (MRDOCS_BUILD_TESTS)
505503
"--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
506504
--generator=${testgenerator}
507505
"--stdlib-includes=${LIBCXX_DIR}"
508-
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
509506
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
510507
--log-level=warn
511508
DEPENDS mrdocs-test
@@ -703,9 +700,6 @@ if (MRDOCS_INSTALL)
703700
install(DIRECTORY ${LIBCXX_DIR}/
704701
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/libcxx
705702
FILES_MATCHING PATTERN "*")
706-
install(DIRECTORY ${STDLIB_INCLUDE_DIR}/
707-
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/clang
708-
FILES_MATCHING PATTERN "*")
709703
install(DIRECTORY ${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs/
710704
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/libc-stubs
711705
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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,7 @@
561561
},
562562
"stdlib-includes": {
563563
"default": [
564-
"<mrdocs-root>/share/mrdocs/headers/libcxx",
565-
"<mrdocs-root>/share/mrdocs/headers/clang"
564+
"<mrdocs-root>/share/mrdocs/headers/libcxx"
566565
],
567566
"description": "When `use-system-stdlib` is disabled, the C++ standard library headers are available in these paths.",
568567
"items": {
@@ -602,7 +601,7 @@
602601
"type": "string"
603602
},
604603
"use-system-libc": {
605-
"default": false,
604+
"default": true,
606605
"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.",
607606
"enum": [
608607
true,
@@ -612,7 +611,7 @@
612611
"type": "boolean"
613612
},
614613
"use-system-stdlib": {
615-
"default": false,
614+
"default": true,
616615
"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.",
617616
"enum": [
618617
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

include/mrdocs/Support/Concepts.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,12 @@ concept range_of_tuple_like =
137137
std::ranges::range<Range> && tuple_like<std::ranges::range_value_t<Range>>;
138138

139139
#ifdef __cpp_lib_reference_from_temporary
140-
using std::reference_constructs_from_temporary_v;
141-
using std::reference_converts_from_temporary_v;
140+
/** True when binding `To` from `From` would require a temporary conversion.
141+
*/
142+
using std::reference_constructs_from_temporary_v;
143+
/** Like `reference_converts_from_temporary_v`, but for construction.
144+
*/
145+
using std::reference_converts_from_temporary_v;
142146
#else
143147
/** True when binding `To` from `From` would require a temporary conversion.
144148
*/

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: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,16 +528,15 @@
528528
"brief": "Use the system C++ standard library",
529529
"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.",
530530
"type": "bool",
531-
"default": false
531+
"default": true
532532
},
533533
{
534534
"name": "stdlib-includes",
535535
"brief": "C++ Standard Library include paths",
536536
"details": "When `use-system-stdlib` is disabled, the C++ standard library headers are available in these paths.",
537537
"type": "list<path>",
538538
"default": [
539-
"<mrdocs-root>/share/mrdocs/headers/libcxx",
540-
"<mrdocs-root>/share/mrdocs/headers/clang"
539+
"<mrdocs-root>/share/mrdocs/headers/libcxx"
541540
],
542541
"relative-to": "<config-dir>",
543542
"must-exist": false,
@@ -548,7 +547,7 @@
548547
"brief": "Use the system C standard library",
549548
"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.",
550549
"type": "bool",
551-
"default": false
550+
"default": true
552551
},
553552
{
554553
"name": "libc-includes",

src/lib/MrDocsCompilationDatabase.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,10 @@ adjustCommandLine(
302302
cmdLineCStrs.data(),
303303
cmdLineCStrs.data() + cmdLineCStrs.size());
304304

305-
auto const systemIncludeFlag = is_clang_cl ? "-external:I" : "-isystem";
305+
char const* systemIncludeFlag = is_clang_cl ? "-external:I" : "-isystem";
306+
// FIXME: No CL equivalent, but not really needed there?
307+
char const* afterIncludeFlag = is_clang_cl ? "-external:I" : "-idirafter";
308+
306309

307310
// ------------------------------------------------------
308311
// Supress all warnings
@@ -406,10 +409,10 @@ adjustCommandLine(
406409

407410
if (!(*config)->useSystemLibc)
408411
{
409-
new_cmdline.emplace_back("-nostdinc");
412+
new_cmdline.emplace_back(is_clang_cl ? "-X" : "-nostdlibinc");
410413
for (auto const& inc : (*config)->libcIncludes)
411414
{
412-
new_cmdline.emplace_back(systemIncludeFlag);
415+
new_cmdline.emplace_back(afterIncludeFlag);
413416
new_cmdline.emplace_back(inc);
414417
}
415418
}

0 commit comments

Comments
 (0)