FS#62624 - clang package is using BUILD_SHARED_LIBS=ON but this is an unsupported configuration

Attached to Project: Arch Linux
Opened by Wink Saville (winksaville) - Monday, 13 May 2019, 19:35 GMT
Last edited by Evangelos Foutras (foutrelis) - Friday, 24 May 2019, 09:23 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To No-one
Architecture All
Severity High
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 1
Private No

Details

Description:
I was unable to build Zig (https://ziglang.org) unless I built llvm and clang myself.

The reason is that the only supported clang configuration is statically linking
with libclang*.a files. Using BUILD_SHARED_LIBS=ON is not a supported configuration
for any of the llvm tools as stated in [building LLVM with CMake](https://llvm.org/docs/CMake.html):
```
BUILD_SHARED_LIBS is only recommended for use by LLVM developers. If you want to build LLVM as a shared library, you should use the LLVM_BUILD_LLVM_DYLIB option.
```

So Zig needs the libclang*.a files to build, but those aren't available in the clang package:
```
$ ls /usr/lib/libclang*.a
ls: cannot access '/usr/lib/libclang*.a': No such file or directory
```
Only the libclang*.so files are available
```
$ ls /usr/lib/libclang*.so
/usr/lib/libclangAnalysis.so /usr/lib/libclangFrontendTool.so /usr/lib/libclangStaticAnalyzerCheckers.so /usr/lib/libclangTidyObjCModule.so
/usr/lib/libclangApplyReplacements.so /usr/lib/libclangHandleCXX.so /usr/lib/libclangStaticAnalyzerCore.so /usr/lib/libclangTidyPerformanceModule.so
/usr/lib/libclangARCMigrate.so /usr/lib/libclangHandleLLVM.so /usr/lib/libclangStaticAnalyzerFrontend.so /usr/lib/libclangTidyPlugin.so
/usr/lib/libclangASTMatchers.so /usr/lib/libclangIncludeFixerPlugin.so /usr/lib/libclangTidyAbseilModule.so /usr/lib/libclangTidyPortabilityModule.so
/usr/lib/libclangAST.so /usr/lib/libclangIncludeFixer.so /usr/lib/libclangTidyAndroidModule.so /usr/lib/libclangTidyReadabilityModule.so
/usr/lib/libclangBasic.so /usr/lib/libclangIndex.so /usr/lib/libclangTidyBoostModule.so /usr/lib/libclangTidy.so
/usr/lib/libclangChangeNamespace.so /usr/lib/libclangLex.so /usr/lib/libclangTidyBugproneModule.so /usr/lib/libclangTidyUtils.so
/usr/lib/libclangCodeGen.so /usr/lib/libclangMove.so /usr/lib/libclangTidyCERTModule.so /usr/lib/libclangTidyZirconModule.so
/usr/lib/libclangCrossTU.so /usr/lib/libclangParse.so /usr/lib/libclangTidyCppCoreGuidelinesModule.so /usr/lib/libclangToolingASTDiff.so
/usr/lib/libclangDaemon.so /usr/lib/libclangQuery.so /usr/lib/libclangTidyFuchsiaModule.so /usr/lib/libclangToolingCore.so
/usr/lib/libclangDoc.so /usr/lib/libclangReorderFields.so /usr/lib/libclangTidyGoogleModule.so /usr/lib/libclangToolingInclusions.so
/usr/lib/libclangDriver.so /usr/lib/libclangRewriteFrontend.so /usr/lib/libclangTidyHICPPModule.so /usr/lib/libclangToolingRefactor.so
/usr/lib/libclangDynamicASTMatchers.so /usr/lib/libclangRewrite.so /usr/lib/libclangTidyLLVMModule.so /usr/lib/libclangTooling.so
/usr/lib/libclangEdit.so /usr/lib/libclangSema.so /usr/lib/libclangTidyMiscModule.so
/usr/lib/libclangFormat.so /usr/lib/libclangSerialization.so /usr/lib/libclangTidyModernizeModule.so
/usr/lib/libclangFrontend.so /usr/lib/libclang.so /usr/lib/libclangTidyMPIModule.so
```


Additional info:
* package version(s):
A quick look at the history of PKGBUILD, this has been the case at least since clang was split from
llvm in March 2018 with change ca81062dc3ce320dfd7ff52bd40d56ebc304d698.

* link to upstream:
See [D61804](https://reviews.llvm.org/D61804) where I'm investigating a solution
which both static and shared libs can be built.

Steps to reproduce:
Install clang with pacman and try to build a program that needs libclang*.a, such as Zig.
This task depends upon

Closed by  Evangelos Foutras (foutrelis)
Friday, 24 May 2019, 09:23 GMT
Reason for closing:  Deferred
Additional comments about closing:  Will revisit this when clang 9 is out.
Comment by Jake Kreiger (Magali75) - Monday, 13 May 2019, 22:21 GMT
Right, BUILD_SHARED_LIBS should be removed and LLVM_LINK_LLVM_DYLIB:ON ans optionally LLVM_BUILD_LLVM_DYLIB:ON added
Comment by Wink Saville (winksaville) - Wednesday, 15 May 2019, 05:54 GMT
Also, there is now a better solution being proposed for creating a libclang dynamic library, libclang_shared.so, see https://reviews.llvm.org/D61909).
Comment by Wink Saville (winksaville) - Thursday, 16 May 2019, 23:33 GMT
Here, https://reviews.llvm.org/D62040, is a change which provides documention distributing LLVM and its subprojects for distrubutation.
Comment by Evangelos Foutras (foutrelis) - Friday, 17 May 2019, 18:29 GMT
community/zig 0.4.0-1 seems to link to extra/clang just fine.

Of course, if CLANG_LINK_CLANG_DYLIB is introduced upstream in clang 9, I'll switch to that.
Comment by Wink Saville (winksaville) - Friday, 17 May 2019, 19:45 GMT
It's because they have to turn off --link-static (https://git.archlinux.org/svntogit/community.git/tree/trunk/force_dynamic_llvm.patch?h=packages/zig).
And I think this turns off creating a stage2 compiler: https://git.archlinux.org/svntogit/community.git/tree/trunk/no_stage2_artifacts.patch?h=packages/zig.

Not a great solution.

@foutrelis, have you had time to look at the new documentation being prepared (https://reviews.llvm.org/D62040),
it would be great to get your perspective?
Comment by Evangelos Foutras (foutrelis) - Friday, 17 May 2019, 20:35 GMT
I don't have anything to add right now. It seems the need for dynamically linking clang tools to clang libraries has already been identified. [1]

Without BUILD_SHARED_LIBS=ON the clang package (which includes clang-tools-extra to address  FS#50865 ) would grow to about 770 MiB which is too large.

Also note that the patch to avoid "--link-static" is for linking to libLLVM.so. Zig finds the shared clang libraries without modification, though it likely fails to run when mixing those with static LLVM libraries.

I'll close this if you don't mind, with the intention of transitioning to CLANG_LINK_CLANG_DYLIB if it becomes available in clang 9.

[1] https://reviews.llvm.org/D61909#1501733
Comment by Wink Saville (winksaville) - Saturday, 18 May 2019, 15:36 GMT
Closing this is fine, but I'd like to beable to discuss LLVM_DISTRIBUTION_COMPONENTS that could be here, or maybe you'd like to do it on llvm-dev or ... ?
Comment by Wink Saville (winksaville) - Saturday, 18 May 2019, 18:25 GMT

Loading...