This is an archive of the discontinued LLVM Phabricator instance.

[llvm-rc]: Find <target>-clang over just clang
ClosedPublic

Authored by thieta on Feb 8 2022, 12:45 AM.

Details

Summary

This patch makes llvm-rc/windres prefer <target>-clang over
clang when doing it's preprocessing. This is so that we can
have a .cfg file for <target> and configure sysroot and other
important flags.

Config files not picked up with clang --target=<target>
automatically.

We only look for <target>-clang in the same dir as llvm-windres
and not for all PATHs to minimize the change.

Diff Detail

Event Timeline

thieta requested review of this revision.Feb 8 2022, 12:45 AM
thieta created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 8 2022, 12:45 AM

For these cases, I guess we'd end up executing <triple>-clang -target <triple>, which is a bit redundant, but it's probably not worth complicating the code to avoid that.

Ideally we'd have a test for this, but I think such a test for this can be pretty hard to fit into the test framework, so it can probably go in without.

llvm/tools/llvm-rc/llvm-rc.cpp
128

Please follow the coding convention of the surrounding code here (local variables starting with a uppercase letter)

131

(Triple + "-clang").str() would probably be simpler here

thieta updated this revision to Diff 406736.Feb 8 2022, 2:04 AM
thieta marked 2 inline comments as done.

Addressed comments from Martin.

thieta added a comment.Feb 8 2022, 2:06 AM

For these cases, I guess we'd end up executing <triple>-clang -target <triple>, which is a bit redundant, but it's probably not worth complicating the code to avoid that.

Yeah I was looking into this - but it seemed a bit complicated to remove the -target in the invocation and made the code more complicated just for a cosmetic issue that is only visible if you pass verbose to llvm-windres and look at the output. It didn't think it was worth it.

Ideally we'd have a test for this, but I think such a test for this can be pretty hard to fit into the test framework, so it can probably go in without.

Same I also looked into this and couldn't figure out a decent way to do this.

mstorsjo accepted this revision.Feb 8 2022, 2:10 AM

LGTM, thanks!

I guess it can be customary to wait until other timezones have been awake for some time too before landing though, in case someone else has something they want to say (even though this is fairly trivial).

This revision is now accepted and ready to land.Feb 8 2022, 2:10 AM
thieta added a comment.Feb 8 2022, 2:12 AM

LGTM, thanks!

I guess it can be customary to wait until other timezones have been awake for some time too before landing though, in case someone else has something they want to say (even though this is fairly trivial).

Yep no hurry - I'll merge this tomorrow.

This revision was landed with ongoing or failed builds.Feb 9 2022, 12:05 AM
This revision was automatically updated to reflect the committed changes.
MaskRay added a subscriber: MaskRay.EditedFeb 9 2022, 12:14 AM

This is so that we can have a .cfg file for <target> and configure sysroot and other important flags.

I know nearly nothing about llvm-rc... but I wonder whether there is a better way.

For the GNU driver part of Clang, the general direction is to move away from $triple-$program.... 3452a0d8c17f7166f479706b293caf6ac76ffd90

https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-b-prefix "Search $prefix$file for executables, libraries, and data files. If $prefix is a directory, search $prefix/$file"

(I try to document everything I know in https://maskray.me/blog/2021-03-28-compiler-driver-and-cross-compilation#search-paths )

This is so that we can have a .cfg file for <target> and configure sysroot and other important flags.

I know nearly nothing about llvm-rc... but I wonder whether there is a better way.

Maybe the config file searching could be expanded to find config files based on target from other things than the target prefix? But that changes more than just around llvm-rc. I suggested that we would look for the sysroot based on the target in this discussion: https://discourse.llvm.org/t/teach-clang-to-find-a-sysroot-based-on-target-in-resource-dir/6100 and the answer to that was the config files, which makes sense since they are a bit more flexible and you might want to set other flags than just --sysroot.