Skip to content

Commit

Permalink
feat: use-system-libc option
Browse files Browse the repository at this point in the history
  • Loading branch information
alandefreitas committed Dec 15, 2024
1 parent e47b824 commit f99d262
Show file tree
Hide file tree
Showing 53 changed files with 3,769 additions and 60 deletions.
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ if (MRDOCS_BUILD_TESTS)
--generate=${testgenerator}
"--stdlib-includes=${LIBCXX_DIR}"
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
--report=2
)
foreach (action IN ITEMS test create update)
Expand All @@ -405,6 +406,7 @@ if (MRDOCS_BUILD_TESTS)
--generate=${testgenerator}
"--stdlib-includes=${LIBCXX_DIR}"
"--stdlib-includes=${STDLIB_INCLUDE_DIR}"
"--libc-includes=${CMAKE_SOURCE_DIR}/share/mrdocs/headers/libc-stubs"
--report=2
DEPENDS mrdocs-test
)
Expand Down Expand Up @@ -553,12 +555,15 @@ if (MRDOCS_INSTALL)
# share
#-------------------------------------------------
install(DIRECTORY ${LIBCXX_DIR}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/libcxx
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/headers/libcxx
FILES_MATCHING PATTERN "*")
install(DIRECTORY ${STDLIB_INCLUDE_DIR}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/mrdocs/clang
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
29 changes: 23 additions & 6 deletions docs/mrdocs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@
"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"
},
"multipage": {
"default": true,
"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.",
Expand Down Expand Up @@ -225,14 +236,14 @@
},
"stdlib-includes": {
"default": [
"<mrdocs-root>/share/mrdocs/libcxx",
"<mrdocs-root>/share/mrdocs/clang"
"<mrdocs-root>/share/mrdocs/headers/libcxx",
"<mrdocs-root>/share/mrdocs/headers/clang"
],
"description": "Standard Library include paths. These paths are used to replace the standard library paths provided by the compiler.",
"description": "When `use-system-stdlib` is disabled, the C++ standard library headers are available in these paths.",
"items": {
"type": "string"
},
"title": "Standard Library include paths",
"title": "C++ Standard Library include paths",
"type": "array"
},
"system-includes": {
Expand All @@ -250,10 +261,16 @@
"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.",
"title": "Use the system C standard library",
"type": "boolean"
},
"use-system-stdlib": {
"default": false,
"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.",
"title": "Use the system standard library",
"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.",
"title": "Use the system C++ standard library",
"type": "boolean"
},
"verbose": {
Expand Down
10 changes: 5 additions & 5 deletions share/mrdocs/addons/generator/adoc/partials/symbol.adoc.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@

{{#each symbol.doc.exceptions}}
| `{{exception}}`
| {{description}}
| {{{description}}}
{{/each}}
|===

Expand Down Expand Up @@ -137,7 +137,7 @@

{{#each symbol.doc.tparams}}
| *{{name}}*
| {{description}}
| {{{description}}}
{{/each}}
|===

Expand All @@ -152,7 +152,7 @@

{{#each allTParams as |param|}}
| *{{param.name}}*
| {{param.description}}
| {{{param.description}}}
{{/each}}
|===

Expand All @@ -169,7 +169,7 @@

{{#each symbol.doc.params}}
| *{{name}}*
| {{description}}
| {{{description}}}
{{/each}}
|===

Expand All @@ -184,7 +184,7 @@

{{#each allParams as |param|}}
| *{{param.name}}*
| {{param.description}}
| {{{param.description}}}
{{/each}}
|===

Expand Down
16 changes: 16 additions & 0 deletions share/mrdocs/headers/libc-stubs/assert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2024 Alan de Freitas ([email protected])
//
// Official repository: https://github.com/cppalliance/mrdocs
//

#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_ASSERT_H
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_ASSERT_H

#define assert(...) ((void)0)

#endif // MRDOCS_SHARE_HEADERS_LIBC_STUBS_ASSERT_H
120 changes: 120 additions & 0 deletions share/mrdocs/headers/libc-stubs/complex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2024 Alan de Freitas ([email protected])
//
// Official repository: https://github.com/cppalliance/mrdocs
//

#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_COMPLEX_H
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_COMPLEX_H

// Types
#define imaginary _Imaginary
#define complex _Complex

// Constants
#define _Imaginary_I ((float _Imaginary)1.0)
#define _Complex_I ((float _Complex)1.0)
#define I _Complex_I

// Manipulation
#define CMPLX(x, y) ((double _Complex)((x) + _Complex_I * (y)))
#define CMPLXF(x, y) ((float _Complex)((x) + _Complex_I * (y)))
#define CMPLXL(x, y) ((long double _Complex)((x) + _Complex_I * (y)))

double creal(double _Complex z);
float crealf(float _Complex z);
long double creall(long double _Complex z);

double cimag(double _Complex z);
float cimagf(float _Complex z);
long double cimagl(long double _Complex z);

double cabs(double _Complex z);
float cabsf(float _Complex z);
long double cabsl(long double _Complex z);

double carg(double _Complex z);
float cargf(float _Complex z);
long double cargl(long double _Complex z);

double _Complex conj(double _Complex z);
float _Complex conjf(float _Complex z);
long double _Complex conjl(long double _Complex z);

double _Complex cproj(double _Complex z);
float _Complex cprojf(float _Complex z);
long double _Complex cprojl(long double _Complex z);

// Exponential functions
double _Complex cexp(double _Complex z);
float _Complex cexpf(float _Complex z);
long double _Complex cexpl(long double _Complex z);

double _Complex clog(double _Complex z);
float _Complex clogf(float _Complex z);
long double _Complex clogl(long double _Complex z);

// Power functions
double _Complex cpow(double _Complex x, double _Complex y);
float _Complex cpowf(float _Complex x, float _Complex y);
long double _Complex cpowl(long double _Complex x, long double _Complex y);

double _Complex csqrt(double _Complex z);
float _Complex csqrtf(float _Complex z);
long double _Complex csqrtl(long double _Complex z);

// Trigonometric functions
double _Complex csin(double _Complex z);
float _Complex csinf(float _Complex z);
long double _Complex csinl(long double _Complex z);

double _Complex ccos(double _Complex z);
float _Complex ccosf(float _Complex z);
long double _Complex ccosl(long double _Complex z);

double _Complex ctan(double _Complex z);
float _Complex ctanf(float _Complex z);
long double _Complex ctanl(long double _Complex z);

double _Complex casin(double _Complex z);
float _Complex casinf(float _Complex z);
long double _Complex casinl(long double _Complex z);

double _Complex cacos(double _Complex z);
float _Complex cacosf(float _Complex z);
long double _Complex cacosl(long double _Complex z);

double _Complex catan(double _Complex z);
float _Complex catanf(float _Complex z);
long double _Complex catanl(long double _Complex z);

// Hyperbolic functions
double _Complex csinh(double _Complex z);
float _Complex csinhf(float _Complex z);
long double _Complex csinhl(long double _Complex z);

double _Complex ccosh(double _Complex z);
float _Complex ccoshf(float _Complex z);
long double _Complex ccoshl(long double _Complex z);

double _Complex ctanh(double _Complex z);
float _Complex ctanhf(float _Complex z);
long double _Complex ctanhl(long double _Complex z);

double _Complex casinh(double _Complex z);
float _Complex casinhf(float _Complex z);
long double _Complex casinhl(long double _Complex z);

double _Complex cacosh(double _Complex z);
float _Complex cacoshf(float _Complex z);
long double _Complex cacoshl(long double _Complex z);

double _Complex catanh(double _Complex z);
float _Complex catanhf(float _Complex z);
long double _Complex catanhl(long double _Complex z);

#endif // MRDOCS_SHARE_HEADERS_LIBC_STUBS_COMPLEX_H
32 changes: 32 additions & 0 deletions share/mrdocs/headers/libc-stubs/ctype.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2024 Alan de Freitas ([email protected])
//
// Official repository: https://github.com/cppalliance/mrdocs
//

#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_CTYPE_H
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_CTYPE_H

// Character classification
int isalnum( int ch );
int isalpha( int ch );
int islower( int ch );
int isupper( int ch );
int isdigit( int ch );
int isxdigit( int ch );
int iscntrl( int ch );
int isgraph( int ch );
int isspace( int ch );
int isblank( int ch );
int isprint( int ch );
int ispunct( int ch );

// Character manipulation
int tolower( int ch );
int toupper( int ch );

#endif // MRDOCS_SHARE_HEADERS_LIBC_STUBS_CTYPE_H
35 changes: 35 additions & 0 deletions share/mrdocs/headers/libc-stubs/errno.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2024 Alan de Freitas ([email protected])
//
// Official repository: https://github.com/cppalliance/mrdocs
//

#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_ERRNO_H
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_ERRNO_H

#include "stddef.h"

// Define errno as a thread-local variable
#ifdef __cplusplus
extern "C" {
#endif

// Thread-local storage for errno
extern __thread errno_t __errno;

#ifdef __cplusplus
}
#endif

// Error codes
#define EDOM 1
#define ERANGE 2
#define EILSEQ 3

#define errno (__errno)

#endif // MRDOCS_SHARE_HEADERS_LIBC_STUBS_ERRNO_H
54 changes: 54 additions & 0 deletions share/mrdocs/headers/libc-stubs/fenv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Licensed under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Copyright (c) 2024 Alan de Freitas ([email protected])
//
// Official repository: https://github.com/cppalliance/mrdocs
//

#ifndef MRDOCS_SHARE_HEADERS_LIBC_STUBS_FENV_H
#define MRDOCS_SHARE_HEADERS_LIBC_STUBS_FENV_H

// Types
typedef struct {
unsigned int __control_word;
unsigned int __status_word;
unsigned int __tag_word;
unsigned int __other_flags;
} fenv_t;

typedef unsigned int fexcept_t;

// Functions
int feclearexcept(int excepts);
int fetestexcept(int excepts);
int feraiseexcept(int excepts);
int fegetexceptflag(fexcept_t* flagp, int excepts);
int fesetexceptflag(const fexcept_t* flagp, int excepts);
int fegetround(void);
int fesetround(int round);
int fegetenv(fenv_t* envp);
int fesetenv(const fenv_t* envp);
int feholdexcept(fenv_t* envp);
int feupdateenv(const fenv_t* envp);

// Macros for floating-point exceptions
#define FE_ALL_EXCEPT 0x3F
#define FE_DIVBYZERO 0x04
#define FE_INEXACT 0x20
#define FE_INVALID 0x01
#define FE_OVERFLOW 0x08
#define FE_UNDERFLOW 0x10

// Macros for floating-point rounding direction
#define FE_DOWNWARD 0x400
#define FE_TONEAREST 0x000
#define FE_TOWARDZERO 0xC00
#define FE_UPWARD 0x800

// Default floating-point environment
extern const fenv_t* FE_DFL_ENV;

#endif // MRDOCS_SHARE_HEADERS_LIBC_STUBS_FENV_H
Loading

0 comments on commit f99d262

Please sign in to comment.