Skip to content

Commit bb8d10e

Browse files
K-ballomizvekov
authored andcommitted
feat: use system libs by default
WIP
1 parent 240921d commit bb8d10e

File tree

24 files changed

+135
-68
lines changed

24 files changed

+135
-68
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: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
common-flags-base: {{#if (ieq compiler 'clang')}}-gz=zstd {{/if}}
9696
common-flags: {{{ common-flags-base }}}{{#if msan }}-fsanitize-memory-track-origins {{/if}}
9797
common-ccflags: {{{ ccflags }}} {{{ common-flags }}}
98-
mrdocs-flags: {{{ warning-flags }}}{{#if (and (eq compiler 'gcc') (not asan)) }}-static {{/if}}
98+
mrdocs-flags: {{{ warning-flags }}}
9999
mrdocs-ccflags: {{{ common-ccflags }}} {{{ mrdocs-flags }}}
100100
mrdocs-package-generators: {{#if (ieq os 'windows') }}7Z ZIP WIX{{else}}TGZ TXZ{{/if}}
101101
mrdocs-release-package-artifact: release-packages-{{{ lowercase os }}}
@@ -287,7 +287,7 @@ jobs:
287287
# section, but which depend on paths not known at that point.
288288
- name: Resolved Matrix
289289
id: rmatrix
290-
run: |
290+
run: |
291291
set -euvx
292292
293293
third_party_dir="$(realpath $(pwd)/..)/third-party"
@@ -556,8 +556,7 @@ jobs:
556556
- name: CMake Workflow
557557
uses: alandefreitas/cpp-actions/[email protected]
558558
env:
559-
# Bump per-test timeout on Windows to avoid CTest default (1500s) killing slow golden suites.
560-
CTEST_TEST_TIMEOUT: ${{ runner.os == 'Windows' && '3600' || '' }}
559+
CTEST_TEST_TIMEOUT: 3600
561560
with:
562561
cmake-version: '>=3.26'
563562
cxxstd: ${{ matrix.cxxstd }}
@@ -736,6 +735,22 @@ jobs:
736735
contents: write
737736

738737
steps:
738+
# This calculates a bunch of variables, which would normally go in to the regular matrix extra-values
739+
# section, but which depend on paths not known at that point.
740+
- name: Resolved Matrix
741+
id: rmatrix
742+
run: |
743+
set -euvx
744+
745+
third_party_dir="$(realpath $(pwd)/..)/third-party"
746+
if [[ "${{ runner.os }}" == 'Windows' ]]; then
747+
third_party_dir="$(echo "$third_party_dir" | sed 's/\\/\//g; s|^/d/|D:/|')"
748+
fi
749+
echo "third-party-dir=$third_party_dir" >> $GITHUB_OUTPUT
750+
751+
llvm_path="$third_party_dir/llvm"
752+
echo "llvm-path=$llvm_path" >> $GITHUB_OUTPUT
753+
739754
- name: Ensure Node
740755
if: matrix.container != '' && env.ACT == 'true'
741756
run: |
@@ -778,6 +793,13 @@ jobs:
778793
compiler: ${{ matrix.compiler }}
779794
version: ${{ matrix.version }}
780795

796+
- name: Cached LLVM Binaries
797+
id: llvm-cache
798+
uses: actions/cache@v4
799+
with:
800+
path: ${{ steps.rmatrix.outputs.llvm-path }}
801+
key: ${{ matrix.llvm-archive-basename }}
802+
781803
- name: Download MrDocs package
782804
uses: actions/download-artifact@v4
783805
with:
@@ -794,13 +816,11 @@ jobs:
794816
# Print tree structure
795817
find packages -print | sed 's;[^/]*/;|____;g;s;____|; |;g'
796818
819+
dest_dir="${{ steps.rmatrix.outputs.llvm-path }}"
820+
797821
if [[ ${{ runner.os }} != 'Windows' ]]; then
798-
dest_dir="$HOME/local"
799-
mkdir -p "$dest_dir"
800822
find packages -maxdepth 1 -name 'MrDocs-*.tar.gz' -exec tar -vxzf {} -C $dest_dir --strip-components=1 \;
801823
else
802-
dest_dir="$GITHUB_WORKSPACE/usr/local"
803-
dest_dir=$(echo "$dest_dir" | sed 's/\\/\//g')
804824
find packages -maxdepth 1 -name "MrDocs-*.7z" -exec 7z x {} -o$dest_dir \;
805825
if [[ $(ls -1 $dest_dir | wc -l) -eq 1 ]]; then
806826
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
@@ -2379,7 +2379,8 @@ extractSFINAEInfo(clang::QualType const T)
23792379
Result.Type = resultType->getAsType();
23802380
for (std::size_t I = 0; I < Args.size(); ++I)
23812381
{
2382-
if (SFINAEControl->ControllingParams[I])
2382+
if (I < SFINAEControl->ControllingParams.size()
2383+
&& SFINAEControl->ControllingParams[I])
23832384
{
23842385
MRDOCS_SYMBOL_TRACE(Args[I], context_);
23852386
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)