From 297bc80eab5128e1cde7cd597368109a033b6cc0 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 28 Sep 2016 18:03:28 +0200 Subject: Update idea: C++ modules support Add module test for Clang and VC --- build2/cxx-modules/modtest/README | 129 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 build2/cxx-modules/modtest/README (limited to 'build2/cxx-modules/modtest/README') diff --git a/build2/cxx-modules/modtest/README b/build2/cxx-modules/modtest/README new file mode 100644 index 0000000..2cb4743 --- /dev/null +++ b/build2/cxx-modules/modtest/README @@ -0,0 +1,129 @@ +Use use_modules=false command line variable override to compile without +modules: + +$ b config.cxx=clang++ use_modules=true test +$ b config.cxx=cl-14u2 use_modules=true test + +Other useful options: + +config.cxx.coptions+=-stdlib=libc++ + +For now use config.bin.lib=static if compile with VC. + +CLang 3.7.0, 3.9.0 +================== + +Notes: + +* What is a header file for clang? Looks like it considers it a module. But + what if definitions are contained in a separate (corresponding source) + file. It sounds like such a file also imports the module it implements. + Sounds wierd. + + Probably need to add -fmodule-name= when compile module source + file(s). Should make some difference (which externally is invisible). + +* When clang sees #include it compiles the included file (with a separate + compiler instance) and place the result into the cache. + +* clang++ -module-file-info foo-8KLLM232DU5X.pcm prints lot of information + about foo module. + +* module.modulemap file(s) appears in the output of the "show dependencies" + command like that: + + clang++ -I`pwd` -fmodules -std=c++1y -M -MG -MQ ^ driver.cxx + +Issues: + +* First run of b when configured to use CLang fails with: + fatal error: error in backend: IO failure on output stream. + + Some bug in clang++ 3.7.0 which seems to relate to the creation/update of + translated modules cache while using -M (dependency generation) option. + Consequitive runs (even those which require module recompilation) work well. + + clang 3.8.0, 3.9.0 work fine. + +VC 14 U2,3 +========== + +Notes: + +* Module interface description get persisted into the separate ifc-file when + the module source file is compiled: foo.cxx -> foo.obj, foo.ifc. To compile + a source file which imports a module the compiler expects module's ifc-file + to be available. + + That's currently requres to maintain a proper prerequisite's order in + buildfile. When build an executable consuming module located in a library + need to ensure the library source files are compiled before executable's + source files to get lib's ifc-files ready: + + $ b config.cxx=cl-14u2 use_modules=true 'lib{bar}' + $ b config.cxx=cl-14u2 use_modules=true + +* There is a ifc.exe tool (comes with VC) which can be used to embed interface + files into static lib or convert to object file. + +* No signs of the tools/compiler switch to extract a module dependencies from a + source file. Some people complains/asks about it: + + http://nibblestew.blogspot.ru/2015/10/some-comments-on-c-modules-talk.html + http://stackoverflow.com/questions/35230327/how-to-use-vc-modules-in-cmake + +Issues: + +* Using std::string in the struct foo results in VC 14 U2 with linker's + inability to resolve string symbols while linking foo.exe.obj. VC 14 U3 + compiler in this case fails with internal error while compiling driver.cxx. + + CLang 3.9.0 works ok in this case. + +* How to only produce .ifc file without the object file? /module:export? + + Looks like compiling the header (with /TP) is the best options so far: it + produces .obj but a small one. + + cl /c /EHsc /experimental:module /module:interface /TP foo + +References +========== + +A Module System for C++ (Revision 4): + + http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0142r0.pdf + +-- + +CLang modules: + + http://clang.llvm.org/docs/Modules.html + +CLang module tests (examples): + + https://github.com/llvm-mirror/clang/tree/master/test/Modules + +Some early presentation (Feb 2012, Doug Gregor) + + https://isocpp.org/blog/2012/11/modules-update-on-work-in-progress-doug-gregor + +-- + +Modules Support in Visual C++ 2015 Update 1: + + https://blogs.msdn.microsoft.com/vcblog/2015/12/03/c-modules-in-vs-2015-update-1/ + +Compiler improvements in VS 2015 Update 2 (in regards of C++ Modules there are +seems to be just bug fixes): + + https://blogs.msdn.microsoft.com/vcblog/2016/02/11/compiler-improvements-in-vs-2015-update-2/ + +MS C++ Modules talk on CppCon 2015: + + https://github.com/isocpp/CppCoreGuidelines/blob/master/talks/Large-Scale-C%2B%2B-With-Modules.pdf + https://www.youtube.com/watch?v=RwdQA0pGWa4 + +VC 14 Update 3 + + https://www.visualstudio.com/en-us/news/releasenotes/vs2015-update3-vs -- cgit v1.1