Skip to content

Replace tl::expected and libfmt with standard libary equivalents - #8618

Merged
AJenbo merged 7 commits into
diasurgical:masterfrom
glebm:std-format
Jul 21, 2026
Merged

Replace tl::expected and libfmt with standard libary equivalents#8618
AJenbo merged 7 commits into
diasurgical:masterfrom
glebm:std-format

Conversation

@glebm

@glebm glebm commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

tl::expected -> std::expected

  • tl::expected -> std::expected, tl::unexpected/tl::make_unexpected -> std::unexpected
  • .map()/.map_error() -> .transform()/.transform_error()
  • #include <expected.hpp> -> #include , grouped with std headers
  • Remove 3rdParty/tl/expected.hpp (the tl target remains for function_ref.hpp)

[[nodiscard]] warning fixes

std::expected is annotated as [[nodiscard]] and switching to it surfaced several warnings for places where we were silently dropping the errors. A commit here fixes most of these.

fmt::format -> std::format

  • fmt::format with literal format strings -> std::format.
  • fmt::format(fmt::runtime(...)) -> FormatRuntime in the new utils/format.hpp, an std::vformat wrapper that is also safe under the P2905 lvalue requirement of std::make_format_args.
  • fmt::dynamic_format_arg_store (Lua logging) -> a small hand-rolled per-field formatter over std::variant, returning std::expected.
  • fmt::format_int -> std::to_chars.
  • fmt::join -> manual joins at the two call sites.
  • SDL_audiolib: new patch that rewrites aulib_log.h to use std::format and drops the fmt dependency from its CMakeLists.
  • The -static-libstdc++ guard now keys off DEVILUTIONX_STATIC_SDL_AUDIOLIB instead of DEVILUTIONX_STATIC_LIBFMT.
  • libfmt removed from CMake, vcpkg, Brewfile, CI workflows, Dockerfiles, packaging scripts, UWP project, and docs.
  • macOS minimum version bumped to 13.3+, iOS to 16.3+ (required for <format>)

Disable PS4 and Xbox NXDK CI

These platforms have obsolete toolchains, disables them for now to avoid being stuck on old language level for who knows how long. Once the toolchains are updated, we can re-enable them.

Tracking bugs for libcxx update:

Failing builds:

@glebm
glebm force-pushed the std-format branch 6 times, most recently from 2cb5161 to 5d7acaf Compare July 13, 2026 16:59
@glebm
glebm marked this pull request as ready for review July 13, 2026 17:09
@glebm
glebm enabled auto-merge (rebase) July 13, 2026 17:09
glebm and others added 7 commits July 19, 2026 13:11
Now that the project targets C++23, use the standard library's
std::expected instead of the vendored tl::expected polyfill:

- tl::expected -> std::expected, tl::unexpected/tl::make_unexpected -> std::unexpected
- .map()/.map_error() -> .transform()/.transform_error()
- #include <expected.hpp> -> #include <expected>, grouped with std headers
- Remove 3rdParty/tl/expected.hpp (the tl target remains for function_ref.hpp)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
These toolchains haven't updated their libcxx in years.
Disables these CI builds in order to avoid being stuck on old language level support.

Once / if the toolchains are updated, we can re-enable these platforms.

Toolchain update bugs:
* PS4: OpenOrbis/OpenOrbis-PS4-Toolchain#262
* Xbox nxdk: XboxDev/nxdk-libcxx#3
Includes
diasurgical/asio@112f011,
which fixes a C++23 deprecation warning
- `fmt::format` with literal format strings -> `std::format`.
- `fmt::format(fmt::runtime(...))` -> `FormatRuntime` in the new
  `utils/format.hpp`, a std::vformat wrapper that is also safe under the
  P2905 lvalue requirement of `std::make_format_args`.
- `fmt::dynamic_format_arg_store` (Lua logging) -> a small hand-rolled
  per-field formatter over `std::variant`, returning `std::expected`.
- `fmt::format_int` -> `std::to_chars`.
- `fmt::join` -> manual joins at the two call sites.
- SDL_audiolib: new patch that rewrites aulib_log.h to use std::format
  and drops the fmt dependency from its CMakeLists.
- The `-static-libstdc++` guard now keys off
  `DEVILUTIONX_STATIC_SDL_AUDIOLIB` instead of `DEVILUTIONX_STATIC_LIBFMT`.
- libfmt removed from CMake, vcpkg, Brewfile, CI workflows,
  Dockerfiles, packaging scripts, UWP project, and docs.
- macOS bumped to 13.3+, iOS to 16.3+ (required for `<format>`)
- Amiga m68k: provide `__cmpdf2`, which is missing from the hard-float
  libgcc multilib but referenced via libstdc++'s long double paths.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@glebm glebm changed the title Replace libfmt with std::format Replace tl::expected and libfmt with standard libary equivalents Jul 19, 2026
@glebm
glebm requested a review from AJenbo July 19, 2026 12:46

@AJenbo AJenbo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

203/204 files reviewed

Comment thread Source/utils/log.hpp
* `std::format` has no equivalent of `fmt::dynamic_format_arg_store`, so we
* parse the replacement fields ourselves and format each one individually.
*/
std::expected<std::string, std::string> FormatLuaMessage(std::string_view fmt, std::span<const LuaFormatArg> args)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only function that gives me a bit of pause, but it's not something that is normally used heavily so not a big issue.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's a bit unfortunate that std::format doesn't support dynamic format arguments but we're unlikely to need anything more than this very basic formatting here.

@AJenbo
AJenbo disabled auto-merge July 21, 2026 21:59
@AJenbo
AJenbo merged commit ac2d7fc into diasurgical:master Jul 21, 2026
25 checks passed
@glebm
glebm deleted the std-format branch July 21, 2026 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants