Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 689410 - cmake.eclass should set library search suffix for riscv
Summary: cmake.eclass should set library search suffix for riscv
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Eclasses (show other bugs)
Hardware: riscv Linux
: Normal normal
Assignee: Gentoo KDE team
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks: 720296
  Show dependency tree
 
Reported: 2019-07-07 15:08 UTC by Marcus Comstedt
Modified: 2021-08-22 15:51 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch to cmake-utils.eclass to set CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX on riscv (cmake-utils.eclass.patch,715 bytes, patch)
2019-07-07 15:08 UTC, Marcus Comstedt
Details | Diff
Proposed patch to cmake for find_package() (find_package.patch,1.38 KB, patch)
2019-10-06 12:43 UTC, Marcus Comstedt
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marcus Comstedt 2019-07-07 15:08:02 UTC
Created attachment 582126 [details, diff]
Patch to cmake-utils.eclass to set CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX on riscv

The CMake function find_library has some heuristics which can find libraries in e.g. /usr/lib64, but which can not handle the two level libdir of the riscv profiles.

Thus, the suffix to append to "/usr/lib" etc needs to be hardcoded using the cmake variable CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX.

The attached patch does just that, and with it I am able to emerge both cmake itself and dev-util/schroot, a package which uses cmake to build.

Potentially the CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX could be set on all arches, but that would probably require much more testing.
Comment 1 Andreas Sturmlechner gentoo-dev 2019-07-07 19:21:54 UTC
I have no idea about riscv.
Comment 2 Marcus Comstedt 2019-07-23 21:45:13 UTC
(In reply to Andreas Sturmlechner from comment #1)
> I have no idea about riscv.

Hi.

Are you blocked on some information about riscv that you need?

The libdir in the riscv profiles contain a second level with the ABI name,
and as such are e.g. "lib64/lp64d", with the libraries placed under /usr/lib64/lp64d/.  So there are no libraries directly under /usr/lib64/, and thus cmake's heuristic of looking for libs in /usr/lib64/ will not work.  Using the CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX override to directly point out the correct libdir does work though.
Comment 3 Göktürk Yüksek archtester gentoo-dev 2019-10-06 00:28:34 UTC
@marcus, we'll have to send this as a patch to gentoo-dev for approval. Do we not need something similar for find_package()? pc files have the same issue.
Comment 4 Marcus Comstedt 2019-10-06 09:25:14 UTC
You mean -config.cmake files, right?  .pc files are for pkg-config, not cmake.

But yes, it seems that we need to do something about find_package() as well.
However, in this case it can't be fixed just with the eclass.

cmFindLibraryCommand.cxx adds

  ${CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX}

to the search list, but cmFindPackageCommand.cxx adds

  lib/${CMAKE_LIBRARY_ARCHITECTURE}

(note the "lib/" first, where we need lib64/...)

So a patch to cmake itself (can be upstreamed) is also needed.
Comment 5 Marcus Comstedt 2019-10-06 10:58:49 UTC
As a tangential comment, I don't quite understand why the libdir is not
lib/lp64d (which would work with the CMAKE_LIBRARY_ARCHITECTURE setting)
rather than lib64/lp64d...  Why do we need to specify "64" twice?
Comment 6 Marcus Comstedt 2019-10-06 12:43:28 UTC
Created attachment 591974 [details, diff]
Proposed patch to cmake for find_package()

Since cmFindPackageCommand already uses FIND_LIBRARY_USE_LIB32_PATHS and
FIND_LIBRARY_USE_LIB64_PATHS, I figured it would make sense for it to
honour CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX as well.  This way no additional
change to the eclass is needed.

I have tested that find_package(libxml2) works correctly with this patch
(it didn't without).
Comment 7 Göktürk Yüksek archtester gentoo-dev 2019-10-17 14:57:54 UTC
(In reply to Marcus Comstedt from comment #6)
> Created attachment 591974 [details, diff] [details, diff]
> Proposed patch to cmake for find_package()
> 
> Since cmFindPackageCommand already uses FIND_LIBRARY_USE_LIB32_PATHS and
> FIND_LIBRARY_USE_LIB64_PATHS, I figured it would make sense for it to
> honour CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX as well.  This way no additional
> change to the eclass is needed.
> 
> I have tested that find_package(libxml2) works correctly with this patch
> (it didn't without).

I tested the patch with clang, and can confirm that it works.
(In reply to Marcus Comstedt from comment #5)
> As a tangential comment, I don't quite understand why the libdir is not
> lib/lp64d (which would work with the CMAKE_LIBRARY_ARCHITECTURE setting)
> rather than lib64/lp64d...  Why do we need to specify "64" twice?

"""
In the new profiles, the lib->lib64 compatibility symlink is removed.
64-bit libraries need to be installed directly to lib64.  /lib
and /usr/lib become real directories, that are used for cross-arch
and native non-library packages (gcc, clang) and 32-bit libraries
on the multilib profile (which improves compatibility with prebuilt x86
packages).
"""
https://www.gentoo.org/support/news-items/2019-06-05-amd64-17-1-profiles-are-now-stable.html
Comment 8 Marcus Comstedt 2019-10-17 16:28:31 UTC
(In reply to Göktürk Yüksek from comment #7)

> 64-bit libraries need to be installed directly to lib64.

Except that they aren't.  They are installed in lib64/lp64d.  So the letter of this rule is already violated.  And I don't think installing them in lib/lp64d would go against the spirit of the rule (which is to not look for 64-bit libraries directly under lib).
Comment 9 Göktürk Yüksek archtester gentoo-dev 2019-10-25 20:00:31 UTC
(In reply to Marcus Comstedt from comment #8)
> (In reply to Göktürk Yüksek from comment #7)
> 
> > 64-bit libraries need to be installed directly to lib64.
> 
> Except that they aren't.  They are installed in lib64/lp64d.  So the letter
> of this rule is already violated.  And I don't think installing them in
> lib/lp64d would go against the spirit of the rule (which is to not look for
> 64-bit libraries directly under lib).

My understanding is that lib64/lp64{,d} is required to support multilib: https://www.sifive.com/blog/all-aboard-part-5-risc-v-multilib. If I have two variants of the same library, one supporting the ABI lp64 and another supporting lp64d, how would I keep them on the same machine without introducing path collisions?
Comment 10 Marcus Comstedt 2019-10-25 20:21:48 UTC
By putting them in lib/lp64/ and lib/lp64d/ respectively.  It's the need to put the 64-bit ABI directories under "lib64" rather than "lib" that I do not understand.  It just ends up saying "64" twice...
Comment 11 Göktürk Yüksek archtester gentoo-dev 2019-10-25 20:34:50 UTC
(In reply to Marcus Comstedt from comment #10)
> By putting them in lib/lp64/ and lib/lp64d/ respectively.  It's the need to
> put the 64-bit ABI directories under "lib64" rather than "lib" that I do not
> understand.  It just ends up saying "64" twice...

I think it's there to prevent hypothetical problems of using the same ABI names on different bit-width architecture variants. Imagine that in the future we added support for rv32 and it also supports the lp64 ABI. And I want to compile a library targeting (rv32,lp64) and (rv64,lp64) configurations. If you were to put everything in lib/, you'd introduce a collision again.

Obviously this is not a realistic scenario. The ABIs for rv32 and rv64 do not intersect. But I think the lib32/lib64 separation provides a more generic solution. Using the example above, you'd have lib32/lp64 and lib64/lp64 and there would be no collisions.
Comment 12 Marcus Comstedt 2019-10-25 21:40:35 UTC
Yeah, that doesn't really make much sense.  If the ABI:s are different they should not have the same name.  And if the ABI:s are the same the library should be the same regardless of what hardware you run it on...
Comment 13 Marcus Comstedt 2020-01-04 10:53:16 UTC
Note:  The new "cmake.eclass" also needs to set CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX on riscv.
Comment 14 Larry the Git Cow gentoo-dev 2020-07-24 21:26:10 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=89d746829c14ffb7ea1cc2de97bab63d0b77fdb5

commit 89d746829c14ffb7ea1cc2de97bab63d0b77fdb5
Author:     Andreas K. Hüttel <dilfridge@gentoo.org>
AuthorDate: 2020-07-24 21:24:36 +0000
Commit:     Andreas K. Hüttel <dilfridge@gentoo.org>
CommitDate: 2020-07-24 21:25:56 +0000

    cmake*.eclass: Hardcode CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX for riscv
    
    Bug: https://bugs.gentoo.org/689410
    Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>

 eclass/cmake-utils.eclass | 6 ++++++
 eclass/cmake.eclass       | 6 ++++++
 2 files changed, 12 insertions(+)
Comment 15 Larry the Git Cow gentoo-dev 2020-07-24 21:29:36 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/kde.git/commit/?id=7318b8b9cfc9d2a172e75701ea95f63f7cffa0f5

commit 7318b8b9cfc9d2a172e75701ea95f63f7cffa0f5
Author:     Andreas K. Hüttel <dilfridge@gentoo.org>
AuthorDate: 2020-07-24 21:24:36 +0000
Commit:     Andreas K. Hüttel <dilfridge@gentoo.org>
CommitDate: 2020-07-24 21:29:04 +0000

    cmake*.eclass: Hardcode CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX for riscv
    
    Bug: https://bugs.gentoo.org/689410
    Signed-off-by: Andreas K. Hüttel <dilfridge@gentoo.org>

 eclass/cmake.eclass | 6 ++++++
 1 file changed, 6 insertions(+)
Comment 16 Andreas Sturmlechner gentoo-dev 2021-08-22 15:11:25 UTC
Can we consider this fixed then?