Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,6 @@ if (MRDOCS_BUILD_TESTS)
"${PROJECT_SOURCE_DIR}/test-files/golden-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
)
foreach (action IN ITEMS test create update)
Expand All @@ -498,9 +495,6 @@ if (MRDOCS_BUILD_TESTS)
"${PROJECT_SOURCE_DIR}/test-files/golden-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
)
Expand Down Expand Up @@ -656,16 +650,6 @@ if (MRDOCS_INSTALL)
#-------------------------------------------------
# share
#-------------------------------------------------
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 "*")

foreach (share_mrdocs_dir addons)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/share/mrdocs/${share_mrdocs_dir}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs
Expand Down
3 changes: 0 additions & 3 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -2225,9 +2225,6 @@ def generate_run_configs(self):
f'--action={verb}',
f'--generator={generator}',
f'--addons={os.path.join(self.options.mrdocs_src_dir, "share", "mrdocs", "addons")}',
f'--stdlib-includes={os.path.join(self.options.llvm_install_dir, "include", "c++", "v1")}',
f'--stdlib-includes={self.find_latest_clang_include_dir()}',
f'--libc-includes={os.path.join(self.options.mrdocs_src_dir, "share", "mrdocs", "headers", "libc-stubs")}',
'--log-level=warn'
]
})
Expand Down
28 changes: 0 additions & 28 deletions docs/modules/ROOT/pages/usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -269,34 +269,6 @@ cmake: '-D BOOST_ROOT=/path/to/boost'

Another option supported by CMake is to set the `BOOST_ROOT` environment variable as `/path/to/boost` before running MrDocs.

=== System dependencies

It's also common for libraries to depend on the C++ standard library, the C standard library, or other system libraries. These dependencies are usually resolved by the compiler and are not explicitly specified in the source code:

* The {cpp} standard library: The compiler will look for specific paths according to the `-stdlib` option and include them as implicit `-isystem` paths. For instance, Clang can use different implementations of the {cpp} standard library. By default, that's Microsoft STL on Windows, libstdc++ on Linux and libc++ otherwise. This can be disabled with `-nostdinc++ -nostdlib++` or, in MrDocs, with `use-system-stdlib=false`.
* The C standard library (and system libraries): Unlike with libc++, LLVM+Clang does not provide an implementation of the C standard library. It always depends on the system for that. The compiler will not look for specific paths but implicitly include all system libraries. This can be disabled with `-nostdinc` or, in MrDocs, with `use-system-libc=false`.

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&plus;&plus; -nostdlib&plus;&plus;` and `-nostdinc` flags were passed to Clang. Additionally:

- 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.
- 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.

The rationale for that is reproducibility. You want to be able to build your documentation and don't want it to stop working because the platform or some platform details have changed.
These default values also help avoid conflicts where the same symbol or header is defined twice if the compilation database includes system paths relevant to one specific compiler. That can breaks things when MrDocs attempts to compile it with clang.
In other words, MrDocs becomes a sandboxed environment where only the C and C++ standard libraries are available.

The default values described above work for most libraries and applications that only depend on the C and C++ standard libraries. When there are no dependencies outside the standard libraries, the user probably won't even notice the difference between these options.

However, if you depend on other system libraries, that means you need to handle these dependencies explicitly. For instance, this is very common with networking libraries. There are a few solutions to this, and these solutions are in a continuum regarding the use of `use-system-stdlib`/`use-system-libc` and the design of the code:

1. Depending on the design of your library, you can implement a different path for MrDocs where you don't need these system headers. System headers are often guarded by macros to detect the platform: for instance, `&lowbar;&lowbar;linux&lowbar;&lowbar;` for `<linux/version.h>` and `&lowbar;WIN32` for `<Windows.h>`. You can use the `&lowbar;&lowbar;MRDOCS&lowbar;&lowbar;` macro to provide an implementation for MrDocs. This implementation would typically include stubs for the symbols you need in the documentation. Because symbols from system libraries are typically not exposed in the public API of your library, that gives you replacements that make sense for the documentation. However, this solution is not enough when other dependencies also depend on these system libraries.
2. Handle it as an explicit dependency. Explicitly include the paths you need in your compilation database as if it's a dependency described in the <<dependencies>> section. For instance, you can get CMake to explicitly find `<linux/version.h>` or `<Windows.h>` and only include those directories with `-isystem` or `-I` in the compilation database.
3. Enable `use-system-libc`. MrDocs will still use the bundled libc&plus;&plus; for the C&plus;&plus; standard library, and use the system headers for the C standard library, making all system paths available. That makes system headers such as `<linux/version.h>` or `<Windows.h>` available by default. The trade-off is losing the reproducibility guarantees described above.

The first option in this list provides the most control and the most reproducibility. The third option is the most convenient but also the most fragile.

[#missing-includes]
=== Missing includes

Expand Down
43 changes: 0 additions & 43 deletions docs/mrdocs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,17 +320,6 @@
"title": "Use legible names",
"type": "boolean"
},
"libc-includes": {
"default": [
"<mrdocs-root>/share/mrdocs/headers/libc-stubs"
],
"description": "When `use-system-libc` is disabled, the C standard library headers are available in these paths.",
"items": {
"type": "string"
},
"title": "Standard Library include paths",
"type": "array"
},
"log-level": {
"default": "info",
"description": "The reporting level determines the amount of information displayed during the generation of the documentation.",
Expand Down Expand Up @@ -519,18 +508,6 @@
"title": "Path to the root directory of the source code",
"type": "string"
},
"stdlib-includes": {
"default": [
"<mrdocs-root>/share/mrdocs/headers/libcxx",
"<mrdocs-root>/share/mrdocs/headers/clang"
],
"description": "When `use-system-stdlib` is disabled, the C++ standard library headers are available in these paths.",
"items": {
"type": "string"
},
"title": "C++ Standard Library include paths",
"type": "array"
},
"system-includes": {
"default": [],
"description": "System include paths. These paths are used to add directories to the system include search path. The system include search path is used to search for system headers. The system headers are headers that are provided by the system and are not part of the project. The system headers are used to provide the standard library headers and other system headers. The system headers are not part of the project and are not checked for warnings and errors.",
Expand All @@ -546,26 +523,6 @@
"title": "Path for the tagfile",
"type": "string"
},
"use-system-libc": {
"default": false,
"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,
false
],
"title": "Use the system C standard library",
"type": "boolean"
},
"use-system-stdlib": {
"default": false,
"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,
false
],
"title": "Use the system C++ standard library",
"type": "boolean"
},
"verbose": {
"default": false,
"description": "Verbose output. When set to true, MrDocs outputs additional information during the generation of the documentation.",
Expand Down
16 changes: 0 additions & 16 deletions share/mrdocs/headers/libc-stubs/assert.h

This file was deleted.

120 changes: 0 additions & 120 deletions share/mrdocs/headers/libc-stubs/complex.h

This file was deleted.

32 changes: 0 additions & 32 deletions share/mrdocs/headers/libc-stubs/ctype.h

This file was deleted.

35 changes: 0 additions & 35 deletions share/mrdocs/headers/libc-stubs/errno.h

This file was deleted.

Loading
Loading