@@ -51,29 +51,22 @@ 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 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) {
54
+ let libm_path = target_dir ( ) . join ( if cfg ! ( release_profile) {
60
55
"release"
61
56
} else {
62
57
"debug"
63
- } ) ) ;
58
+ } ) ;
64
59
65
60
// Replace libm at runtime
66
61
if cfg ! ( target_os = "macos" ) {
67
- let lib_name = format ! ( "liblibm.{}" , "dylib" ) ;
68
- let lib_path = libm_path. join ( Path :: new ( & lib_name) ) ;
62
+ let lib_path = libm_path. join ( "liblibm.dylib" ) ;
69
63
// for debugging:
70
64
// cmd.env("DYLD_PRINT_LIBRARIES", "1");
71
65
// cmd.env("X", "1");
72
66
cmd. env ( "DYLD_FORCE_FLAT_NAMESPACE" , "1" ) ;
73
67
cmd. env ( "DYLD_INSERT_LIBRARIES" , lib_path. display ( ) . to_string ( ) ) ;
74
68
} else if cfg ! ( target_os = "linux" ) {
75
- let lib_name = format ! ( "liblibm.{}" , "so" ) ;
76
- let lib_path = libm_path. join ( Path :: new ( & lib_name) ) ;
69
+ let lib_path = libm_path. join ( "liblibm.so" ) ;
77
70
cmd. env ( "LD_PRELOAD" , lib_path. display ( ) . to_string ( ) ) ;
78
71
}
79
72
// Run the binary:
@@ -140,3 +133,11 @@ pub(crate) fn ctype_and_printf_format_specifier(x: &str) -> (&str, &str) {
140
133
_ => panic ! ( "unknown type: {}" , x) ,
141
134
}
142
135
}
136
+
137
+ pub ( crate ) fn target_dir ( ) -> std:: path:: PathBuf {
138
+ if let Ok ( dir) = std:: env:: var ( "CARGO_TARGET_DIR" ) {
139
+ std:: path:: PathBuf :: from ( & dir)
140
+ } else {
141
+ Path :: new ( "../../target" ) . into ( )
142
+ }
143
+ }
0 commit comments