Skip to content

Commit 565c485

Browse files
K-ballomizvekov
authored andcommitted
feat: use system libs by default
WIP
1 parent 4e7ef04 commit 565c485

File tree

25 files changed

+149
-78
lines changed

25 files changed

+149
-78
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: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ jobs:
9191
common-flags-base: {{#if (ieq compiler 'clang')}}-gz=zstd {{/if}}
9292
common-flags: {{{ common-flags-base }}}{{#if msan }}-fsanitize-memory-track-origins {{/if}}
9393
common-ccflags: {{{ ccflags }}} {{{ common-flags }}}
94-
mrdocs-flags: {{{ warning-flags }}}{{#if (and (eq compiler 'gcc') (not asan)) }}-static {{/if}}
94+
mrdocs-flags: {{{ warning-flags }}}
9595
mrdocs-ccflags: {{{ common-ccflags }}} {{{ mrdocs-flags }}}
9696
mrdocs-package-generators: {{#if (ieq os 'windows') }}7Z ZIP WIX{{else}}TGZ TXZ{{/if}}
9797
mrdocs-release-package-artifact: release-packages-{{{ lowercase os }}}
@@ -725,6 +725,22 @@ jobs:
725725
contents: write
726726

727727
steps:
728+
# This calculates a bunch of variables, which would normally go in to the regular matrix extra-values
729+
# section, but which depend on paths not known at that point.
730+
- name: Resolved Matrix
731+
id: rmatrix
732+
run: |
733+
set -euvx
734+
735+
third_party_dir="$(realpath $(pwd)/..)/third-party"
736+
if [[ "${{ runner.os }}" == 'Windows' ]]; then
737+
third_party_dir="$(echo "$third_party_dir" | sed 's/\\/\//g; s|^/d/|D:/|')"
738+
fi
739+
echo "third-party-dir=$third_party_dir" >> $GITHUB_OUTPUT
740+
741+
llvm_path="$third_party_dir/llvm"
742+
echo "llvm-path=$llvm_path" >> $GITHUB_OUTPUT
743+
728744
- name: Ensure Node
729745
if: matrix.container != '' && env.ACT == 'true'
730746
run: |
@@ -767,6 +783,13 @@ jobs:
767783
compiler: ${{ matrix.compiler }}
768784
version: ${{ matrix.version }}
769785

786+
- name: Cached LLVM Binaries
787+
id: llvm-cache
788+
uses: actions/cache@v4
789+
with:
790+
path: ${{ steps.rmatrix.outputs.llvm-path }}
791+
key: ${{ matrix.llvm-archive-basename }}
792+
770793
- name: Download MrDocs package
771794
uses: actions/download-artifact@v4
772795
with:
@@ -775,28 +798,29 @@ jobs:
775798

776799
- name: Install MrDocs from Package
777800
run: |
778-
set -x
779-
801+
set -euvx
802+
780803
# Delete packages/_CPack_Packages files from previous runs
781804
rm -rf packages/_CPack_Packages
782-
805+
783806
# Print tree structure
784807
find packages -print | sed 's;[^/]*/;|____;g;s;____|; |;g'
785-
808+
809+
dest_dir="${{ steps.rmatrix.outputs.llvm-path }}"
810+
786811
if [[ ${{ runner.os }} != 'Windows' ]]; then
787-
dest_dir="$HOME/local"
788-
mkdir -p "$dest_dir"
789812
find packages -maxdepth 1 -name 'MrDocs-*.tar.gz' -exec tar -vxzf {} -C $dest_dir --strip-components=1 \;
790813
else
791-
dest_dir="$GITHUB_WORKSPACE/usr/local"
792-
dest_dir=$(echo "$dest_dir" | sed 's/\\/\//g')
793-
find packages -maxdepth 1 -name "MrDocs-*.7z" -exec 7z x {} -o$dest_dir \;
794-
if [[ $(ls -1 $dest_dir | wc -l) -eq 1 ]]; then
795-
single_dir=$(ls -1 $dest_dir)
796-
if [[ -d $dest_dir/$single_dir ]]; then
797-
mv $dest_dir/$single_dir/* $dest_dir/
798-
rmdir $dest_dir/$single_dir
799-
fi
814+
package=$(find packages -maxdepth 1 -name "MrDocs-*.7z" -print -quit)
815+
filename=$(basename "$package")
816+
name="${filename%.*}"
817+
7z x "${package}" -o${dest_dir}
818+
set +e
819+
robocopy "${dest_dir}/${name}" "${dest_dir}" //move //e //np /nfl
820+
exit_code=$?
821+
set -e
822+
if (( exit_code >= 8 )); then
823+
exit 1
800824
fi
801825
fi
802826
MRDOCS_ROOT="$dest_dir"
@@ -1240,4 +1264,4 @@ jobs:
12401264
uses: actions/cache@v4
12411265
with:
12421266
path: ${{ steps.rmatrix.outputs.llvm-path }}
1243-
key: ${{ matrix.llvm-archive-basename }}
1267+
key: ${{ matrix.llvm-archive-basename }}

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})
@@ -384,6 +375,7 @@ if (WIN32)
384375
mrdocs-core
385376
PUBLIC
386377
/permissive- # strict C++
378+
/Zc:__cplusplus # report C++ standard support
387379
/W4 # enable all warnings
388380
/MP # multi-processor compilation
389381
/EHs # C++ Exception handling
@@ -407,6 +399,13 @@ if (MRDOCS_DOCUMENTATION_BUILD)
407399
return()
408400
endif()
409401

402+
# Replicate the clang resource directory structure within our own build,
403+
# so that libclang will find it when executing directly from the build directory.
404+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin")
405+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib/clang")
406+
set(RESOURCE_DIR "lib/clang/${Clang_VERSION_MAJOR}")
407+
file(CREATE_LINK "${LLVM_BINARY_DIR}/${RESOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/${RESOURCE_DIR}" SYMBOLIC)
408+
410409
#-------------------------------------------------
411410
#
412411
# Tool
@@ -484,7 +483,6 @@ if (MRDOCS_BUILD_TESTS)
484483
"--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
485484
--generator=${testgenerator}
486485
"--stdlib-includes=${LIBCXX_DIR}"
487-
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
488486
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
489487
--log-level=warn
490488
)
@@ -499,7 +497,6 @@ if (MRDOCS_BUILD_TESTS)
499497
"--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons"
500498
--generator=${testgenerator}
501499
"--stdlib-includes=${LIBCXX_DIR}"
502-
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
503500
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
504501
--log-level=warn
505502
DEPENDS mrdocs-test
@@ -697,9 +694,6 @@ if (MRDOCS_INSTALL)
697694
install(DIRECTORY ${LIBCXX_DIR}/
698695
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/libcxx
699696
FILES_MATCHING PATTERN "*")
700-
install(DIRECTORY ${STDLIB_INCLUDE_DIR}/
701-
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/clang
702-
FILES_MATCHING PATTERN "*")
703697
install(DIRECTORY ${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs/
704698
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/libc-stubs
705699
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
@@ -570,8 +570,7 @@
570570
},
571571
"stdlib-includes": {
572572
"default": [
573-
"<mrdocs-root>/share/mrdocs/headers/libcxx",
574-
"<mrdocs-root>/share/mrdocs/headers/clang"
573+
"<mrdocs-root>/share/mrdocs/headers/libcxx"
575574
],
576575
"description": "When `use-system-stdlib` is disabled, the C++ standard library headers are available in these paths.",
577576
"items": {
@@ -611,7 +610,7 @@
611610
"type": "string"
612611
},
613612
"use-system-libc": {
614-
"default": false,
613+
"default": true,
615614
"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.",
616615
"enum": [
617616
true,
@@ -621,7 +620,7 @@
621620
"type": "boolean"
622621
},
623622
"use-system-stdlib": {
624-
"default": false,
623+
"default": true,
625624
"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.",
626625
"enum": [
627626
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
@@ -2372,7 +2372,8 @@ extractSFINAEInfo(clang::QualType const T)
23722372
Result.Type = resultType->getAsType();
23732373
for (std::size_t I = 0; I < Args.size(); ++I)
23742374
{
2375-
if (SFINAEControl->ControllingParams[I])
2375+
if (I < SFINAEControl->ControllingParams.size()
2376+
&& SFINAEControl->ControllingParams[I])
23762377
{
23772378
MRDOCS_SYMBOL_TRACE(Args[I], context_);
23782379
clang::TemplateArgument ArgsI = Args[I];

src/lib/AST/ExtractDocComment.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ class DocCommentVisitor
627627
auto compsExp = parseHTMLStartSpan(C, cur);
628628
if (!compsExp)
629629
{
630-
report::error(
630+
report::warn(
631631
"{} at {} ({})",
632632
compsExp.error().message(),
633633
filename,

src/lib/ConfigOptions.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,16 +537,15 @@
537537
"brief": "Use the system C++ standard library",
538538
"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.",
539539
"type": "bool",
540-
"default": false
540+
"default": true
541541
},
542542
{
543543
"name": "stdlib-includes",
544544
"brief": "C++ Standard Library include paths",
545545
"details": "When `use-system-stdlib` is disabled, the C++ standard library headers are available in these paths.",
546546
"type": "list<path>",
547547
"default": [
548-
"<mrdocs-root>/share/mrdocs/headers/libcxx",
549-
"<mrdocs-root>/share/mrdocs/headers/clang"
548+
"<mrdocs-root>/share/mrdocs/headers/libcxx"
550549
],
551550
"relative-to": "<config-dir>",
552551
"must-exist": false,
@@ -557,7 +556,7 @@
557556
"brief": "Use the system C standard library",
558557
"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.",
559558
"type": "bool",
560-
"default": false
559+
"default": true
561560
},
562561
{
563562
"name": "libc-includes",

0 commit comments

Comments
 (0)