build2: msvc: build2 fail with '__cpp_modules' is reserved

I have been using CMake for a long time and I am looking for an alternative for CXX modules. Build2 seems to meet almost all my requirements. It’s brilliant.

Unfortunately, it currently fails with MSVC. This is probably a known issue but I could not see it reflected in the issues board:

# Suppress warnings coming from external libraries.
#
cxx.internal.scope = current

# Some compilers (e.g. gcc) require that experimental features be enabled.
#
cxx.std = experimental
cxx.features.modules = true

assert $cxx.features.modules "no modules support for $cxx.signature"

using cxx

mxx{*}: extension = cero

# Assume headers are not importable unless stated otherwise.
#
hxx{*}: cxx.importable = false

# The test target for cross-testing (running tests under Wine, etc).
#
test.target = $cxx.target
C:\Users\wroy\Desktop\cero\cero-std\main.cero: error C2220: the following warning is treated as an error
C:\Users\wroy\Desktop\cero\cero-std\main.cero: error C2220: the following warning is treated as an error
C:\Users\wroy\Desktop\cero\cero-std\main.cero: warning C4117: macro name '__cpp_modules' is reserved, '#define' ignored
C:\Users\wroy\Desktop\cero\cero-std\main.cero: warning C4117: macro name '__cpp_modules' is reserved, '#define' ignored

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (16 by maintainers)

Most upvoted comments

FYI, I am planning to start looking into this next week.

Partitions, e.g. import a:b are not necessary

In my opinion, they are very important, necessary and I definitely intend to use them haha! XD (based on my experience with various experiments with modules in msvc)

as one can simply pass import a.b to get more or less the same result.

That is not at all the same result ^^; : one is a partition of a, so only a’s primary module interface can have this import line, and code in that partition is only for implementing definitions of module a and owned by it, it’s quite important distinction. The other is importing a totally separate module (not a and not part of a either) so any source file can use that import line and a.b have no relationship with a, they are completely separated modules (dot is not introducing a hierarchy, it’s just part of the name). They are not even used the same way nor lead to the same consequences.

But if that hack and only-primary-interface support is enough for you to start, kudos! Personally I need most of the features of modules to work to start anything other than small projects I already experimented modules with. Ideally just supporting what works with msvc (so not everything -there are bugs- but most of the standard features) should be enough for me to start real projects.

Interestingly, this has cleared up some confusion about partitions. From what you’ve said, they seem to be essentially the equivalent of private/public headers and are generally useful if you’re writing modules to be consumed by other projects.

Kind of, if we are talking about interface partition that’s kind of the idea but more “hermetic”. If we are talking private/implementation partitions, then it’s closer to pairing cpp files with definitions/implementations and a header exposing the interface. You might want to check a complete explanation, though clear ones are not easy to find. Unfortunately the subject is not that as easy as it could have been. ^^;

Anything new on this front?

This is planned for the next release and I hope to start looking into this in a few weeks. I will ping this issue with anything to test.

Speaking of, if you were to enable GitHub sponsors, I wouldn’t hesitate to fund it — even though I don’t have much to offer — should it help speed things up a bit. 😃

Thanks for the offer, but at this stage I suspect setting this up will take more time than it will gain. But we will definitely consider this if/when build2 becomes more widely used.

I do, ping me when time comes! In fact, I’m looking to go all the way with modules, even if they are more or less experimental at the moment. In my experience, they are quite stable with MSBuild. So much so that I haven’t encountered any major problems for a while with them.

Exactly same here 👍🏽