Skip to content

Conversation

@chrisnovakovic
Copy link
Contributor

The flags necessary for Clang to compile C++ modules changed between Clang 15 and 17:

  • Clang >= 16 (and therefore Apple Clang >= 15, which are built from LLVM >= 16) just require C++20 features to be enabled (-std=c++20) in order to enable modules, while older versions of Clang explicitly require modules to be enabled via the -fmodules-ts option. Choose the appropriate flag based on the detected Clang version.
  • Clang >= 17 (and Apple Clang >= 16) require a dependent module's name to be specified along with its path with -fmodule-file, otherwise a warning (-Weager-load-cxx-named-modules) is outputted, but specifying the module's name at all is a syntax error with Clang < 16 (and Apple Clang < 15). When using Clang >= 16, specify the basename of the module file as the module name; nothing in the C++ specification says that a single module has to be declared in a file of the same name, but it'll be the case most of the time (and will fail loudly in the other cases).

Fixes #27.

@chrisnovakovic
Copy link
Contributor Author

Of course Apple Clang has to behave differently to mainline Clang in this specific instance...

Copy link
Collaborator

@peterebden peterebden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Was ages ago that I looked at the module stuff though; I'm not surprised it doesn't match up any more, but I also hear they've been tricky to support in general - I don't know to what degree we have something that works in the real world any more. (Although it is noted as experimental in the comment at least!)

@chrisnovakovic
Copy link
Contributor Author

Makes sense. Was ages ago that I looked at the module stuff though; I'm not surprised it doesn't match up any more, but I also hear they've been tricky to support in general - I don't know to what degree we have something that works in the real world any more. (Although it is noted as experimental in the comment at least!)

Indeed: C++ modules are a mess. I'd like to keep whatever level of support we currently have, but it's pretty hard to figure out exactly what's broken across the various compiler versions - #61 should simplify that quite a bit...

@chrisnovakovic
Copy link
Contributor Author

Force-pushing to rebase on master so we get the benefit of the new CI tests on this PR.

The flags necessary for Clang to compile C++ modules changed between
Clang 15 and 17:

* Clang >= 16 just require C++20 features to be enabled (`-std=c++20`)
  in order to enable modules, while older versions of Clang explicitly
  require modules to be enabled via the `-fmodules-ts` option. Choose
  the appropriate flag based on the detected Clang version.
* Clang >= 17 require a dependent module's name to be specified along
  with its path with `-fmodule-file`, otherwise a warning
  (`-Weager-load-cxx-named-modules`) is outputted, but specifying the
  module's name at all is a syntax error with Clang < 16. When using
  Clang >= 16, specify the basename of the module file as the module
  name; nothing in the C++ specification says that a single module has
  to be declared in a file of the same name, but it'll be the case most
  of the time (and will fail loudly in the other cases).

Fixes please-build#27.
@chrisnovakovic
Copy link
Contributor Author

I've given up trying to figure out whether Apple Clang supports C++ modules - the compiler's error messages say yes, but only with -std=c++20 or -fmodules-ts (neither of which compile //tests/modules); the preprocessor says no (neither __cpp_modules nor __cpp_lib_modules are set); some sources say they've been supported partially since 10.0.1, but give no indication of how that support can be enabled; some sources say yes, but only with -fmodules (an invalid option); other sources say no, not at all. It's incredible how badly-documented this all is.

I'm going to disable these tests by default unless they're re-enabled with a feature flag, and set that feature flag for the ubuntu_clang CI profiles.

@chrisnovakovic chrisnovakovic merged commit 03cf66b into please-build:master Sep 25, 2025
17 of 28 checks passed
@chrisnovakovic chrisnovakovic deleted the clang-16-modules branch September 25, 2025 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

-fmodules-ts is deprecated since clang16

3 participants