Current status of C++20 modules?

Hello Team Sonar!

I have tried to analyze my project, which I have switched to C++20 modules recently. As my used tools are supporting C++20 modules since some months (cmake 3.28, GCC 14), I did the switch and the C++20 modules are working fine.

However, Sonar Scanner seems not yet to work with C++20 modules. I have used the latest available Scanner 5.0.1.3006, which is from 2023-08-04. The message I get is:

ERROR: Error during SonarScanner execution
java.lang.IllegalStateException: The "build-wrapper-dump.json" file was found but 0 C/C++/Objective-C files were analyzed. Please make sure that:
  * you are using the latest version of the build-wrapper and the CFamily analyzer
  * you are correctly invoking the scanner with correct configuration
  * your compiler is supported
  * you are wrapping your build correctly
  * you are wrapping a full/clean build
  * you are providing the path to the correct build-wrapper output directory
  * you are building and analyzing the same source checkout, absolute paths must be identical in build and analysis steps

The problem seems to be that the .cppm files are not recognized:

but 0 C/C++/Objective-C files were analyzed

Is there an update available, when C++20 modules support can be expected?

Simon

Hello, @sgleissner, and welcome to the community,

Indeed, we currently do not support modules and do not have yet an estimated timeline for doing so.

However, it is on our radar, and we have recently started examining the C++ ecosystem to see how modules are implemented by tooling and used by developers. If your project is open source, it would be helpful if you could share it so we can better understand the use cases.

Best regards,
Alejandro

Hello Alejandro,

Thanks for the warm welcome.

If your project is open source, it would be helpful if you could share it so we can better understand the use cases.

Yes, sure, you can find the sources here:
https://github.com/sgleissner/guardfw

Of course this is early work in progress and I don’t guarantee anything, but it

  • compiles
  • has test cases
  • a Github action runner with Sonar Cloud setup
  • and a very small example app (besides the test cases).

You can also install it under /usr/local, it will populate the folders

  • src/c++-modules/guardfw/ (for the .cppm files) and
  • lib64/cmake/guardfw/ (for cmake files).

You will also need:

  • cmake 3.28
  • gcc-14
  • Ninja

The library itself is a generic and highly configurable wrapper for Posix library functions. Instead of returning error codes, it throws exceptions (and exceptions can’t be ignored, but this behaviour can be changed for each wrapped call). But for you the most interesting thing is, that it heavily uses C++20 modules.

Please ask, if you have any questions.

Greetings
Simon

Thanks a lot!

Hello again @sgleissner,

As of today, we support C++20 modules in SonarCloud. Here is the announcement.

It should be as easy as adding

sonar.cfamily.enableModules=true

To your sonar-scanner configuration (via command line or sonar-project.properties)

If everything works as intended, you will see some new entries on the logs such as

INFO: 52 compilation units were scanned for C++ modules
INFO: C++ module dependency scanning cache: 0/52 hits
INFO: 21 BMIs were built for C++ modules
...
INFO: C and C++ analysis quality score: 100/100

Please, let us know how it goes!

Hello Alejandro,

these are great news, I will check this out this weekend.

Thank you!
Simon