@@ -45,6 +45,12 @@ pub(crate) fn compile_file(src_path: &Path, bin_path: &Path) {
4545 . arg ( "-o" )
4646 . arg ( bin_path)
4747 . 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+
4854 handle_err (
4955 & format ! ( "compile file: {}" , src_path. display( ) ) ,
5056 & cmd. output ( ) . unwrap ( ) ,
5965{
6066 let mut cmd = process:: Command :: new ( path) ;
6167
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- }
8168 // Run the binary:
8269 let output = cmd. output ( ) . unwrap ( ) ;
8370 handle_err ( & format ! ( "run file: {}" , path. display( ) ) , & output) ;
@@ -150,3 +137,22 @@ pub(crate) fn target_dir() -> std::path::PathBuf {
150137 Path :: new ( "../../target" ) . into ( )
151138 }
152139}
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