Skip to content

✨ (minor) v6: Use import std - #139

Merged
kammce merged 1 commit into
mainfrom
v6-import-std
Nov 26, 2026
Merged

kammce merged 1 commit into
mainfrom
v6-import-std

Conversation

@kammce

@kammce kammce commented Nov 26, 2026

Copy link
Copy Markdown
Member

Moves libhal-util v6 to import std. Every module, unit test, compile check and the test package now imports std instead of including the standard headers it uses, and most global module fragments are gone. This follows libhal#276.

Requirements

  • CMake 4.5, for the library and the test package (cmake/[^4.5.0]).
  • libhal-cmake-util 5.0.16, so clang-tidy doesn't report libc++'s own sources.
  • libhal 5.0.0-alpha.23, the first libhal release that uses import std itself.
  • llvm-toolchain 0.2.0 for Cortex-M builds, which points CMake at the matching multilib's libc++.modules.json.

LLVM only.

Changes beyond swapping includes

  • No macros. The std module exports none, so CHAR_BIT became std::numeric_limits<T>::digits in bit_value::width and upscale(). Both are on unsigned types, where the two are equal.
  • No global names. The std module exports std::size_t, not size_t. The unqualified size_t, uint32_t, uint64_t and int64_t in the modules, 31 lines in all, are now qualified with std::. They're the same types, so the API doesn't change.
  • i2c.cppm still includes <mutex> in its global module fragment. libc++ built without threads, as on bare-metal targets, leaves std::lock_guard and std::unique_lock out of the std module. libhal's spi.cppm does the same.
  • units.test.cpp still includes <chrono> and <ios>. Its operator<< for std::chrono::duration has to come before <boost/ut.hpp>, and includes have to come before import std;.

Verified locally

  • Host (macOS, LLVM 23): all 18 test programs pass, the compile checks pass, and clang-tidy reports nothing. The test package builds and runs.
  • STM32F103: conan create builds against the armv7m_soft_nofp libc++ std module.
  • Consumer: libhal-arm-mcu v2 main and all 11 of its STM32F103 demos built against this branch. Every image is byte-identical to one built against libhal-util 6.0.0-alpha.14, for example can at 30,744 B and i2c at 30,176 B.

CMake 4.5 makes `import std` available to every C++20 target it scans,
with no property to set. Each module, unit test, compile check and the
test package imports std instead of including the standard headers it
uses, and most global module fragments go away.

- Require CMake 4.5, in the library and the test package,
  libhal-cmake-util 5.0.16, which keeps clang-tidy out of the std
  module's sources, and libhal 5.0.0-alpha.23, the first release that
  uses import std itself.
- The std module exports no macros and no global names, so CHAR_BIT
  becomes std::numeric_limits<T>::digits (both uses are unsigned
  types), and size_t, uint32_t and the other C integer names are
  qualified with std::.
- i2c.cppm still includes <mutex>: libc++ built without threads, as on
  bare-metal targets, leaves std::lock_guard and std::unique_lock out
  of the std module.
- units.test.cpp still includes <chrono> and <ios>: its operator<< for
  std::chrono::duration must come before <boost/ut.hpp>, and the
  includes must come before import std.
@kammce
kammce merged commit c4d34f5 into main Nov 26, 2026
9 of 10 checks passed
@kammce
kammce deleted the v6-import-std branch November 26, 2026 15:51
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