@@ -200,6 +200,14 @@ pub(crate) fn link_with_plan(
200200/// profiles. Prefers the profile matching the compiler's own build: a release
201201/// `meshc` links the release runtime, a debug `meshc` links the debug runtime.
202202fn find_mesh_rt ( target : & LinkTarget ) -> Result < PathBuf , String > {
203+ // ENV override (highest priority)
204+ if let Ok ( path) = std:: env:: var ( "MESH_RT_PATH" ) {
205+ let path = PathBuf :: from ( path) ;
206+ if path. exists ( ) {
207+ return Ok ( path) ;
208+ }
209+ }
210+
203211 let profiles: & [ & str ] = if cfg ! ( debug_assertions) {
204212 & [ "debug" , "release" ]
205213 } else {
@@ -217,6 +225,49 @@ fn find_mesh_rt(target: &LinkTarget) -> Result<PathBuf, String> {
217225 }
218226 }
219227
228+ // NEW: fallback directories
229+ let mut extra_dirs: Vec < PathBuf > = Vec :: new ( ) ;
230+
231+ // ~/.mesh/lib
232+ if let Some ( home) = std:: env:: var_os ( "HOME" ) {
233+ extra_dirs. push ( PathBuf :: from ( home) . join ( ".mesh/lib" ) ) ;
234+ }
235+
236+ // current working directory
237+ if let Ok ( current) = std:: env:: current_dir ( ) {
238+ extra_dirs. push ( current) ;
239+ }
240+
241+ // directory of meshc binary
242+ if let Ok ( exe) = std:: env:: current_exe ( ) {
243+ if let Some ( parent) = exe. parent ( ) {
244+ extra_dirs. push ( parent. to_path_buf ( ) ) ;
245+ }
246+ }
247+
248+ // search fallback dirs
249+ for dir in extra_dirs {
250+ // check profile-based structure
251+ for profile in profiles {
252+ let candidate = dir. join ( profile) . join ( target. runtime_filename ( ) ) ;
253+
254+ if candidate. exists ( ) {
255+ return Ok ( candidate) ;
256+ }
257+
258+ searched_paths. push ( candidate) ;
259+ }
260+
261+ // check direct file
262+ let direct = dir. join ( target. runtime_filename ( ) ) ;
263+ if direct. exists ( ) {
264+ return Ok ( direct) ;
265+ }
266+
267+ searched_paths. push ( direct) ;
268+ }
269+
270+ // error message (unchanged)
220271 let mut message = format ! (
221272 "Could not locate Mesh runtime static library for target '{}'. Expected {}. Run `cargo build -p mesh-rt{}` first." ,
222273 target. display_triple( ) ,
0 commit comments