This is an archive of the discontinued LLVM Phabricator instance.

Install the LLVM header module.modulemaps
Needs ReviewPublic

Authored by EricWF on Dec 4 2016, 3:58 PM.

Details

Summary

Currently the LLVM module.modulemap files are not installed along side the headers. This is because these module maps only work during in-tree builds where some of the headers are in the build directory. Once those generated headers are installed with the in-tree headers the module maps no longer work.

This patch adds a new map called module.modulemap.install which correctly handles the LLVM headers in their install configuration. The changes needed to support that are:

  1. Build llvm/Support/DataTypes.h as a separate module instead of as part of LLVM_Utils. This is required to avoid a cyclic dependency between the LLVM_C and LLVM_Utils modules.
  2. Add the generated Config/*.def headers to the LLVM_Config module.
  3. Handle the IR/Attributes.gen and IR/Intrinsics.gen headers so that the LLVM_IR umbrella is complete.

Unfortunately I don't think there is a way to modify the existing module.modulemap file so that it works with both in-tree and installed headers. @rsmith is there a better way to handle this?

Diff Detail

Event Timeline

EricWF updated this revision to Diff 80216.Dec 4 2016, 3:58 PM
EricWF retitled this revision from to Install the LLVM header module.modulemaps.
EricWF updated this object.
EricWF added reviewers: rsmith, beanz, v.g.vassilev, aprantl.
EricWF added subscribers: llvm-commits, rsmith.
EricWF updated this revision to Diff 80218.Dec 4 2016, 4:17 PM
  • The foo.gen headers don't need to be textual, so don't mark them as such.
EricWF updated this revision to Diff 80219.Dec 4 2016, 4:21 PM
  • Change the foo.gen headers back to being textual. I was incorrect in saying they didn't need to be.
v.g.vassilev edited edge metadata.Dec 5 2016, 1:26 AM

Can't we concatenate the modulemap in the source directory with the modulemap in the build directory and publish them in the install folder?

EricWF added a comment.Dec 5 2016, 2:05 AM

Can't we concatenate the modulemap in the source directory with the modulemap in the build directory and publish them in the install folder?

Unfortunately not. The module.modulemap.install file provides *different* definitions for existing modules. For example LLVM_Config is defined in module.modulemap as

module LLVM_Config { requires cplusplus umbrella "Config" module * { export * } }

but module.modulemap.install needs to take the generated headers into account, which leads to the differing definition below:,

module LLVM_Config {
  requires cplusplus
  umbrella "Config"
  module * { export * }
 textual header "Config/AsmParsers.def"
 textual header "Config/AsmPrinters.def"
 textual header "Config/Disassemblers.def"
 textual header "Config/Targets.def"
}

We can't easily achieve this by concatenating the maps. We also can't name these additional headers in the module.modulemap file since they don't exist as part of that modules "umbrella" until after installation.

Can we use extern module in that case. It seems that it could help reducing the duplication:

module LLVM_Config_Extended {
 textual header "Config/AsmParsers.def"
 textual header "Config/AsmPrinters.def"
 textual header "Config/Disassemblers.def"
 textual header "Config/Targets.def"
  use "LLVM_Config"
}
extern module "LLVM_Config" "our_installed_src_module.modulemap"
EricWF added a comment.Dec 5 2016, 3:17 AM

Can we use extern module in that case. It seems that it could help reducing the duplication:

IDK, I'll give it a shot! Thanks for the advice.

EricWF updated this revision to Diff 80245.Dec 5 2016, 3:42 AM
EricWF edited edge metadata.
  • Use extern module instead of an entirely new module map.
EricWF updated this revision to Diff 80247.Dec 5 2016, 3:44 AM
  • Fix copy-paste error
EricWF updated this revision to Diff 80312.Dec 5 2016, 12:51 PM
  • Fix CMake changes to match existing style.
  • Move the IR/Intrinsics.gen header into the LLVM_Intrinsics module instead of its parent LLVM_intrinsics_gen
EricWF updated this revision to Diff 80321.Dec 5 2016, 1:32 PM
  • Fix installation directory for module.install.modulemap.

I've tested this patch against a full in-tree build with modules enabled and full out-of-tree clang builds.

Thanks for working on this! LGTM.

EricWF planned changes to this revision.Dec 7 2016, 1:53 PM

After installing the module.modulemap LLVM fails to build because when building the modules it finds both the in-tree map and installed map. I think fixing this will require changing the Clang module.modulemap search behavior.

Hm, do we have both -I pointing to the folders of the installed modulemap and the modulemap in the source? Or it is because of the module.extern.modulemap?

@EricFW, ping. I was wondering whether there are news about the planned changes.

EricWF added a comment.Mar 7 2017, 2:38 PM

So there is a bug tracking the Clang changes needed: https://bugs.llvm.org/show_bug.cgi?id=31905
I've tried to fix the bug myself but I haven't had any luck.

Once that gets fixed these changes are good to go, I still use them every day.

EricWF updated this revision to Diff 91087.Mar 8 2017, 3:23 PM
  • Merging with master in case other people want to use this.

It's still waiting on http://llvm.org/PR31905 to be fixed though.

bruno resigned from this revision.Nov 9 2020, 11:55 AM