This is an archive of the discontinued LLVM Phabricator instance.

[Bazel] Switch LLVM targets based on configuration flags.
Needs ReviewPublic

Authored by izuk on Dec 3 2021, 10:40 AM.

Details

Summary

Added a flag @llvm-project//llvm:targets to control which LLVM targets are
built at compile time:

$ bazel build --@llvm-projectllvm:targets=AArch64,X86 --config=generic_clang @llvm-project...

Diff Detail

Event Timeline

izuk created this revision.Dec 3 2021, 10:40 AM
izuk requested review of this revision.Dec 3 2021, 10:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2021, 10:40 AM
izuk edited the summary of this revision. (Show Details)Dec 3 2021, 10:41 AM

I think you need to rebase for the build to pass

izuk updated this revision to Diff 391675.Dec 3 2021, 10:56 AM

Rebased off HEAD.

This overall seems like an improvement. Some thoughts:

  1. Being able to just list the targets you want seems good. Do we also have a use case for "everything except target X" though? That would be hard to express in this scheme, whereas with individual target enable/disable flags it would be easy. Is there a way to get both? Is it worth it?
  2. It would be nice to be able to have targets that are configured, but are disabled by default. I guess we can add that pretty easily by creating a separate variable and using that for build_setting_default in the string list flag.
  3. It's a bit hard to guarantee that nothing directly references the targets. I think we do want it to be possible to directly reference a specific target, but if someone passes a flag without a target enabled, it seems like we shouldn't build that target. As I suggest above, perhaps we should make the srcs of disabled targets empty.
  4. As a test, can you try building with no targets enabled? I'm curious what happens. It might also flush out edge cases. What about with only some weird target enabled (and no X86)
utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
29–30

Can you include an example usage, as you have in the patch description here?

68–69

When I first read this I thought you were talking about Starlark macros. Maybe that could be clarified?

1781

Perhaps we should select out all srcs if the target isn't enabled. Then there's no chance some other dependency is going to pull in anything from a disabled target

utils/bazel/llvm-project-overlay/llvm/enum_targets_gen.bzl
5

Please update the documentation

63

I had to read the code to understand what this meant. Can you expand the documentation a bit? It is probably also worth explaining *why* you need two parameters here rather than just passing the targets you want (because this is dependent on selects and therefore has to be processed within a rule).

utils/bazel/llvm-project-overlay/llvm/target_macros.bzl
35–38

Just seems a bit cleaner

izuk updated this revision to Diff 392905.Dec 8 2021, 1:01 PM
izuk marked 4 inline comments as done.

Addressed documentation comments.
Changed enum_targets_gen into a macro.

izuk marked an inline comment as done.Dec 8 2021, 1:02 PM

I tried to address all the documentation comments.

utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
1781

Not sure I understand. Do you mean, have the Bazel target but with an empty srcs?

GMNGeoffrey added inline comments.Dec 9 2021, 5:48 PM
utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
1781

Yes, exactly. The set of targets has to be static, but we could make the Bazel target a noop, so that disabling an LLVM target really guarantees it isn't built.

utils/bazel/llvm-project-overlay/llvm/enum_targets_gen.bzl
53

Does that work? 🤨 Selects aren't evaluated within macros (which is why this rule exists). I think you're going to end up with just "if <object>" which will always be True