Skip to content

Commit 509a9dc

Browse files
committed
feat: use-system-libc option
fix cppalliance#731
1 parent e47b824 commit 509a9dc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3879
-60
lines changed

Diff for: CMakeLists.txt

+8-3
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ if (MRDOCS_BUILD_TESTS)
391391
--generate=${testgenerator}
392392
"--stdlib-includes=${LIBCXX_DIR}"
393393
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
394+
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
394395
--report=2
395396
)
396397
foreach (action IN ITEMS test create update)
@@ -405,6 +406,7 @@ if (MRDOCS_BUILD_TESTS)
405406
--generate=${testgenerator}
406407
"--stdlib-includes=${LIBCXX_DIR}"
407408
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
409+
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
408410
--report=2
409411
DEPENDS mrdocs-test
410412
)
@@ -553,12 +555,15 @@ if (MRDOCS_INSTALL)
553555
# share
554556
#-------------------------------------------------
555557
install(DIRECTORY ${LIBCXX_DIR}
556-
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/libcxx
558+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/libcxx
557559
FILES_MATCHING PATTERN "*")
558560
install(DIRECTORY ${STDLIB_INCLUDE_DIR}
559-
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/clang
561+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/clang
560562
FILES_MATCHING PATTERN "*")
561-
563+
install(DIRECTORY ${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs/
564+
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/libc-stubs
565+
FILES_MATCHING PATTERN "*")
566+
562567
foreach (share_mrdocs_dir addons)
563568
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/share/mrdocs/${share_mrdocs_dir}
564569
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs

Diff for: docs/mrdocs.schema.json

+23-6
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,17 @@
179179
"title": "Use legible names",
180180
"type": "boolean"
181181
},
182+
"libc-includes": {
183+
"default": [
184+
"<mrdocs-root>/share/mrdocs/headers/libc-stubs"
185+
],
186+
"description": "When `use-system-libc` is disabled, the C standard library headers are available in these paths.",
187+
"items": {
188+
"type": "string"
189+
},
190+
"title": "Standard Library include paths",
191+
"type": "array"
192+
},
182193
"multipage": {
183194
"default": true,
184195
"description": "Generates a multipage documentation. The output directory must be a directory. This option acts as a hint to the generator to create a multipage documentation. Whether the hint is followed or not depends on the generator.",
@@ -225,14 +236,14 @@
225236
},
226237
"stdlib-includes": {
227238
"default": [
228-
"<mrdocs-root>/share/mrdocs/libcxx",
229-
"<mrdocs-root>/share/mrdocs/clang"
239+
"<mrdocs-root>/share/mrdocs/headers/libcxx",
240+
"<mrdocs-root>/share/mrdocs/headers/clang"
230241
],
231-
"description": "Standard Library include paths. These paths are used to replace the standard library paths provided by the compiler.",
242+
"description": "When `use-system-stdlib` is disabled, the C++ standard library headers are available in these paths.",
232243
"items": {
233244
"type": "string"
234245
},
235-
"title": "Standard Library include paths",
246+
"title": "C++ Standard Library include paths",
236247
"type": "array"
237248
},
238249
"system-includes": {
@@ -250,10 +261,16 @@
250261
"title": "Path for the tagfile",
251262
"type": "string"
252263
},
264+
"use-system-libc": {
265+
"default": false,
266+
"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.",
267+
"title": "Use the system C standard library",
268+
"type": "boolean"
269+
},
253270
"use-system-stdlib": {
254271
"default": false,
255-
"description": "True if the compiler has to use just the system standard library. When set to true, the compiler uses the system standard library instead of the standard library provided by the compiler.",
256-
"title": "Use the system standard library",
272+
"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.",
273+
"title": "Use the system C++ standard library",
257274
"type": "boolean"
258275
},
259276
"verbose": {

Diff for: share/mrdocs/addons/generator/adoc/partials/symbol.adoc.hbs

+5-5
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898

9999
{{#each symbol.doc.exceptions}}
100100
| `{{exception}}`
101-
| {{description}}
101+
| {{{description}}}
102102
{{/each}}
103103
|===
104104

@@ -137,7 +137,7 @@
137137

138138
{{#each symbol.doc.tparams}}
139139
| *{{name}}*
140-
| {{description}}
140+
| {{{description}}}
141141
{{/each}}
142142
|===
143143

@@ -152,7 +152,7 @@
152152

153153
{{#each allTParams as |param|}}
154154
| *{{param.name}}*
155-
| {{param.description}}
155+
| {{{param.description}}}
156156
{{/each}}
157157
|===
158158

@@ -169,7 +169,7 @@
169169

170170
{{#each symbol.doc.params}}
171171
| *{{name}}*
172-
| {{description}}
172+
| {{{description}}}
173173
{{/each}}
174174
|===
175175

@@ -184,7 +184,7 @@
184184

185185
{{#each allParams as |param|}}
186186
| *{{param.name}}*
187-
| {{param.description}}
187+
| {{{param.description}}}
188188
{{/each}}
189189
|===
190190

Diff for: share/mrdocs/headers/libc-stubs/assert.h

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2024 Alan de Freitas ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdocs
9+
//
10+
11+
#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_ASSERT_H
12+
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_ASSERT_H
13+
14+
#define assert(...) ((void)0)
15+
16+
#endif // MRDOCS_SHARE_HEADERS_LIBC_STUBS_ASSERT_H

Diff for: share/mrdocs/headers/libc-stubs/complex.h

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2024 Alan de Freitas ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdocs
9+
//
10+
11+
#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_COMPLEX_H
12+
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_COMPLEX_H
13+
14+
// Types
15+
#define imaginary _Imaginary
16+
#define complex _Complex
17+
18+
// Constants
19+
#define _Imaginary_I ((float _Imaginary)1.0)
20+
#define _Complex_I ((float _Complex)1.0)
21+
#define I _Complex_I
22+
23+
// Manipulation
24+
#define CMPLX(x, y) ((double _Complex)((x) + _Complex_I * (y)))
25+
#define CMPLXF(x, y) ((float _Complex)((x) + _Complex_I * (y)))
26+
#define CMPLXL(x, y) ((long double _Complex)((x) + _Complex_I * (y)))
27+
28+
double creal(double _Complex z);
29+
float crealf(float _Complex z);
30+
long double creall(long double _Complex z);
31+
32+
double cimag(double _Complex z);
33+
float cimagf(float _Complex z);
34+
long double cimagl(long double _Complex z);
35+
36+
double cabs(double _Complex z);
37+
float cabsf(float _Complex z);
38+
long double cabsl(long double _Complex z);
39+
40+
double carg(double _Complex z);
41+
float cargf(float _Complex z);
42+
long double cargl(long double _Complex z);
43+
44+
double _Complex conj(double _Complex z);
45+
float _Complex conjf(float _Complex z);
46+
long double _Complex conjl(long double _Complex z);
47+
48+
double _Complex cproj(double _Complex z);
49+
float _Complex cprojf(float _Complex z);
50+
long double _Complex cprojl(long double _Complex z);
51+
52+
// Exponential functions
53+
double _Complex cexp(double _Complex z);
54+
float _Complex cexpf(float _Complex z);
55+
long double _Complex cexpl(long double _Complex z);
56+
57+
double _Complex clog(double _Complex z);
58+
float _Complex clogf(float _Complex z);
59+
long double _Complex clogl(long double _Complex z);
60+
61+
// Power functions
62+
double _Complex cpow(double _Complex x, double _Complex y);
63+
float _Complex cpowf(float _Complex x, float _Complex y);
64+
long double _Complex cpowl(long double _Complex x, long double _Complex y);
65+
66+
double _Complex csqrt(double _Complex z);
67+
float _Complex csqrtf(float _Complex z);
68+
long double _Complex csqrtl(long double _Complex z);
69+
70+
// Trigonometric functions
71+
double _Complex csin(double _Complex z);
72+
float _Complex csinf(float _Complex z);
73+
long double _Complex csinl(long double _Complex z);
74+
75+
double _Complex ccos(double _Complex z);
76+
float _Complex ccosf(float _Complex z);
77+
long double _Complex ccosl(long double _Complex z);
78+
79+
double _Complex ctan(double _Complex z);
80+
float _Complex ctanf(float _Complex z);
81+
long double _Complex ctanl(long double _Complex z);
82+
83+
double _Complex casin(double _Complex z);
84+
float _Complex casinf(float _Complex z);
85+
long double _Complex casinl(long double _Complex z);
86+
87+
double _Complex cacos(double _Complex z);
88+
float _Complex cacosf(float _Complex z);
89+
long double _Complex cacosl(long double _Complex z);
90+
91+
double _Complex catan(double _Complex z);
92+
float _Complex catanf(float _Complex z);
93+
long double _Complex catanl(long double _Complex z);
94+
95+
// Hyperbolic functions
96+
double _Complex csinh(double _Complex z);
97+
float _Complex csinhf(float _Complex z);
98+
long double _Complex csinhl(long double _Complex z);
99+
100+
double _Complex ccosh(double _Complex z);
101+
float _Complex ccoshf(float _Complex z);
102+
long double _Complex ccoshl(long double _Complex z);
103+
104+
double _Complex ctanh(double _Complex z);
105+
float _Complex ctanhf(float _Complex z);
106+
long double _Complex ctanhl(long double _Complex z);
107+
108+
double _Complex casinh(double _Complex z);
109+
float _Complex casinhf(float _Complex z);
110+
long double _Complex casinhl(long double _Complex z);
111+
112+
double _Complex cacosh(double _Complex z);
113+
float _Complex cacoshf(float _Complex z);
114+
long double _Complex cacoshl(long double _Complex z);
115+
116+
double _Complex catanh(double _Complex z);
117+
float _Complex catanhf(float _Complex z);
118+
long double _Complex catanhl(long double _Complex z);
119+
120+
#endif // MRDOCS_SHARE_HEADERS_LIBC_STUBS_COMPLEX_H

Diff for: share/mrdocs/headers/libc-stubs/ctype.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2024 Alan de Freitas ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdocs
9+
//
10+
11+
#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_CTYPE_H
12+
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_CTYPE_H
13+
14+
// Character classification
15+
int isalnum( int ch );
16+
int isalpha( int ch );
17+
int islower( int ch );
18+
int isupper( int ch );
19+
int isdigit( int ch );
20+
int isxdigit( int ch );
21+
int iscntrl( int ch );
22+
int isgraph( int ch );
23+
int isspace( int ch );
24+
int isblank( int ch );
25+
int isprint( int ch );
26+
int ispunct( int ch );
27+
28+
// Character manipulation
29+
int tolower( int ch );
30+
int toupper( int ch );
31+
32+
#endif // MRDOCS_SHARE_HEADERS_LIBC_STUBS_CTYPE_H

Diff for: share/mrdocs/headers/libc-stubs/errno.h

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2024 Alan de Freitas ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdocs
9+
//
10+
11+
#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_ERRNO_H
12+
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_ERRNO_H
13+
14+
#include "stddef.h"
15+
16+
// Define errno as a thread-local variable
17+
#ifdef __cplusplus
18+
extern "C" {
19+
#endif
20+
21+
// Thread-local storage for errno
22+
extern __thread errno_t __errno;
23+
24+
#ifdef __cplusplus
25+
}
26+
#endif
27+
28+
// Error codes
29+
#define EDOM 1
30+
#define ERANGE 2
31+
#define EILSEQ 3
32+
33+
#define errno (__errno)
34+
35+
#endif // MRDOCS_SHARE_HEADERS_LIBC_STUBS_ERRNO_H

Diff for: share/mrdocs/headers/libc-stubs/fenv.h

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//
2+
// Licensed under the Apache License v2.0 with LLVM Exceptions.
3+
// See https://llvm.org/LICENSE.txt for license information.
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
//
6+
// Copyright (c) 2024 Alan de Freitas ([email protected])
7+
//
8+
// Official repository: https://github.com/cppalliance/mrdocs
9+
//
10+
11+
#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_FENV_H
12+
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_FENV_H
13+
14+
// Types
15+
typedef struct {
16+
unsigned int __control_word;
17+
unsigned int __status_word;
18+
unsigned int __tag_word;
19+
unsigned int __other_flags;
20+
} fenv_t;
21+
22+
typedef unsigned int fexcept_t;
23+
24+
// Functions
25+
int feclearexcept(int excepts);
26+
int fetestexcept(int excepts);
27+
int feraiseexcept(int excepts);
28+
int fegetexceptflag(fexcept_t* flagp, int excepts);
29+
int fesetexceptflag(const fexcept_t* flagp, int excepts);
30+
int fegetround(void);
31+
int fesetround(int round);
32+
int fegetenv(fenv_t* envp);
33+
int fesetenv(const fenv_t* envp);
34+
int feholdexcept(fenv_t* envp);
35+
int feupdateenv(const fenv_t* envp);
36+
37+
// Macros for floating-point exceptions
38+
#define FE_ALL_EXCEPT 0x3F
39+
#define FE_DIVBYZERO 0x04
40+
#define FE_INEXACT 0x20
41+
#define FE_INVALID 0x01
42+
#define FE_OVERFLOW 0x08
43+
#define FE_UNDERFLOW 0x10
44+
45+
// Macros for floating-point rounding direction
46+
#define FE_DOWNWARD 0x400
47+
#define FE_TONEAREST 0x000
48+
#define FE_TOWARDZERO 0xC00
49+
#define FE_UPWARD 0x800
50+
51+
// Default floating-point environment
52+
extern const fenv_t* FE_DFL_ENV;
53+
54+
#endif // MRDOCS_SHARE_HEADERS_LIBC_STUBS_FENV_H

0 commit comments

Comments
 (0)