https://github.com/bhallstein/cpp-modules-test
Testing C++20 module compilation with Clang
https://github.com/bhallstein/cpp-modules-test
Last synced: about 1 year ago
JSON representation
Testing C++20 module compilation with Clang
- Host: GitHub
- URL: https://github.com/bhallstein/cpp-modules-test
- Owner: bhallstein
- Created: 2022-05-21T11:58:43.000Z (about 4 years ago)
- Default Branch: int
- Last Pushed: 2022-05-21T12:03:26.000Z (about 4 years ago)
- Last Synced: 2025-03-14T13:44:18.133Z (over 1 year ago)
- Language: Shell
- Size: 1000 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# cpp-modules-test
Test of C++ module compilation with clang.
Unfortunately the version of clang/llvm included with xcode 13 doesn't include support for modules, so uses [silkeh/clang](https://hub.docker.com/r/silkeh/clang) docker image.
See [ecosta.dev](https://blog.ecosta.dev/en/tech/cpp-modules-with-clang)
### Module precompilation approach
Unfortunately a module map is required, for reasons I don't understand (it seems like it should be very easy to give the compiler all source files/compilation units to munch on, and for the compiler when encountering one importing an uncompiled module, defer these units to the end of the compilation phase, but that must not be feasible for some reason).
- Here we first compile the module file(s) into `./*.pcm`.
- Then compile main using `-c -fprebuilt-module-path=.`
- Then link with `clang++ *.pcm *.o -o test`
From [clang.llvm.org/docs/Modules.html](https://clang.llvm.org/docs/Modules.html):
> -fprebuilt-module-path=\
>
> Specify the path to the prebuilt modules. If specified, we will look for modules in this directory for a given top-level module name. We don’t need a module map for loading prebuilt modules in this directory and the compiler will not try to rebuild these modules. This can be specified multiple times.