@@ -22,6 +22,7 @@ use crate::{
2222 env_vars,
2323 metadata:: { Output , build_reindexed_channels} ,
2424 packaging:: Files ,
25+ post_process:: package_nature:: { LibraryNameMap , PrefixInfo } ,
2526 render:: resolved_dependencies:: {
2627 FinalizedDependencies , RunExportsDownload , install_environments, resolve_dependencies,
2728 } ,
@@ -71,6 +72,13 @@ pub struct StagingCacheMetadata {
7172
7273 /// The variant configuration that was used
7374 pub variant : BTreeMap < NormalizedKey , Variable > ,
75+
76+ /// Mapping from shared library filenames to the package that provides them.
77+ /// Captured at staging build time while conda-meta is still present, used
78+ /// during overlinking checks as a fallback when these packages are not
79+ /// physically installed in the host prefix.
80+ #[ serde( default ) ]
81+ pub library_name_map : LibraryNameMap ,
7482}
7583
7684impl Output {
@@ -140,7 +148,8 @@ impl Output {
140148 /// 2. If yes, restore the cached files to the prefix
141149 /// 3. If no, build the staging cache and save it
142150 ///
143- /// Returns the finalized dependencies and sources from the staging cache
151+ /// Returns the finalized dependencies, sources, and library name map from
152+ /// the staging cache.
144153 pub async fn build_or_restore_staging_cache (
145154 & self ,
146155 staging : & StagingCache ,
@@ -149,6 +158,7 @@ impl Output {
149158 (
150159 FinalizedDependencies ,
151160 Vec < rattler_build_recipe:: stage1:: Source > ,
161+ LibraryNameMap ,
152162 ) ,
153163 miette:: Error ,
154164 > {
@@ -215,6 +225,7 @@ impl Output {
215225 (
216226 FinalizedDependencies ,
217227 Vec < rattler_build_recipe:: stage1:: Source > ,
228+ LibraryNameMap ,
218229 ) ,
219230 miette:: Error ,
220231 > {
@@ -252,6 +263,13 @@ impl Output {
252263 . await
253264 . into_diagnostic ( ) ?;
254265
266+ // Capture the library name map while conda-meta still exists in the
267+ // prefix. This maps shared library filenames to their providing
268+ // packages so overlinking checks can attribute libraries even after
269+ // the staging cache's host deps are no longer installed.
270+ let prefix_info = PrefixInfo :: from_prefix ( self . prefix ( ) ) . into_diagnostic ( ) ?;
271+ let library_name_map = LibraryNameMap :: from_prefix_info ( & prefix_info) ;
272+
255273 // Run the build script
256274 let target_platform = self . build_configuration . target_platform ;
257275 let mut env_vars = env_vars:: vars ( self , "BUILD" ) ;
@@ -374,6 +392,7 @@ impl Output {
374392 work_dir_files : copied_work_dir. copied_paths ( ) . to_vec ( ) ,
375393 prefix : self . prefix ( ) . to_path_buf ( ) ,
376394 variant : staging. used_variant . clone ( ) ,
395+ library_name_map : library_name_map. clone ( ) ,
377396 } ;
378397
379398 let metadata_json = serde_json:: to_string_pretty ( & metadata) . into_diagnostic ( ) ?;
@@ -385,7 +404,7 @@ impl Output {
385404 metadata. work_dir_files. len( )
386405 ) ;
387406
388- Ok ( ( finalized_dependencies, finalized_sources) )
407+ Ok ( ( finalized_dependencies, finalized_sources, library_name_map ) )
389408 }
390409
391410 /// Restore a staging cache from disk
@@ -397,6 +416,7 @@ impl Output {
397416 (
398417 FinalizedDependencies ,
399418 Vec < rattler_build_recipe:: stage1:: Source > ,
419+ LibraryNameMap ,
400420 ) ,
401421 miette:: Error ,
402422 > {
@@ -436,7 +456,11 @@ impl Output {
436456 metadata. name
437457 ) ;
438458
439- Ok ( ( metadata. finalized_dependencies , metadata. finalized_sources ) )
459+ Ok ( (
460+ metadata. finalized_dependencies ,
461+ metadata. finalized_sources ,
462+ metadata. library_name_map ,
463+ ) )
440464 }
441465
442466 /// Process all staging caches for this output
@@ -451,6 +475,7 @@ impl Output {
451475 Option < (
452476 FinalizedDependencies ,
453477 Vec < rattler_build_recipe:: stage1:: Source > ,
478+ LibraryNameMap ,
454479 ) > ,
455480 miette:: Error ,
456481 > {
@@ -467,7 +492,7 @@ impl Output {
467492 "Building or restoring staging cache: {}" ,
468493 staging_cache. name
469494 ) ;
470- let ( _deps, _sources) = self
495+ let ( _deps, _sources, _lib_map ) = self
471496 . build_or_restore_staging_cache ( staging_cache, tool_configuration)
472497 . await ?;
473498 }
@@ -488,11 +513,11 @@ impl Output {
488513 } ) ?;
489514
490515 // Get or build the cache
491- let ( deps, sources) = self
516+ let ( deps, sources, lib_map ) = self
492517 . build_or_restore_staging_cache ( staging, tool_configuration)
493518 . await ?;
494519
495- Ok ( Some ( ( deps, sources) ) )
520+ Ok ( Some ( ( deps, sources, lib_map ) ) )
496521 } else {
497522 Ok ( None )
498523 }
0 commit comments