Skip to content

Add #embed generation support and string_view-based path APIs - #32

Merged
Randalphwa merged 2 commits into
mainfrom
compiler_versions
Sep 7, 2026
Merged

Add #embed generation support and string_view-based path APIs#32
Randalphwa merged 2 commits into
mainfrom
compiler_versions

Conversation

@Randalphwa

@Randalphwa Randalphwa commented Sep 7, 2026

Copy link
Copy Markdown
Member

Summary
Emit #embed for resource bytes and add string_view path APIs

Motivation
The generated resource file carries every byte as a hex-literal array, which is slow to compile and blows up the generated file. C23's #embed lets the compiler paste the bytes directly, so that's a no-brainer for compilers that support it. While in there: every path lookup took const std::string&, which forced a copy even when the caller already had a view. That's gone too.

Changes

  • CMakeRC.cmake emits a #embed directive guarded by __has_embed, with the hex-literal array kept as the fallback for older compilers. Empty files still emit the zero-byte array — #embed of an empty file is ill-formed in some compilers without if_empty().
  • cmrc.hpp adds file::view() and a path_param type (std::string_view under C++17, const std::string& before); open, is_file, is_directory, exists and iterate_directory all take it.
  • The directory index switched to heterogeneous lookup (std::less<>) under C++14+, so lookups no longer materialize a std::string key.

@sandsc submitted a pr in the original CMakeRC repository to support std::string_view -- this PR adds support for std::stringview, but implemented differently.

CMakeRC.cmake now emits a C23 #embed directive in generated resource
files when the compiler supports it (guarded by __has_embed), falling
back to the hex-literal array otherwise; empty files keep the existing
zero-byte array behavior.

cmrc.hpp gains optional std::string_view support: file::view(), a
string_view-based path_param, and heterogeneous (std::less<>) map
lookups under C++17, avoiding string copies when opening/embedded
path lookups while remaining compatible with older standards.
@Randalphwa
Randalphwa merged commit b4a4b19 into main Sep 7, 2026
1 check passed
@Randalphwa
Randalphwa deleted the compiler_versions branch September 7, 2026 04:12
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.

1 participant