diff --git a/crates/rattler_build_core/src/post_process/checks.rs b/crates/rattler_build_core/src/post_process/checks.rs index 06d028328..08bae0695 100644 --- a/crates/rattler_build_core/src/post_process/checks.rs +++ b/crates/rattler_build_core/src/post_process/checks.rs @@ -630,6 +630,11 @@ pub fn perform_linking_checks( tracing::trace!("Package files: {package_files:#?}"); + let canonical_new_files: HashSet = new_files + .iter() + .filter_map(|file| dunce::canonicalize(file).ok()) + .collect(); + let mut linked_packages = Vec::new(); for package in package_files.iter() { let mut link_info = PackageLinkInfo { @@ -697,8 +702,14 @@ pub fn perform_linking_checks( continue; } - // Check if the package itself has the shared library. - if new_files.iter().any(|file| file.ends_with(lib)) { + // Check if the package itself has the shared library. `new_files` + // holds only regular files, while `lib` is usually the SONAME + // symlink (e.g. `lib/libfoo.so.1` -> `libfoo.so.1.2.3`), so also + // accept a symlink in the package whose target is one of them. + if new_files.iter().any(|file| file.ends_with(lib)) + || dunce::canonicalize(tmp_prefix.join(lib)) + .is_ok_and(|target| canonical_new_files.contains(&target)) + { link_info.linked_packages.push(LinkedPackage { name: lib.to_path_buf(), link_origin: LinkOrigin::PackageItself, diff --git a/test-data/recipes/linking-own-soname-symlink/recipe.yaml b/test-data/recipes/linking-own-soname-symlink/recipe.yaml new file mode 100644 index 000000000..5c065add6 --- /dev/null +++ b/test-data/recipes/linking-own-soname-symlink/recipe.yaml @@ -0,0 +1,19 @@ +package: + name: linking-own-soname-symlink + version: "1.0" + +build: + script: | + mkdir -p $PREFIX/lib + echo 'int a(void) { return 1; }' > a.c + echo 'int a(void); int b(void) { return a(); }' > b.c + $CC -shared -fPIC a.c -Wl,-soname,liba.so.3 -o $PREFIX/lib/liba.so.3.0.0 + ln -s liba.so.3.0.0 $PREFIX/lib/liba.so.3 + ln -s liba.so.3 $PREFIX/lib/liba.so + $CC -shared -fPIC b.c -L$PREFIX/lib -la -Wl,-rpath,'$ORIGIN' -o $PREFIX/lib/libb.so + dynamic_linking: + overlinking_behavior: error + +requirements: + build: + - ${{ compiler('c') }} diff --git a/test/end-to-end/test_simple.py b/test/end-to-end/test_simple.py index ad2a4ef4d..6b48b9b55 100644 --- a/test/end-to-end/test_simple.py +++ b/test/end-to-end/test_simple.py @@ -3585,6 +3585,23 @@ def test_linking_symlinked_soname( assert "lib/libgomp.so.1 (_openmp_mutex)" in output +@pytest.mark.skipif(platform.system() != "Linux", reason="Linux-only test") +def test_linking_own_soname_symlink( + rattler_build: RattlerBuild, recipes: Path, tmp_path: Path +): + """`libb.so` links `liba.so.3`, a SONAME symlink in the same package that + points to `liba.so.3.0.0`. The link must count as the package itself rather + than as overlinking. + """ + args = rattler_build.build_args( + recipes / "linking-own-soname-symlink", + tmp_path, + extra_args=["--target-platform", "linux-64"], + ) + output = rattler_build(*args, stderr=STDOUT) + assert "lib/liba.so.3 (package)" in output + + @pytest.mark.skipif(platform.system() != "Linux", reason="Linux-only test") def test_allow_missing_dso(rattler_build: RattlerBuild, recipes: Path, tmp_path: Path): args = rattler_build.build_args(