@@ -45,6 +45,21 @@ 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+ {
52+ let mut ls = process:: Command :: new ( "ls" ) ;
53+ ls. arg ( lib_path. clone ( ) ) ;
54+ let output = ls. output ( ) . unwrap ( ) ;
55+ let output = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
56+ println ! ( "ls\n {}]n" , output) ;
57+ }
58+ cmd. arg ( format ! ( "-L{}" , lib_path. display( ) ) ) ;
59+ cmd. arg ( "-llibm" ) ;
60+
61+ eprintln ! ( "compile cmd: {:?}" , cmd) ;
62+
4863 handle_err (
4964 & format ! ( "compile file: {}" , src_path. display( ) ) ,
5065 & cmd. output ( ) . unwrap ( ) ,
@@ -59,25 +74,12 @@ where
5974{
6075 let mut cmd = process:: Command :: new ( path) ;
6176
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 ( ) ) ;
77+ if cfg ! ( target_os = "linux" ) {
78+ let ld_library_path = std:: env:: var ( "LD_LIBRARY_PATH" ) . unwrap_or_default ( ) ;
79+ let ld_library_path = format ! ( "{}:{}" , cdylib_dir( ) . display( ) , ld_library_path) ;
80+ cmd. env ( "LD_LIBRARY_PATH" , ld_library_path) ;
8081 }
82+
8183 // Run the binary:
8284 let output = cmd. output ( ) . unwrap ( ) ;
8385 handle_err ( & format ! ( "run file: {}" , path. display( ) ) , & output) ;
@@ -150,3 +152,22 @@ pub(crate) fn target_dir() -> std::path::PathBuf {
150152 Path :: new ( "../../target" ) . into ( )
151153 }
152154}
155+
156+ pub ( crate ) fn cdylib_dir ( ) -> std:: path:: PathBuf {
157+ target_dir ( ) . join ( if cfg ! ( release_profile) {
158+ "release"
159+ } else {
160+ "debug"
161+ } )
162+ }
163+
164+ pub ( crate ) fn cdylib_path ( ) -> std:: path:: PathBuf {
165+ let libm_path = cdylib_dir ( ) ;
166+ if cfg ! ( target_os = "macos" ) {
167+ libm_path. join ( "liblibm.dylib" )
168+ } else if cfg ! ( target_os = "linux" ) {
169+ libm_path. join ( "liblibm.so" )
170+ } else {
171+ panic ! ( "unsupported target_os" )
172+ }
173+ }
0 commit comments