microfmt
Zero-allocation C++ formatting for constrained environments
Loading...
Searching...
No Matches
microfmt_config.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Jarosław Pelczar <jarek@jpelczar.com>
2//
3// SPDX-License-Identifier: BSD-2-Clause
4
5#pragma once
6
34#if defined(__has_include)
35#if __has_include("detail/porting/microfmt_user_config.hpp")
36#include "detail/porting/microfmt_user_config.hpp"
37#endif
38#endif
39
40// Picks up whichever MICROFMT_*_BACKEND_CUSTOM macro(s) the
41// JPLCZ_MICROFMT_PORTING_HEADERS CMake build baked into a generated
42// detail/porting/microfmt_generated_config.hpp (see CMakeLists.txt and
43// detail/porting/README.md) -- a no-op (file never generated, #include
44// never taken) unless that CMake variable was set. Mirrors reloco's own
45// reloco_config.hpp pickup of detail/porting/reloco_generated_config.hpp;
46// unlike that header, microfmt_config.hpp has no ordering constraint
47// against __has_include's availability (microfmt already depends on
48// reloco, whose detail/compat.hpp establishes RELOCO_HAS_INCLUDE well
49// before microfmt_config.hpp is reachable), but a bare __has_include
50// check is used here anyway for exact parity with reloco_config.hpp.
51#if defined(__has_include)
52#if __has_include("detail/porting/microfmt_generated_config.hpp")
53#include "detail/porting/microfmt_generated_config.hpp"
54#endif
55#endif
56
57// ============================================================================
58// Available customization points (see docs/porting.md for details)
59// ============================================================================
60//
61// RELOCO_KERNEL, RELOCO_KERNEL_PANIC, RELOCO_TRAP, RELOCO_UNREACHABLE /
62// RELOCO_HAS_UNREACHABLE, RELOCO_DISABLE_ASSERT / RELOCO_DISABLE_ASSERT_STDIO,
63// RELOCO_DEBUG, RELOCO_TLS_MODEL
64// Owned by reloco (see reloco/reloco_config.hpp, reloco/tls_provider.hpp);
65// microfmt uses them directly rather than a MICROFMT_* alias. They may
66// still be overridden here, since microfmt_user_config.hpp is included
67// before any header applies its own
68// default.
69//
70// MICROFMT_USE_SYSTEM_ERROR
71// Selects the microfmt::posix_errno message backend: std::error_code /
72// std::system_category() (1) or strerror_s/strerror_r/strerror (0,
73// default).
74//
75// MICROFMT_DISABLE_DEBUG_FLAG
76// Strips the runtime `{:?}` (Rust Debug flag) support out of
77// formatter<char>/formatter<microfmt::string_view>/
78// formatter<std::string_view>/detail::const_char_like at the
79// preprocessor level: a literal `{:?}` in a format string then behaves
80// like `{}` for those types (no quoting/escaping), removing that
81// dead-otherwise code from the binary on targets that never write
82// `{:?}` in a format string. Does not affect reloco::Debug<T>/
83// microfmt::as_debug(), which never depend on this at all -- as_debug()
84// always prefers a type's Debug<T> when one exists, entirely
85// independent of this macro. See docs/porting.md.
86//
87// MICROFMT_ENABLE_BOOST_UUID / MICROFMT_ENABLE_BOOST_SOURCE_LOCATION
88// Enable the optional Boost-dependent formatters/detection. The caller
89// is responsible for ensuring Boost is available.
90//
91// MICROFMT_ENABLE_DEFAULT_LOGGER / MICROFMT_DEFAULT_LOGGER
92// Enable the process-wide built-in default logger, and/or name the
93// logger expression used by the MICROFMT_LOG_* free-function macros.
94//
95// MICROFMT_DEFAULT_LOG_SINK_BACKEND_CUSTOM
96// Replaces MICROFMT_ENABLE_DEFAULT_LOGGER's built-in stdout_color_sink
97// backend with a fixed-path #include "detail/porting/
98// default_log_sink.hpp" (not shipped -- see detail/porting/README.md
99// and detail/porting/default_log_sink.template.hpp), for targets that
100// need a different default (an OS-native logging facility, an
101// RTOS/bare-metal console, ...). See docs/porting.md.
102//
103// MICROFMT_SHARED / MICROFMT_SHARED_BUILD
104// Opt in to building/consuming a subset of microfmt's "heavy"
105// definitions (see e.g. microfmt.ipp and formatters/{hexdump,error,
106// semver,styled,pointer,escaped,bitfield,uuid}.ipp) as a real
107// shared library instead of duplicating them into every translation
108// unit/shared object that includes microfmt's headers. MICROFMT_SHARED
109// must be defined consistently by every translation unit in the
110// program; exactly one of them -- the one building the actual shared
111// library -- must additionally define MICROFMT_SHARED_BUILD, and
112// should simply `#include <microfmt/microfmt_compile.hpp>` (an
113// umbrella header pulling in every migrated entity's out-of-line
114// definitions) instead of hand-picking headers. See
115// microfmt/detail/compat.hpp (MICROFMT_API, MICROFMT_API_CONSTEXPR)
116// for the full contract, and tools/codesize/testbed/README.md for the
117// cross-.so duplication problem this addresses.
118//
119// microfmt's own formatter<T> specializations that are themselves
120// templated over a consumer-supplied T (formatter<std::optional<T>>,
121// formatter<reloco::vector<T>>, ...) cannot be migrated this way --
122// microfmt doesn't know which T a given application will instantiate.
123// For those, see microfmt/microfmt_extern.hpp's opt-in
124// MICROFMT_FORMATTER_INSTANCE(Type), which lets the *application*
125// explicitly instantiate/extern-declare the specific Types it uses.
126//
127// MICROFMT_UNWIND_HINT_POINTER_SIZE
128// Pointer size (4 or 8) used by the assembler-only helpers in
129// microfmt/inspector/unwind_hint_asm.h when __SIZEOF_POINTER__ is
130// unavailable. Must match the target's uintptr_t/function-pointer
131// representation.