ImageOptim / libimagequant

Palette quantization library that powers pngquant and other PNG optimizers
https://pngquant.org/lib
Other
780 stars 132 forks source link

libimagequant_sys: missing shared library #109

Closed 0-wiz-0 closed 1 year ago

0-wiz-0 commented 1 year ago

The rust version is supposed to replace the C version. Right now, the rust version only provides a static library. However, this leads to gd's library only existing as a static library and graphviz having problems, because it wants to build a shared object that's loaded at runtime, for which it would need a shared library. I have no idea how to do this from rust, but librsvg does provide a shared library, and at least big parts of it are in rust (perhaps there's a C wrapper for the shared object, I haven't looked). Please provide a shared object for libimagequant. Thanks.

kornelski commented 1 year ago

Rust can build a shared library, but the default cargo build has bad defaults, so it needs an extra help:

cd imagequant-sys/
cargo install cargo-c
cargo cinstall # set appropriately --prefix=/usr/bin --destdir=/
0323pin commented 1 year ago

It seems that the suggested, https://github.com/rust-lang/cargo/issues/5045#issuecomment-501772202 fix to use cdylib-link-lines to generate the shared object is no longer an option as the crate seems to be dead.

Like you pointed on the referenced thread, we are interested in building the share object, not to directly install it as with cargo cinstall. Is there a workaround to generate it inside the "normal" target/release directory?

kornelski commented 1 year ago

cargo cinstall takes --destdir=staging that pretend-installs it in another directory, which you can then package.

Alternatively, modify Cargo.toml and change

[lib]
crate-type = ["staticlib", "lib"]

to

[lib]
crate-type = ["staticlib", "lib", "cdylib"]

to get the default Cargo behavior and a dynamic library in target/release, but due to soname/rpath issues it will work only from the target/ dir, not when installed system-wide. You can fix the shared library to be better behaved if you have tooling to do so.

0323pin commented 1 year ago

@kornelski Sorry for nor reporting back earlier, I would say this can be closed now. We have fixed it following your suggestion of using cargp-c, see package Makefile below:

# $NetBSD: Makefile,v 1.31 2023/06/06 12:41:34 riastradh Exp $

DISTNAME=   libimagequant-4.2.0
CATEGORIES= graphics
MASTER_SITES+=  ${MASTER_SITE_GITHUB:=ImageOptim/}
GITHUB_TAG= ${PKGVERSION_NOREV}

MAINTAINER= adam@NetBSD.org
HOMEPAGE=   https://pngquant.org/lib/
COMMENT=    High-quality conversion of RGBA images to 8-bit indexed-color
LICENSE=    gnu-gpl-v3

TOOL_DEPENDS+=  cargo-c>=0.9.19:../../devel/cargo-c

WRKSRC=     ${WRKDIR}/${DISTNAME}/imagequant-sys

PKGCONFIG_OVERRIDE=     ${DESTDIR}${PREFIX}/lib/pkgconfig/imagequant.pc
PKGCONFIG_OVERRIDE_STAGE=   post-install

.include "cargo-depends.mk"

do-install:
    cd ${WRKSRC} && ${RUN} cargo cinstall --destdir=${DESTDIR} --prefix=${PREFIX} --libdir=${PREFIX}/lib

.include "../../lang/rust/cargo.mk"
.include "../../mk/bsd.pkg.mk"

This way it now installs the following files:

include/libimagequant.h
lib/libimagequant.a
lib/libimagequant.so
lib/libimagequant.so.0
lib/libimagequant.so.0.0.0
lib/pkgconfig/imagequant.pc

Unless @0-wiz-0 thinks differently, this is solved.

0-wiz-0 commented 1 year ago

Yes, sorry for not giving feedback earlier - cargo cinstall is fine, thanks for the explanations!