@@ -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 ??= ""
@@ -72,15 +72,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"
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> --- meta/classes-recipe/cargo_common.bbclass | 23 ++++++++++++++++++++++ meta/recipes-devtools/rust/cargo_1.96.1.bb | 9 --------- 2 files changed, 23 insertions(+), 9 deletions(-)