@@ -51,27 +51,30 @@ where
51
51
let mut cmd = process:: Command :: new ( path) ;
52
52
53
53
// Find the cdylib - we just support standard locations for now.
54
- let libm_path = format ! (
55
- "../../target/{}/liblibm" ,
56
- if cfg!( release_profile) {
57
- "release"
58
- } else {
59
- "debug"
60
- } ,
61
- ) ;
54
+ let target_dir = if let Ok ( dir) = std:: env:: var ( "CARGO_TARGET_DIR" ) {
55
+ std:: path:: PathBuf :: from ( & dir)
56
+ } else {
57
+ Path :: new ( "../../target" ) . into ( )
58
+ } ;
59
+ let libm_path = target_dir. join ( Path :: new ( if cfg ! ( release_profile) {
60
+ "release"
61
+ } else {
62
+ "debug"
63
+ } ) ) ;
62
64
63
65
// Replace libm at runtime
64
66
if cfg ! ( target_os = "macos" ) {
67
+ let lib_name = format ! ( "liblibm.{}" , "dylib" ) ;
68
+ let lib_path = libm_path. join ( Path :: new ( & lib_name) ) ;
65
69
// for debugging:
66
70
// cmd.env("DYLD_PRINT_LIBRARIES", "1");
67
71
// cmd.env("X", "1");
68
72
cmd. env ( "DYLD_FORCE_FLAT_NAMESPACE" , "1" ) ;
69
- cmd. env (
70
- "DYLD_INSERT_LIBRARIES" ,
71
- format ! ( "{}.{}" , libm_path, "dylib" ) ,
72
- ) ;
73
+ cmd. env ( "DYLD_INSERT_LIBRARIES" , lib_path. display ( ) . to_string ( ) ) ;
73
74
} else if cfg ! ( target_os = "linux" ) {
74
- cmd. env ( "LD_PRELOAD" , format ! ( "{}.{}" , libm_path, "so" ) ) ;
75
+ let lib_name = format ! ( "liblibm.{}" , "so" ) ;
76
+ let lib_path = libm_path. join ( Path :: new ( & lib_name) ) ;
77
+ cmd. env ( "LD_PRELOAD" , lib_path. display ( ) . to_string ( ) ) ;
75
78
}
76
79
// Run the binary:
77
80
let output = cmd. output ( ) . unwrap ( ) ;
0 commit comments