ut icon indicating copy to clipboard operation
ut copied to clipboard

MSVC named module enablement

Open MathiasMagnus opened this issue 2 years ago • 0 comments

Problem: Consuming ut as a named module using MSVC has compiler errors.

Solution:

  • Don't include STL headers. (It results in ODR violation when consuming std as module.)
    • MS-STL is the only implementation to date with proper import std capable export definitions implemented as a named module and not as a header unit.
  • Skip the definition of a symbol with internal linkage.

The proposed changes work with a downstream project that builds both the standard binary interface module (from std.ixx) and ut (by renaming ut.hpp to ut.ixx).

import boost.ut;

int main()
{
	using namespace boost::ut;
	"test-basic"_test = [] {
		int i = 42;
		expect(42_i == i);
	};

	return 0;
}

Builds as:

C:\Kellekek\Kitware\CMake\3.28.0\bin\cmake.exe --build C:/Users/mate/Source/Repos/OpenCL-Module/.vscode/build/msbuild-msvc-v143 --config Debug --target test-basic -- /nologo /verbosity:minimal

   1>Checking Build System
   Building Custom Rule C:/Users/mate/Source/Repos/OpenCL-Module/CMakeLists.txt
   Scanning sources for module dependencies...
   std.ixx
   Compiling...
   std.ixx
   StandardLibraryModule.vcxproj -> C:\Users\mate\Source\Repos\OpenCL-Module\.vscode\build\msbuild-msvc-v143\StandardLibraryModule.dir\Debug\StandardLibraryModule.lib
   1>Copying ut.hpp as ut.ixx
   Building Custom Rule C:/Users/mate/Source/Repos/OpenCL-Module/tests/CMakeLists.txt
   Scanning sources for module dependencies...
   ut.ixx
   Compiling...
   ut.ixx
   BoostUtModule.vcxproj -> C:\Users\mate\Source\Repos\OpenCL-Module\.vscode\build\msbuild-msvc-v143\tests\BoostUtModule.dir\Debug\BoostUtModule.lib
   Building Custom Rule C:/Users/mate/Source/Repos/OpenCL-Module/tests/CMakeLists.txt
   test-basic.cpp
   test-basic.vcxproj -> C:\Users\mate\Source\Repos\OpenCL-Module\.vscode\build\msbuild-msvc-v143\tests\Debug\test-basic.exe

The proposed changes don't build ut's own test infra, because none of the tests support import std. How should I go about adding support for that?

Issue: #558

Reviewers: @kris-jusiak

MathiasMagnus avatar Dec 27 '23 19:12 MathiasMagnus