Relocatable modules?

I was looking into getting a build system to cache/share module files (i.e. *.pcm files) between different users to speed up builds. One problem is that it appears clang is embedding absolute paths into the module file, which causes issues when users build from different locations (e.g. their home directories). From the output of clang -fmodule-file-info ... it looks like this absolute path is the location of the various module.modulemap files the build uses. Anyone know of a way to get clang to these absolute path (e.g. using relative paths instead, or something similar to $ORIGIN)?

Thanks!
Andrew

I was looking into getting a build system to cache/share module files (i.e. *.pcm files) between different users to speed up builds. One problem is that it appears clang is embedding absolute paths into the module file, which causes issues when users build from different locations (e.g. their home directories). From the output of clang -fmodule-file-info ... it looks like this absolute path is the location of the various module.modulemap files the build uses. Anyone know of a way to get clang to these absolute path (e.g. using relative paths instead, or something similar to $ORIGIN)?

The paths to module.modulemap files found implicitly by clang will be based on the -I / -isystem paths that Clang is using: if those paths are relative, Clang should use relative paths to the module map files, and if those paths are absolute, Clang will use absolute paths to the module map. (The paths to module.modulemap files found by explicit -fmodule-map-file= arguments should match the form used in said argument.)

You can also diff the output of “llvm-bcanalyzer -dump” to investigate how modules built on different machines differ.

You can also diff the output of “llvm-bcanalyzer -dump” to investigate how modules built on different machines differ.

Ah thanks, this is super useful!

From the dump, it appears the CWD path is embedded in the MODULE_DIRECTORY and ORIGINAL_PCH_DIR. I’m using a pretty simple repro with just an empty header and a module.modulemap in the current working dir and compiling the module via clang++ -fmodules -x c++-header -Xclang -emit-module -c -o a.pcm module.modulemap -fmodule-name=a, so I don’t think I’m passing the absolute paths (but I’m not confident that I’m not doing something wrong).

Interestingly, if I pass -Xclang -fmodule-map-file-home-is-cwd``, the MODULE_DIRECTORY` field is no longer set – but then it appears that headers listed in the module map must be found relative to this location (as opposed to the module map directory – which makes sense).

Anywho, thanks for the tips – it give me a good place to start digging.

Andrew