@@ -45,6 +45,12 @@ pub(crate) fn compile_file(src_path: &Path, bin_path: &Path) {
45
45
. arg ( "-o" )
46
46
. arg ( bin_path)
47
47
. arg ( src_path) ;
48
+
49
+ // Link our libm
50
+ let lib_path = cdylib_dir ( ) ;
51
+ cmd. arg ( format ! ( "-L{}" , lib_path. display( ) ) ) ;
52
+ cmd. arg ( "-llibm" ) ;
53
+
48
54
handle_err (
49
55
& format ! ( "compile file: {}" , src_path. display( ) ) ,
50
56
& cmd. output ( ) . unwrap ( ) ,
59
65
{
60
66
let mut cmd = process:: Command :: new ( path) ;
61
67
62
- // Find the cdylib - we just support standard locations for now.
63
- let libm_path = target_dir ( ) . join ( if cfg ! ( release_profile) {
64
- "release"
65
- } else {
66
- "debug"
67
- } ) ;
68
-
69
- // Replace libm at runtime
70
- if cfg ! ( target_os = "macos" ) {
71
- let lib_path = libm_path. join ( "liblibm.dylib" ) ;
72
- // for debugging:
73
- // cmd.env("DYLD_PRINT_LIBRARIES", "1");
74
- // cmd.env("X", "1");
75
- cmd. env ( "DYLD_FORCE_FLAT_NAMESPACE" , "1" ) ;
76
- cmd. env ( "DYLD_INSERT_LIBRARIES" , lib_path. display ( ) . to_string ( ) ) ;
77
- } else if cfg ! ( target_os = "linux" ) {
78
- let lib_path = libm_path. join ( "liblibm.so" ) ;
79
- cmd. env ( "LD_PRELOAD" , lib_path. display ( ) . to_string ( ) ) ;
80
- }
81
68
// Run the binary:
82
69
let output = cmd. output ( ) . unwrap ( ) ;
83
70
handle_err ( & format ! ( "run file: {}" , path. display( ) ) , & output) ;
@@ -150,3 +137,22 @@ pub(crate) fn target_dir() -> std::path::PathBuf {
150
137
Path :: new ( "../../target" ) . into ( )
151
138
}
152
139
}
140
+
141
+ pub ( crate ) fn cdylib_dir ( ) -> std:: path:: PathBuf {
142
+ target_dir ( ) . join ( if cfg ! ( release_profile) {
143
+ "release"
144
+ } else {
145
+ "debug"
146
+ } )
147
+ }
148
+
149
+ pub ( crate ) fn cdylib_path ( ) -> std:: path:: PathBuf {
150
+ let libm_path = cdylib_dir ( ) ;
151
+ if cfg ! ( target_os = "macos" ) {
152
+ libm_path. join ( "liblibm.dylib" )
153
+ } else if cfg ! ( target_os = "linux" ) {
154
+ libm_path. join ( "liblibm.so" )
155
+ } else {
156
+ panic ! ( "unsupported target_os" )
157
+ }
158
+ }
0 commit comments