@@ -165,6 +165,17 @@ fn add_run_script(smir_json_dir: &Path, ld_library_path: &Path, profile: Profile
165
165
"export LD_LIBRARY_PATH={}" ,
166
166
ld_library_path. display( ) ,
167
167
) ?;
168
+
169
+ #[ cfg( target_os = "macos" ) ]
170
+ {
171
+ // Also set DYLD_LIBRARY_PATH on macOS
172
+ writeln ! (
173
+ run_script,
174
+ "export DYLD_LIBRARY_PATH={}" ,
175
+ ld_library_path. display( ) ,
176
+ ) ?;
177
+ }
178
+
168
179
writeln ! ( run_script) ?;
169
180
writeln ! (
170
181
run_script,
@@ -178,19 +189,50 @@ fn add_run_script(smir_json_dir: &Path, ld_library_path: &Path, profile: Profile
178
189
}
179
190
180
191
fn record_ld_library_path ( smir_json_dir : & Path ) -> Result < PathBuf > {
181
- const LOADER_PATH : & str = "LD_LIBRARY_PATH" ;
182
- if let Some ( paths) = env:: var_os ( LOADER_PATH ) {
183
- // Note: kani filters the LD_LIBRARY_PATH, not sure why as it is working locally as is
184
- let mut ld_library_file = std:: fs:: File :: create ( smir_json_dir. join ( "ld_library_path" ) ) ?;
185
-
186
- match paths. to_str ( ) {
187
- Some ( ld_library_path) => {
188
- writeln ! ( ld_library_file, "{}" , ld_library_path) ?;
189
- Ok ( ld_library_path. into ( ) )
192
+ #[ cfg( target_os = "macos" ) ]
193
+ {
194
+ // macOS: Check DYLD_LIBRARY_PATH or use default path
195
+ if let Some ( paths) = env:: var_os ( "DYLD_LIBRARY_PATH" ) {
196
+ let mut ld_library_file = std:: fs:: File :: create ( smir_json_dir. join ( "ld_library_path" ) ) ?;
197
+ match paths. to_str ( ) {
198
+ Some ( ld_library_path) => {
199
+ writeln ! ( ld_library_file, "{}" , ld_library_path) ?;
200
+ Ok ( ld_library_path. into ( ) )
201
+ }
202
+ None => bail ! ( "Couldn't cast DYLD_LIBRARY_PATH to str" ) ,
203
+ }
204
+ } else {
205
+ // Use default macOS library path including Rust toolchain
206
+ let rustup_home = env:: var ( "HOME" ) . unwrap_or_else ( |_| "/Users" . to_string ( ) ) ;
207
+ let rust_toolchain_path = format ! (
208
+ "{}/.rustup/toolchains/nightly-2024-11-29-aarch64-apple-darwin/lib" ,
209
+ rustup_home
210
+ ) ;
211
+ let default_path = format ! ( "{}:/usr/local/lib:/usr/lib" , rust_toolchain_path) ;
212
+ let mut ld_library_file = std:: fs:: File :: create ( smir_json_dir. join ( "ld_library_path" ) ) ?;
213
+ writeln ! ( ld_library_file, "{}" , default_path) ?;
214
+ Ok ( default_path. into ( ) )
215
+ }
216
+ }
217
+
218
+ #[ cfg( not( target_os = "macos" ) ) ]
219
+ {
220
+ // Linux and other systems: Check LD_LIBRARY_PATH
221
+ if let Some ( paths) = env:: var_os ( "LD_LIBRARY_PATH" ) {
222
+ let mut ld_library_file = std:: fs:: File :: create ( smir_json_dir. join ( "ld_library_path" ) ) ?;
223
+ match paths. to_str ( ) {
224
+ Some ( ld_library_path) => {
225
+ writeln ! ( ld_library_file, "{}" , ld_library_path) ?;
226
+ Ok ( ld_library_path. into ( ) )
227
+ }
228
+ None => bail ! ( "Couldn't cast LD_LIBRARY_PATH to str" ) ,
190
229
}
191
- None => bail ! ( "Couldn't cast LD_LIBRARY_PATH to str" ) ,
230
+ } else {
231
+ // Use default Linux library path
232
+ let default_path = "/usr/local/lib:/usr/lib" ;
233
+ let mut ld_library_file = std:: fs:: File :: create ( smir_json_dir. join ( "ld_library_path" ) ) ?;
234
+ writeln ! ( ld_library_file, "{}" , default_path) ?;
235
+ Ok ( default_path. into ( ) )
192
236
}
193
- } else {
194
- bail ! ( "Couldn't read LD_LIBRARY_PATH from env" ) ; // This should be unreachable
195
237
}
196
238
}
0 commit comments