r/cpp • u/fortsnek274 • 4h ago
RFC: Using external modules or CPS with Visual Studio
Seeking feedback on this suggestion I'll hopefully make to devcom. I barely know what I'm doing, so I probably missed something. Do things work the way I think they do...
Visual Studio/MSBuild should have a way to easily consume modules and/or CPS from external libraries
What is the intended way to consume the modules of an external library? I'm not sure. With header-based libs, you just add to the include and lib paths, and away you go. Maybe stick that stuff in a props file. But for external modules? Are you supposed to reference a pre-built IFC directly?
Instead, external module sources could be discovered and built as needed by the project system. So, external modules would retain the familiar user experience of headers. You just point the project at module sources and it should Just Work.
It would also mean that the library's CMake script would not need a separate compilation of modules to a static library or IFC. A binary distribution probably shouldn't contain an IFC anyway as they may be so much more compiler-dependent than ABI.
Method 1
Add a "additional module source directories" project setting. The build system will lookup all cppm/ixx files in that directory to satisfy imports.
Method 2
Go all-in on the Common Package Specification. Add a "CPS files" project setting. The build system will collect and maybe cache information from listed CPS files to resolve includes and imports, and add additional compile settings. CPS files may use https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3286r0.pdf to list modules.
And the build system can automatically link the libraries listed in those CPS files. Maybe only if a header or module from them is used.
The advantage of this method is that it's a single setting for a library. You'd only need to list the CPS in project settings, and nothing else. The CPS provides the include paths, the libs, preprocessor defs, and module sources.
Method 3
Dedicated external CPS project type. Like method 2, but the project would make available the listed CPS packages, their includes, libs, modules, and preprocessor defs, to referencing projects through the project reference system. Such a project would also act as a central place to put the compiled modules rather than possibly duplicating them among referencing projects.
Or some other method. In essence, external modules should be easy to use, and CPS files should be the future, as maybe exported by CMake. So the project system should handle that stuff in some way.
Also, the project reference system should try to reuse compiled modules if possible, just like with import std.
•
u/not_a_novel_account cmake dev 2h ago
There isn't one. MSBuild does not handle external modules. You do what MSBuild does for
import std: add the source files for the external library's interface directly to the project.MSBuild was never good at managing external libraries in by-hand constructed projects. I never got the feeling they cared much about making this a "good" system.
2
u/mikemarcin Game Developer 4h ago
fwiw I just used vcpkg with native visual studio projects and CPS only for CMake based projects. But good luck it would be nice to have native projects with CPS.
•
u/pjmlp 3h ago
I am still waiting on a NuGET like integration for vcpkg on Visual Studio.
It would be nice however I don't have high hopes on feature prioritisation.