Project:Rust/sys crates

From Gentoo Wiki
Jump to:navigation Jump to:search

The "*-sys" crates generally provides interfaces to C/C++ libraries from Rust. They are generally very inconsistent. In general, we can find crates that do one of the following:

  • require and use system libraries
  • default to using system libraries, but silently fall back to vendored dependencies
  • default to using vendored dependencies, but support enabling linking to system libraries
  • unconditionally use vendored dependencies

app-portage/iwdevtools can be used to detect missing dependencies if the binaries actually linked to them. Eli Schwartz's cargo_vendored_code check can be copied into /usr/local/lib/install-qa-check.d/99rust to help finding crates that vendor stuff. However, in the end the maintainer needs to manually investigate all *-sys crates used in the project, determine how to make them use system libraries and what dependencies to add.

This wiki page aims to collect information on different *-sys crates, to help with fixing current ebuilds and designing a more future-proof solution.

bzip2-sys

bzip2-sys defaults to using the system libbz2 but it requires bzip2.pc that is not provided by Gentoo. A workaround is to create one in the ebuild:

CODE Create bzip2.pc
mkdir "${T}/pkg-config" || die
export PKG_CONFIG_PATH=${T}/pkg-config${PKG_CONFIG_PATH+:${PKG_CONFIG_PATH}}
cat >> "${T}/pkg-config/bzip2.pc" <<-EOF || die
	Name: bzip2
	Version: 9999
	Description:
	Libs: -lbz2
EOF

The issue has been reported upstream: bzip2-rs: Please support linking against system bzip2 without pkg-config.

libdeflate-sys

libdeflate-sys supports using the system library but pins to a very specific version of it. A good workaround is to remove the pin:

CODE Remove libdeflate-sys pin
sed -i -e '/exactly_version/d' \
	"${ECARGO_VENDOR}"/libdeflate-sys-*/build.rs || die

zstd-sys

zstd-sys supports linking to system libzstd via envvar:

CODE Enable system libzstd
export ZSTD_SYS_USE_PKG_CONFIG=1