This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix building against clang dylib
ClosedPublic

Authored by mgorny on Oct 24 2022, 7:54 AM.

Diff Detail

Event Timeline

mgorny created this revision.Oct 24 2022, 7:54 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: StephenFan. · View Herald Transcript
mgorny requested review of this revision.Oct 24 2022, 7:54 AM

Hey @mgorny , thanks for working on this

I thought that this build configuration is actually tested by flang-aarch64-dylib, so I'm not sure why it fails for you. I suspect that you only have libclang.dylib available on your system? And the buildbot would still build libClangBasic.so/a as a separate library?

flang/lib/FrontendTool/CMakeLists.txt
18

Where is TARGET defined? Please bear with me - I'm confused that in Flang (which only defines Flang CMake targets) we would be checking whether "target" is a particular Clang target?

Hey @mgorny , thanks for working on this

I thought that this build configuration is actually tested by flang-aarch64-dylib, so I'm not sure why it fails for you. I suspect that you only have libclang.dylib available on your system? And the buildbot would still build libClangBasic.so/a as a separate library?

Yes, we don't install static clang libraries on Gentoo, and the buildbot probably has them (since the targets are present when doing in-tree build).

flang/lib/FrontendTool/CMakeLists.txt
18

Unless I'm mistaken, if you're doing in-tree build of LLVM + Clang + Flang, then targets from other projects should be visible here. FWICS LLVM is ensuring that Clang is processed prior to Flang in all cases, so it should work.

awarzynski added inline comments.Oct 25 2022, 12:01 AM
flang/lib/FrontendTool/CMakeLists.txt
18

Sorry, I was not familiar with if (TARGET <target>), hence my question. For future reference, it's documented under CMake's existance checks.

This makes sense, but I'm thinking that the following would be a bit more idiomatic. I'm also thinking that perhaps libclang-cpp should be added as a dependency too.

if(CLANG_LINK_CLANG_DYLIB)
 add_dependencies(flangFrontendTool clangBasic)
else()
  add_dependencies(flangFrontendTool clang-cpp)
endif()

CLANG_LINK_CLANG_DYLIB is defined whenever LLVM_LINK_LLVM_DYLIB is. So that ^^^ should be safe and always correct. WDYT?

mgorny marked 2 inline comments as done.Oct 25 2022, 1:54 AM
mgorny added inline comments.
flang/lib/FrontendTool/CMakeLists.txt
18

I suppose you meant if the other way around but yes, it should work. I'm going to try it right now and update the patch in a minute.

mgorny updated this revision to Diff 470412.Oct 25 2022, 1:56 AM
mgorny marked an inline comment as done.

Update to use CLANG_LINK_CLANG_DYLIB for the dependency, and to add a dep on clang-cpp alternatively to clangBasic.

awarzynski accepted this revision.Oct 27 2022, 12:52 PM

Thanks for the updates and apologies for the delay, LGTM!

This revision is now accepted and ready to land.Oct 27 2022, 12:52 PM

Which build does this patch fix? My -DLLVM_ENABLE_PROJECTS='llvm;clang;mlir;flang' -DLLVM_LINK_LLVM_DYLIB=on build ninja check-flang works without this patch.

Note also that lldb has some clangBasic uses without the clang-cpp dispatch.

Which build does this patch fix? My -DLLVM_ENABLE_PROJECTS='llvm;clang;mlir;flang' -DLLVM_LINK_LLVM_DYLIB=on build ninja check-flang works without this patch.

Note also that lldb has some clangBasic uses without the clang-cpp dispatch.

-DCLANG_LINK_CLANG_DYLIB=ON when no static libs are installed.

Thanks for the updates and apologies for the delay, LGTM!

No problem. Thanks!

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptOct 28 2022, 12:40 AM
awarzynski added a comment.EditedOct 28 2022, 2:14 AM

Which build does this patch fix? My -DLLVM_ENABLE_PROJECTS='llvm;clang;mlir;flang' -DLLVM_LINK_LLVM_DYLIB=on build ninja check-flang works without this patch.

Note also that lldb has some clangBasic uses without the clang-cpp dispatch.

Ah, we should've looked at LLDB in search for inspiration - they do indeed have a nice solution :) I think that the approach in this patch is fine and we can improve things later (i.e. there's no rush). I created https://github.com/llvm/llvm-project/issues/58663 to track this. Thanks for the pointer @MaskRay !