Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 720742 - dev-libs/json-c-0.14 ignores USE="static-libs"
Summary: dev-libs/json-c-0.14 ignores USE="static-libs"
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: No maintainer - Look at https://wiki.gentoo.org/wiki/Project:Proxy_Maintainers if you want to take care of it
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-02 23:48 UTC by Igor Rafienko
Modified: 2020-05-13 23:22 UTC (History)
4 users (show)

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


Attachments
Patch to add a live ebuild (json-c_add-live-ebuild.patch,1.54 KB, patch)
2020-05-08 09:46 UTC, hofnarr
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Rafienko 2020-05-02 23:48:57 UTC
As of json-c-0.14, USE="static-libs" has no effect:

$ emerge -vp json-c
[ebuild   R    ] dev-libs/json-c-0.14:0/5::gentoo [0.14:0/5::local-hacks] USE="static-libs threads -doc" ABI_X86="(64) -32 (-x32)" 0 KiB
(...)
$ qlist json-c | grep libjson-c
/usr/lib64/libjson-c.so
/usr/lib64/libjson-c.so.5
/usr/lib64/libjson-c.so.5.0.0

The reason for this is that the CMakeFile allows building EITHER a static library OR a shared library, but never both.

Unpacking the packages and doing manually:

cmake -DBUILD_SHARED_LIBS=OFF . && make

... produces in fact libjson-c.a

This would not have been a huge issue, had a number of packages using static-libs been dependent on json-c (cryptsetup was what triggered my research).

Simply running cmake twice, once with -DBUILD_SHARED_LIBS=OFF and once with -DBUILD_SHARED_LIBS=ON yield all of the "required" library files.

Reproducible: Always

Steps to Reproduce:
1. USE="static-libs" emerge -v json-c
2. Examine /usr/lib/libjson-c.*
3. Observe the absence of libjson-c.a
Actual Results:  
Only libjson-c.so* files are present in /usr/lib/

Expected Results:  
libjson-c.so* and libjson-c.a should both be installed in /usr/lib/
Comment 1 Jakov Smolić archtester gentoo-dev 2020-05-04 13:44:46 UTC
Hi, thank you for submitting this, I'll be working on fixing this as a part of https://github.com/gentoo/gentoo/pull/15586.

static-libs config part has been left out of the version bump, so right now this flag has no effect whatsoever because it is not tied to any cmake option. 
For now I've found a way to build either static or shared library, because as you have mentioned CMAke lists doesn't enable this.

I also found this comment in the CMakeLists file https://github.com/json-c/json-c/blob/master/CMakeLists.txt#L384

So I'll try to investigate further whether it will be possible to build both shared and static libs :)
Comment 2 Jakov Smolić archtester gentoo-dev 2020-05-04 13:46:31 UTC
(In reply to Jakov Smolic from comment #1)
> For now I've found a way to build either static or shared library, because
> as you have mentioned CMAke lists doesn't enable this.
** sentence correction - CMakeLists doesn't enable building both static and shared libs
Comment 3 Igor Rafienko 2020-05-04 19:21:24 UTC
(In reply to Jakov Smolic from comment #2)

> ** sentence correction - CMakeLists doesn't enable building both static and
> shared libs

Would it be possible to build first one, then the other? This sequence (in the same workdir, even):

1) cmake -DBUILD_SHARED_LIBS=ON && make
2) cmake -DBUILD_SHARED_LIBS=OFF && make
3) install both *.a and *.so (and whatever else).

Step #2 could be contingent on if use static ; then ...

