-
Notifications
You must be signed in to change notification settings - Fork 21
use system libs by default #1077
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,7 +91,7 @@ jobs: | |
| common-flags-base: {{#if (ieq compiler 'clang')}}-gz=zstd {{/if}} | ||
| common-flags: {{{ common-flags-base }}}{{#if msan }}-fsanitize-memory-track-origins {{/if}} | ||
| common-ccflags: {{{ ccflags }}} {{{ common-flags }}} | ||
| mrdocs-flags: {{{ warning-flags }}}{{#if (and (eq compiler 'gcc') (not asan)) }}-static {{/if}} | ||
| mrdocs-flags: {{{ warning-flags }}} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we doing that? A huge problem we have had in the past is that the Linux release, which is actually an Ubuntu release, would not work on other versions of Ubuntu unless we set that. Otherwise, it would depend on a specific version of libc, and the release would fail. Is this going to break now? |
||
| mrdocs-ccflags: {{{ common-ccflags }}} {{{ mrdocs-flags }}} | ||
| mrdocs-package-generators: {{#if (ieq os 'windows') }}7Z ZIP WIX{{else}}TGZ TXZ{{/if}} | ||
| mrdocs-release-package-artifact: release-packages-{{{ lowercase os }}} | ||
|
|
@@ -726,6 +726,26 @@ jobs: | |
| contents: write | ||
|
|
||
| steps: | ||
| # This calculates a bunch of variables, which would normally go in to the regular matrix extra-values | ||
| # section, but which depend on paths not known at that point. | ||
| - name: Resolved Matrix | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a new matrix of this kind or just code being moved? Because I remember we already had a step like that. |
||
| id: rmatrix | ||
| run: | | ||
| set -euvx | ||
|
|
||
| third_party_dir="$(realpath $(pwd)/..)/third-party" | ||
| if [[ "${{ runner.os }}" == 'Windows' ]]; then | ||
| third_party_dir="$(echo "$third_party_dir" | sed 's/\\/\//g; s|^/d/|D:/|')" | ||
| fi | ||
| echo "third-party-dir=$third_party_dir" >> $GITHUB_OUTPUT | ||
|
|
||
| llvm_path="$third_party_dir/llvm" | ||
| echo "llvm-path=$llvm_path" >> $GITHUB_OUTPUT | ||
|
|
||
| llvm_cache_key="${{ matrix.llvm-archive-basename }}" | ||
| llvm_cache_key="${llvm_cache_key//:/-}" | ||
| echo "llvm-cache-key=$llvm_cache_key" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Ensure Node | ||
| if: matrix.container != '' && env.ACT == 'true' | ||
| run: | | ||
|
|
@@ -768,6 +788,14 @@ jobs: | |
| compiler: ${{ matrix.compiler }} | ||
| version: ${{ matrix.version }} | ||
|
|
||
| - name: Cached LLVM Binaries | ||
| id: llvm-cache | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ${{ steps.rmatrix.outputs.llvm-path }} | ||
| key: ${{ steps.rmatrix.outputs.llvm-cache-key }} | ||
| fail-on-cache-miss: true | ||
|
|
||
| - name: Download MrDocs package | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
|
|
@@ -776,28 +804,29 @@ jobs: | |
|
|
||
| - name: Install MrDocs from Package | ||
| run: | | ||
| set -x | ||
| set -euvx | ||
|
|
||
| # Delete packages/_CPack_Packages files from previous runs | ||
| rm -rf packages/_CPack_Packages | ||
|
|
||
| # Print tree structure | ||
| find packages -print | sed 's;[^/]*/;|____;g;s;____|; |;g' | ||
|
|
||
|
|
||
| dest_dir="${{ steps.rmatrix.outputs.llvm-path }}" | ||
|
|
||
| if [[ ${{ runner.os }} != 'Windows' ]]; then | ||
| dest_dir="$HOME/local" | ||
| mkdir -p "$dest_dir" | ||
| find packages -maxdepth 1 -name 'MrDocs-*.tar.gz' -exec tar -vxzf {} -C $dest_dir --strip-components=1 \; | ||
| else | ||
| dest_dir="$GITHUB_WORKSPACE/usr/local" | ||
| dest_dir=$(echo "$dest_dir" | sed 's/\\/\//g') | ||
| find packages -maxdepth 1 -name "MrDocs-*.7z" -exec 7z x {} -o$dest_dir \; | ||
| if [[ $(ls -1 $dest_dir | wc -l) -eq 1 ]]; then | ||
| single_dir=$(ls -1 $dest_dir) | ||
| if [[ -d $dest_dir/$single_dir ]]; then | ||
| mv $dest_dir/$single_dir/* $dest_dir/ | ||
| rmdir $dest_dir/$single_dir | ||
| fi | ||
| package=$(find packages -maxdepth 1 -name "MrDocs-*.7z" -print -quit) | ||
| filename=$(basename "$package") | ||
| name="${filename%.*}" | ||
| 7z x "${package}" -o${dest_dir} | ||
| set +e | ||
| robocopy "${dest_dir}/${name}" "${dest_dir}" //move //e //np //nfl | ||
| exit_code=$? | ||
| set -e | ||
| if (( exit_code >= 8 )); then | ||
| exit 1 | ||
| fi | ||
| fi | ||
| MRDOCS_ROOT="$dest_dir" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -261,15 +261,6 @@ if (NOT EXISTS "${LIBCXX_DIR}") | |
| "Please provide a LLVM with libc++ enabled\n") | ||
| endif() | ||
|
|
||
| set(STDLIB_INCLUDE_DIR "${LLVM_BINARY_DIR}/lib/clang/${Clang_VERSION_MAJOR}/include" | ||
| CACHE PATH "Path to the clang headers include directory") | ||
| message(STATUS "STDLIB_INCLUDE_DIR: ${STDLIB_INCLUDE_DIR}") | ||
| if (NOT EXISTS "${STDLIB_INCLUDE_DIR}") | ||
| message(FATAL_ERROR | ||
| "STDLIB_INCLUDE_DIR (${STDLIB_INCLUDE_DIR}) does not exist.\n" | ||
| "Missing clang headers\n") | ||
| endif() | ||
|
|
||
| list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}") | ||
| include(HandleLLVMOptions) | ||
| add_definitions(${LLVM_DEFINITIONS}) | ||
|
|
@@ -384,6 +375,7 @@ if (WIN32) | |
| mrdocs-core | ||
| PUBLIC | ||
| /permissive- # strict C++ | ||
| /Zc:__cplusplus # report C++ standard support | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does that do? |
||
| /W4 # enable all warnings | ||
| /MP # multi-processor compilation | ||
| /EHs # C++ Exception handling | ||
|
|
@@ -407,6 +399,15 @@ if (MRDOCS_DOCUMENTATION_BUILD) | |
| return() | ||
| endif() | ||
|
|
||
| # Replicate the clang resource directory structure within our own build, | ||
| # so that libclang will find it when executing directly from the build directory. | ||
| # The installed binary will use runtime path resolution to locate the resource directory | ||
| # relative to the executable, so both LLVM and MrDocs must be installed to the same prefix. | ||
| set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin") | ||
| file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/lib/clang") | ||
| set(RESOURCE_DIR "lib/clang/${Clang_VERSION_MAJOR}") | ||
| file(CREATE_LINK "${LLVM_BINARY_DIR}/${RESOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/${RESOURCE_DIR}" SYMBOLIC) | ||
|
|
||
| #------------------------------------------------- | ||
| # | ||
| # Tool | ||
|
|
@@ -484,7 +485,6 @@ if (MRDOCS_BUILD_TESTS) | |
| "--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons" | ||
| --generator=${testgenerator} | ||
| "--stdlib-includes=${LIBCXX_DIR}" | ||
| "--stdlib-includes=${STDLIB_INCLUDE_DIR}" | ||
| "--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs" | ||
| --log-level=warn | ||
| ) | ||
|
|
@@ -499,7 +499,6 @@ if (MRDOCS_BUILD_TESTS) | |
| "--addons=${CMAKE_SOURCE_DIR}/share/mrdocs/addons" | ||
| --generator=${testgenerator} | ||
| "--stdlib-includes=${LIBCXX_DIR}" | ||
| "--stdlib-includes=${STDLIB_INCLUDE_DIR}" | ||
| "--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs" | ||
| --log-level=warn | ||
| DEPENDS mrdocs-test | ||
|
|
@@ -697,9 +696,6 @@ if (MRDOCS_INSTALL) | |
| install(DIRECTORY ${LIBCXX_DIR}/ | ||
| DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/libcxx | ||
| FILES_MATCHING PATTERN "*") | ||
| install(DIRECTORY ${STDLIB_INCLUDE_DIR}/ | ||
| DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/clang | ||
| FILES_MATCHING PATTERN "*") | ||
| install(DIRECTORY ${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs/ | ||
| DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/libc-stubs | ||
| FILES_MATCHING PATTERN "*") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -278,7 +278,7 @@ It's also common for libraries to depend on the C++ standard library, the C stan | |
|
|
||
| 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. | ||
|
|
||
| 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++ -nostdlib++` and `-nostdinc` flags were passed to Clang. Additionally: | ||
| 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++ -nostdlib++` and `-nostdinc` flags were passed to Clang. Additionally: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch. It's quite hard to remember to fix those details in the documentation. :) |
||
|
|
||
| - When `use-system-stdlib` is `false`, MrDocs will use the bundled libc++ 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. | ||
| - 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. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -570,8 +570,7 @@ | |
| }, | ||
| "stdlib-includes": { | ||
| "default": [ | ||
| "<mrdocs-root>/share/mrdocs/headers/libcxx", | ||
| "<mrdocs-root>/share/mrdocs/headers/clang" | ||
| "<mrdocs-root>/share/mrdocs/headers/libcxx" | ||
| ], | ||
| "description": "When `use-system-stdlib` is disabled, the C++ standard library headers are available in these paths.", | ||
| "items": { | ||
|
|
@@ -611,7 +610,7 @@ | |
| "type": "string" | ||
| }, | ||
| "use-system-libc": { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this option be called something else? Because it seems like the other option does relate to the C++ standard library, but it seems like this option is just about making the typical system paths available by default and not the C standard library in particular. |
||
| "default": false, | ||
| "default": true, | ||
| "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.", | ||
| "enum": [ | ||
| true, | ||
|
|
@@ -621,7 +620,7 @@ | |
| "type": "boolean" | ||
| }, | ||
| "use-system-stdlib": { | ||
| "default": false, | ||
| "default": true, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, that's the default behavior for Windows and Linux, while the opposite would be the default behavior on MacOS, right? |
||
| "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.", | ||
| "enum": [ | ||
| true, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| #include <type_traits> | ||
| #include <stdexcept> | ||
|
|
||
| /** Computes the square root of an integral value. | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -302,7 +302,10 @@ adjustCommandLine( | |
| cmdLineCStrs.data(), | ||
| cmdLineCStrs.data() + cmdLineCStrs.size()); | ||
|
|
||
| auto const systemIncludeFlag = is_clang_cl ? "-external:I" : "-isystem"; | ||
| char const* systemIncludeFlag = is_clang_cl ? "-external:I" : "-isystem"; | ||
| // FIXME: No CL equivalent, but not really needed there? | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand this comment. It's quite weird to have new code that already has a fix me comment, especially when it's a single line of code. 😅 Maybe it's more about a limitation than something to be fixed. I'm not sure because I'm not completely sure I understand the problem that needs to be fixed here. If there is no CL equivalent, but it works for CL, maybe it's not needed, right? Or can't we just ensure it's included at the end by ourselves? 🙂 |
||
| char const* afterIncludeFlag = is_clang_cl ? "-external:I" : "-idirafter"; | ||
|
|
||
|
|
||
| // ------------------------------------------------------ | ||
| // Supress all warnings | ||
|
|
@@ -406,10 +409,10 @@ adjustCommandLine( | |
|
|
||
| if (!(*config)->useSystemLibc) | ||
| { | ||
| new_cmdline.emplace_back("-nostdinc"); | ||
| new_cmdline.emplace_back(is_clang_cl ? "-X" : "-nostdlibinc"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we put all this logic about what the arguments look like in a single place? For some flags, we're doing it at the beginning and already calculating what the arguments look like. For some other flags, we're doing it in-line. |
||
| for (auto const& inc : (*config)->libcIncludes) | ||
| { | ||
| new_cmdline.emplace_back(systemIncludeFlag); | ||
| new_cmdline.emplace_back(afterIncludeFlag); | ||
| new_cmdline.emplace_back(inc); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These kinds of changes can go in
style: *commits.