[clang] Support '-fmodule-file-home-is-cwd' for C++ header units. (PR #135147)

Michael Park via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 10 11:27:26 PDT 2025


mpark wrote:

> > > If you did `-fmodule-file=<name>=<pcm>` for header units, I think it is better to upstream that first. I think it is more fundamental.
> > 
> > 
> > We don't do anything special downstream. As far as I know it already works today.
> 
> If `-fmodule-file=<name>=<pcm>` already works for header units, it is helpful to update the documents.

Well, it "works" but my understanding is that it's not officially supported today in Clang. My understanding is that header units technically are anonymous, and therefore don't have a module name. Is that correct?

What we do downstream roughly is to just give the header unit a module name corresponding to its path.
```
clang++ -std=c++23 --precompile -xc++-user-header lib.h -fmodule-name=lib.h -o lib.pcm
```
then to use it, provide: `-fmodule-file=lib.h=lib.pcm` and `-fmodule-map-file=lib.modulemap` that looks like:
```
module "lib.h" {
  header "lib.h"
  export *
}
```

This makes it such that an `import "lib.h"` does what we want with respect to lazy loading and such.
Given that we're hacking around an unofficial implementation detail in a sense... I'm not sure it makes sense to document it per se 😕 What do you think?

https://github.com/llvm/llvm-project/pull/135147


More information about the cfe-commits mailing list