It is a bit of a hack, though
Comment 4 Jakov Smolić archtester gentoo-dev 2020-05-04 20:20:28 UTC
(In reply to Igor Rafienko from comment #3)
> (In reply to Jakov Smolic from comment #2)
> 
> > ** sentence correction - CMakeLists doesn't enable building both static and
> > shared libs
> 
> Would it be possible to build first one, then the other? This sequence (in
> the same workdir, even):
> 
Hmm, I don't think that would be doable with ebuild.

However I tried something similar. I inspected  the cmake-configure wrapper script 
https://github.com/json-c/json-c/blob/master/cmake-configure#L64

and it seems to pass by default both -DBUILD_SHARED_LIBS=ON and -DBUILD_SHARED_LIBS=OFF.

So I set -DBUILD_SHARED_LIBS=ON by default and if the static-libs is set, add in -DBUILD_SHARED_LIBS=OFF, but that only builds static, not the dynamic as well...

I've inquired about this to the json-c upstream so if they offer some solution I will incorporate it in the ebuild and let you know.
Comment 5 hofnarr 2020-05-08 00:07:59 UTC
FWIW, I temporarily worked around this issue by fixing CMakeLists.txt (https://github.com/dota17/json-c/pull/90) and writing a live ebuild with following line added inside `multilib_src_configure()`:

-DBUILD_STATIC_LIBS=$(usex static-libs)
Comment 6 Jakov Smolić archtester gentoo-dev 2020-05-08 08:34:24 UTC
Thanks for adding that :)
0.14 is going to have to be as it is right now. We have to wait for next release to include it in the ebuild.

Though I can add live ebuild in my pull request as a solution for those that wish to build both libraries.
Comment 7 hofnarr 2020-05-08 09:46:09 UTC
Created attachment 636830 [details, diff]
Patch to add a live ebuild

Ok! Attached is the live ebuild I'm using at the moment (git patch).

Also thought if it's possible to release a new version of the package -- 0.14-r1? The ebuild would patch CMakeLists.txt to include the fixes from master. That would provide a meaningful solution in the meantime. I can send a patch for review, if that sounds good.
Comment 8 Jakov Smolić archtester gentoo-dev 2020-05-08 12:31:00 UTC
Patch for 0.14 ebuild would be nice, maybe even better than adding live ebuild, although we can also add 9999 ebuild for those that wish to have latest upstream changes.

Maybe you can push the patch to github and rthen I can cherry pick it into already opened pull request
Comment 9 hofnarr 2020-05-08 18:00:11 UTC
(In reply to Jakov Smolic from comment #8)
> Maybe you can push the patch to github and rthen I can cherry pick it into
> already opened pull request

I pushed both patches to my branch on Github, see https://github.com/hofnarrr/gentoo/tree/json-c-patches

Hope it helps! Please let me know if there's something noteworthy in the patches.
Comment 10 Jakov Smolić archtester gentoo-dev 2020-05-08 19:26:22 UTC
Thanks, great work :) 
I cherry-picked your two commits into the pull request (https://github.com/gentoo/gentoo/pull/15586/commits)

I just made one small correction on the 0.14 patch - I set static-libs support to OFF by default, and included -DBUILD_STATIC_LIBS=$(usex static-libs) in the src_configure part of the ebuild. That way static library is built if user turns on static-libs USE flag.

Thanks for helping out with this.
Comment 11 hofnarr 2020-05-08 21:32:25 UTC
(In reply to Jakov Smolic from comment #10) 
> I [...] included -DBUILD_STATIC_LIBS=$(usex static-libs)
> in the src_configure part of the ebuild. That way static
> library is built if user turns on static-libs USE flag.

Oh, good catch. My pretty unorthodox ebuild dev workflow might explain why it was missing from the r1-patch, oh well!

Thanks for taking the time to get these patches to the mainline, appreciate it!
Comment 12 Larry the Git Cow gentoo-dev 2020-05-12 13:57:43 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=34cc9b34ece4e078343c264acaf4b9962a57969b

commit 34cc9b34ece4e078343c264acaf4b9962a57969b
Author:     Anssi Jaatinen <hofnarr@hofnarr.fi>
AuthorDate: 2020-05-08 17:48:22 +0000
Commit:     Joonas Niilola <juippis@gentoo.org>
CommitDate: 2020-05-12 13:57:12 +0000

    dev-libs/json-c: add patch for static-libs support
    
    Enable building both static and shared libraries.
    Closes: https://bugs.gentoo.org/720742
    
    Signed-off-by: Anssi Jaatinen <hofnarr@hofnarr.fi>
    Signed-off-by: Jakov Smolic <jakov.smolic@sartura.hr>
    Signed-off-by: Luka Perkov <luka.perkov@sartura.hr>
    Signed-off-by: Joonas Niilola <juippis@gentoo.org>

 .../files/json-c-0.14_cmake-static-libs.patch      | 56 ++++++++++++++++++++++
 .../{json-c-0.14.ebuild => json-c-0.14-r1.ebuild}  |  5 ++
 2 files changed, 61 insertions(+)