Repository navigation
✨ (minor) v6: Use import std - #139
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Moves libhal-util v6 to
import std. Every module, unit test, compile check and the test package now importsstdinstead of including the standard headers it uses, and most global module fragments are gone. This follows libhal#276.Requirements
cmake/[^4.5.0]).import stditself.libc++.modules.json.LLVM only.
Changes beyond swapping includes
stdmodule exports none, soCHAR_BITbecamestd::numeric_limits<T>::digitsinbit_value::widthandupscale(). Both are on unsigned types, where the two are equal.stdmodule exportsstd::size_t, notsize_t. The unqualifiedsize_t,uint32_t,uint64_tandint64_tin the modules, 31 lines in all, are now qualified withstd::. They're the same types, so the API doesn't change.i2c.cppmstill includes<mutex>in its global module fragment. libc++ built without threads, as on bare-metal targets, leavesstd::lock_guardandstd::unique_lockout of thestdmodule. libhal'sspi.cppmdoes the same.units.test.cppstill includes<chrono>and<ios>. Itsoperator<<forstd::chrono::durationhas to come before<boost/ut.hpp>, and includes have to come beforeimport std;.Verified locally
conan createbuilds against thearmv7m_soft_nofplibc++stdmodule.mainand 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 examplecanat 30,744 B andi2cat 30,176 B.