Skip to content

Conversation

FuegoFro
Copy link
Contributor

Makes a couple of changes to make Clang modules work better with generated libraries. Namely:

  • Only include public files in generated modulemap files. Previously it would include every header, which would A) potentially add headers from other modules (eg in React where multiple modules share a source directory) or include headers that aren't supposed to be compileable externally (eg all of Yoga's public headers handle both C and C++, but its internal ones assume C++ and would break when being used from a C translation unit).
  • Generate module maps for each target, not just the top-level target, since they will (likely) have different sources from the top-level one.
  • Populate the module_map attribute in the objc_library rule so Bazel doesn't generate its own module map.
  • Explicitly specify -fmodules if we have modules enabled. I'm not sure why, but I was running into cases where Bazel wouldn't pass that flag to Clang even when modules were enabled.
  • Only generate gen_module_map rule if module map generation is on.

Makes a couple of changes to make Clang modules work better with generated libraries. Namely:
- Only include public files in generated modulemap files. Previously it would include every header, which would A) potentially add headers from other modules (eg in React where multiple modules share a source directory) or include headers that aren't supposed to be compileable externally (eg all of Yoga's public headers handle both C and C++, but its internal ones assume C++ and would break when being used from a C translation unit).
- Generate module maps for each target, not just the top-level target, since they will (likely) have different sources from the top-level one.
- Populate the `module_map` attribute in the `objc_library` rule so Bazel doesn't generate its own module map.
- Explicitly specify `-fmodules` if we have modules enabled. I'm not sure why, but I was running into cases where Bazel *wouldn't* pass that flag to Clang even when modules were enabled.
- Only generate `gen_module_map` rule if module map generation is on.
return Glob(pattern: pattern, behavior: GlobBehaviorBashV4).paths
}

// Expands a set of globs with the semantics of pod `source_file` globs.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: This is just the functionality that was in Sources/RepoToolsCore/RepoActions.swift, but pulled out to a function for easy reuse.

I had been testing this off an older master, which didn't have the `[system]` change. This:
- Suppresses the `[system]` tag if there's nothing in the modulemap, since otherwise it complains with "expected umbrella, header, submodule, or module export".
- Changes directory creation to use the FS manager rather than shell, because I was getting weird issues where the `pwd` was returning an empty string.
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.

1 participant