This is an archive of the discontinued LLVM Phabricator instance.

[cmake] Don't include symlinks to tools in Build-all when `LLVM_BUILD_TOOLS` is off
ClosedPublic

Authored by zero9178 on Aug 29 2022, 1:14 PM.

Details

Summary

When building LLVM with LLVM_BUILD_TOOLS as OFF, numerous tools such as llvm-ar or llvm-objcopy end up still being built. The reason for this is that the symlink targets are unconditionally included in a Build-all build, causing the tool they're symlinking to be built after all.

This patch changes that behaviour to be more intuative by only including including the symlink in a Build-all build if the target they're linking to is also included.

Diff Detail

Event Timeline

zero9178 created this revision.Aug 29 2022, 1:14 PM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: mgorny. · View Herald Transcript
zero9178 requested review of this revision.Aug 29 2022, 1:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2022, 1:14 PM

I need to review more but I am suspicious of this exact fix before we are looking up a LLVM-specific env inside what I think is a reusable project also useable by downstream projects.

I need to review more but I am suspicious of this exact fix before we are looking up a LLVM-specific env inside what I think is a reusable project also useable by downstream projects.

The code below sort of already makes this assumption, but I could change this patch and the line below to use ${project}_BUILD_TOOLS. That "enforces" common vocabulary while also respecting any other downstream projects making use of llvm_add_tool_symlink.

Could we just read the EXCLUDE_FROM_ALL property of the target tool and use that to set the same property on the symlink target? We'd ideally use a generator expression for that so it works independently of the order the tool target and the symlink target are defined, but the CMake documentation makes it seem like EXCLUDE_FROM_ALL may only support generator expressions in 3.19 and above, whereas our minimum is 3.13.4. It's pretty conventional to always define the symlink target after the tool target though, so even just setting the property directly should work fine in practice.

zero9178 updated this revision to Diff 456617.Aug 30 2022, 5:03 AM
zero9178 edited the summary of this revision. (Show Details)

Change approach to querying EXCLUDE_FROM_ALL property of the target and using it to determine whether the resulting symlink should be included in a Build-all built.

smeenai accepted this revision.Aug 30 2022, 5:25 AM

Thanks, LGTM

llvm/cmake/modules/AddLLVM.cmake
2139

Before committing, could you add a TODO comment to switch this to use a generator expression once our minimum required CMake version is >= 3.19?

This revision is now accepted and ready to land.Aug 30 2022, 5:25 AM
This revision was landed with ongoing or failed builds.Aug 30 2022, 5:46 AM
This revision was automatically updated to reflect the committed changes.