Skip to content

Public transitive headermap rule first pass - #26

Merged
jerrymarino merged 3 commits into
masterfrom
jmarino_prototype_headermap_rule
Oct 3, 2019
Merged

jerrymarino merged 3 commits into
masterfrom
jmarino_prototype_headermap_rule

Conversation

@jerrymarino

Copy link
Copy Markdown
Collaborator

This patch prototypes a headermap rule in skylark!

It works quite well, and sacrifices usability, since it isn't implicitly
created.

Public transitive objc_library header usage:

  • deps go into hdr_providers
  • hdrs into hdrs wrapped in a filegroup
  • the actual header map goes into hdrs for public usage

Other consumers of the rules can wrap objc_library in a macro, which
both instantiate and consume this rule.

It works by transitively merging public headermaps. This works
effortlessly, since headermaps are propagated transitively along with the
headers.

Usage:
Create a basic headermap ( for the pod PINOperation )

headermap(
  name = "PINOperation_hmap",
  namespace = "PINOperation",
  # File group to headers
  hdrs = [
    "PINOperation_hdrs"
  ],
  hdr_providers = []
)

It supports transitive propagation via the hdr_providers rule,
which are currently objc providers only, we can expand this to multiple
types once swift support is added.

headermap(
  name = "PINCache_hmap",
  namespace = "PINCache",
  hdrs = [
    "PINCache_hdrs"
  ],
  hdr_providers = [ "//Vendor/PINOperation:PINOperation" ]
)

Compilation flags:
.hmaps will need to be explicitly added to the command line. Likely,
this will be achieved with copts in PodToBUILD. I'm not sure if the
behavior of replacing GENFILES with the correct directory is
available in Bazel, so that may rely on a custom toolchain or simply use
the include attribute.

Other considerations:
Be smarter about headers that actually exist. This needs more thought.
If the input pruning and dot d pruning work is useable from skylark,
it'd be great to leverage that.

@jerrymarino

Copy link
Copy Markdown
Collaborator Author

No need to review this one yet. The plan for this is to implement it in PodToBUILD ( and other places 😉 ) to improve build performance.

Unless there is a clear path to merge bazelbuild/bazel#3712 into master, this will replace the PR for most of my use cases.

@jerrymarino
jerrymarino force-pushed the jmarino_prototype_headermap_rule branch from 76e87b5 to 1744ba7 Compare October 1, 2019 19:59
@jerrymarino jerrymarino changed the title WIP: Prototype public transitive headermap rule Public transitive headermap rule first pass Oct 1, 2019
@jerrymarino

Copy link
Copy Markdown
Collaborator Author

It looks like GENDIR is now working for the copts attribute, so we probably don't need the custom toolchain to implement this any longer

@jerrymarino
jerrymarino force-pushed the jmarino_prototype_headermap_rule branch 4 times, most recently from 3aca0de to c4d13e3 Compare October 3, 2019 01:07
This patch prototypes a headermap rule in skylark!

It works quite well, and sacrifices usability, since it isn't implicitly
created.

Public transitive `objc_library` header usage:
- `deps` go into `deps`
- `hdrs` into `hdrs` wrapped in a filegroup
- the actual header map goes into `hdrs` for public usage

Other consumers of the rules can wrap `objc_library` in a macro, which
both instantiate and consume this rule.

It works by transitively merging public headermaps. This works
effortlessly, since headermaps are propagated transitively along with the
headers.

Usage:
Create a basic headermap ( for the pod PINOperation )
headermap(
  name = "PINOperation_hmap",
  namespace = "PINOperation",
  # File group to headers
  hdrs = [
    "PINOperation_hdrs"
  ],
  deps = []
)

It supports transitive propagation via the `deps` rule,
which are currently objc providers only, we can expand this to multiple
types once swift support is added.
headermap(
  name = "PINCache_hmap",
  namespace = "PINCache",
  hdrs = [
    "PINCache_hdrs"
  ],
  deps = [ "//Vendor/PINOperation:PINOperation" ]
)

Compilation flags:
Explicitly set this in copts, the compiler shoulnd't have O(N) hmaps.

Other considerations and TODOs:
- Be smarter about headers that actually exist. This needs more thought.
If the input pruning and dot d pruning work is useable from skylark,
it'd be great to leverage that.
- Add better documentation
@jerrymarino
jerrymarino force-pushed the jmarino_prototype_headermap_rule branch from c4d13e3 to 6178db8 Compare October 3, 2019 01:23
@jerrymarino

Copy link
Copy Markdown
Collaborator Author

This one should be ready to merge, and get us to parity of how headers were treated.

We should improve upon that:

  • split out a "namespaced" headermap.
  • conditionally only propagate namespaced includes
  • leave the flat header paths as for use in cocoapods, or apps which want to use them. e.g. in my app I don't want people to include "Vendor/Texture/Texture.h as Texture.h"

@jerrymarino

Copy link
Copy Markdown
Collaborator Author

This needs a few things before we enable it by default including:

  • validate correctness on a few hundred cocoapods
  • rewrite vendor'd llvm headermap hash table impl for performance or integrate internal rule based on Xcode's hmap data structure
  • replace $(GENDIR) with $(BINDIR)

@jerrymarino
jerrymarino merged commit 202b33c into master Oct 3, 2019
@jerrymarino
jerrymarino deleted the jmarino_prototype_headermap_rule branch October 3, 2019 19:33
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