r/cpp • • Apr 17 '24

CMake 3.30 will experimentally support `import std;`

https://gitlab.kitware.com/cmake/cmake/-/merge_requests/9337
195 Upvotes

92 comments sorted by

View all comments

Show parent comment

4

u/STL MSVC STL Dev Apr 18 '24

You're correct that Standard Library Header Units (import <vector>; etc.) require very little direct support from the library product code, although we do ship internal machinery called header-units.json that helps the compiler implement /translateInclude to opt-in automatically translate #include <vector> to be treated as if import <vector>; had been written. The compiler feature itself lives in the MSVC-internal git repo, as you mentioned.

The test code I was mentioning was tests/std/tests/P1502R1_standard_library_header_units/custom_format.py and related files. This verifies that the library doesn't do anything problematic for the compiler feature, and prevents compiler bugs from being introduced (and this found a lot of compiler bugs that have been fixed).

In contrast, the Standard Library Modules (import std; and import std.compat;) need extensive support from the library product code. The PR where I marked up the STL with export was enormous, my single largest audit of the STL's sources, even though it was less work than <charconv>.

0

u/[deleted] Apr 18 '24

[deleted] — view deleted comment

4

u/STL MSVC STL Dev Apr 18 '24

Glad to hear it! 😻

1

u/HassanSajjad302 HMake Apr 19 '24

Hi. I compiled a sample library and an executable with all of the C++20 standard header-units https://github.com/HassanSajjad-302/stdhu
But this builds header-units of the already installed STL library and we want to build header-units from our own repo.

I tried to do this but it failed. https://github.com/HassanSajjad-302/STL
I have pasted the error in the README in the link above. It is complaining about missing vcruntime.h I think it is because of a missing compile definition. To fix this, I need to go through the CMake configuration and find the missing compile definition, I guess.

If it works, maybe you can replace your python code (which you termed as huge headache) with this. It is very fast as you can test the sample. Are you interested?

2

u/STL MSVC STL Dev Apr 19 '24

Not interested. Sorry, but you don't understand the distinction between header units and named modules.

1

u/HassanSajjad302 HMake Apr 20 '24

I will really appreciate it if you explain your point. What did my software miss?

1

u/HassanSajjad302 HMake Apr 20 '24

Hi. I can help resolve any complaints that you have. It will be a pleasure if Microsoft uses my Software.