fix: build issues with -fmodules flag
#47
Merged
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.
Fix C++20 modules compilation on macOS
Fixes #44
Problem
The SDK failed to compile on macOS when C++20 modules were enabled with the
-fmodulesflag. The build produced four compilation errors in the nlohmann JSON library:definition of 'basic_streambuf' must be imported from module 'std.streambuf' before it is required(line 6261)use of undeclared identifier 'errno'(line 8620)use of undeclared identifier 'errno'(line 8630)use of undeclared identifier 'errno'(line 8646)Root Cause
When C++20 modules are enabled, the visibility of standard library includes becomes more restricted. The nlohmann JSON library is a single-header library with includes scattered throughout different sections. Previously, includes from one section were implicitly available in other sections, but with C++20 modules, each section requires explicit includes for the symbols it uses.
Solution
Added two missing standard library includes to
third_party/nlohmann/json.hpp:Added
#include <cerrno>at line 7381 in the lexer sectionerrnomacro is used when parsing numbers in the lexerAdded
#include <streambuf>at line 6162 in the input adapters section<istream>is presentTesting
-fmodulesflag enabledChanges
third_party/nlohmann/json.hpp: Added 2 include statements for C++20 modules compatibility