diff mbox series

[meta-lts-mixins,scarthgap/rust,12/37] cargo: centralise anti-vendoring environment variables

Message ID d2b5f157ecb8e879e3a21132841c6dda48b31dbe.1789156653.git.scott.murray@konsulko.com
State New
Headers show
Series Update to 1.98.1 | expand

Commit Message

Scott Murray Sept. 11, 2026, 8:12 p.m. UTC
From: Ross Burton <ross.burton@arm.com>

The cargo recipe has exports to stop the libssh2-sys (and git2-sys, but
disabled) crate from vendoring the C code into the built binary and
instead link to the shared libraries that we already have built.

This is desirable because it means that we have a single copy of say
libssh2 on the system that can be updated easily, instead of potentially
multiple different versions embedded in rust binaries.

This isn't specific to cargo, so move it into cargo_common so that all
recipes that build crates don't vendor C code.

The git2-sys linking was disabled due to incompatibilities with older
versions, but this appears to be historical now and git2-sys will link
dynamically if the library can be found. Force this by exporting the
variable so it refuses to build if it can't link.

Add anti-vendoring exports for libsqlite3-sys, openssl-sys, and
zstd-sys.  Also explicitly tell pkg-config-sys that we'd prefer to never
build vendorered code, and link dynamically not statically.

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(adapted from oe-core commit 6634a9a273e59a9671ce37d8ec84bb67b08b74d6)
Signed-off-by: Scott Murray <scott.murray@konsulko.com>
---
 classes-recipe/cargo_common.bbclass   | 23 +++++++++++++++++++++++
 recipes-devtools/rust/cargo_1.96.1.bb |  9 ---------
 2 files changed, 23 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/classes-recipe/cargo_common.bbclass b/classes-recipe/cargo_common.bbclass
index 34fd1e7..7ff2351 100644
--- a/classes-recipe/cargo_common.bbclass
+++ b/classes-recipe/cargo_common.bbclass
@@ -226,6 +226,29 @@  oe_cargo_fix_env () {
 	export HOST_CFLAGS="${BUILD_CFLAGS}"
 	export HOST_CXXFLAGS="${BUILD_CXXFLAGS}"
 	export HOST_AR="${BUILD_AR}"
+
+	# Tell crates to use system libraries instead of vendoring C code
+
+	# git2-rs
+	export LIBGIT2_NO_VENDOR="1"
+
+	# libssh2-sys
+	export LIBSSH2_SYS_USE_PKG_CONFIG="1"
+
+	# libsqlite3-sys
+	export LIBSQLITE3_SYS_USE_PKG_CONFIG="1"
+
+	# openssl-sys
+	export OPENSSL_NO_VENDOR="1"
+
+	# pkg-config-rs. Crates can still override the dynamic linking
+	# but try to dynamically link to system libraries.
+	# https://docs.rs/pkg-config/latest/pkg_config/
+	export SYSTEM_DEPS_BUILD_INTERNAL="never"
+	export PKG_CONFIG_ALL_DYNAMIC="1"
+
+	# zstd-sys
+	export ZSTD_SYS_USE_PKG_CONFIG="1"
 }
 
 EXTRA_OECARGO_PATHS ??= ""
diff --git a/recipes-devtools/rust/cargo_1.96.1.bb b/recipes-devtools/rust/cargo_1.96.1.bb
index 35e9cf9..99cac69 100644
--- a/recipes-devtools/rust/cargo_1.96.1.bb
+++ b/recipes-devtools/rust/cargo_1.96.1.bb
@@ -73,15 +73,6 @@  do_install:append:class-nativesdk() {
 
 FILES:${PN} += "${base_prefix}/environment-setup.d"
 
-# Disabled due to incompatibility with libgit2 0.28.x (https://github.com/rust-lang/git2-rs/issues/458, https://bugs.gentoo.org/707746#c1)
-# as shipped by Yocto Dunfell.
-# According to https://github.com/rust-lang/git2-rs/issues/458#issuecomment-522567539, there are no compatibility guarantees between
-# libgit2-sys and arbitrary system libgit2 versions, so better keep this turned off.
-#export LIBGIT2_SYS_USE_PKG_CONFIG = "1"
-
-# Needed for pkg-config to be used
-export LIBSSH2_SYS_USE_PKG_CONFIG = "1"
-
 # When building cargo-native we don't have cargo-native to use and depend on,
 # so we must use the locally set up snapshot to bootstrap the build.
 BASEDEPENDS:remove:class-native = "cargo-native"