@@ -52,6 +52,22 @@ fn main() {
5252 let out_dir = env:: var ( "OUT_DIR" ) . expect ( "OUT_DIR not set" ) ;
5353 let target = env:: var ( "TARGET" ) . unwrap_or_else ( |_| "unknown" . to_string ( ) ) ;
5454
55+ // Check if we're building from the repository (where src/libstdbuf exists)
56+ // or from crates.io (where it doesn't)
57+ let libstdbuf_src = Path :: new ( "src/libstdbuf" ) ;
58+ if !libstdbuf_src. exists ( ) {
59+ // When building from crates.io, libstdbuf is already available as a dependency
60+ // We can't build it here, so we'll need to handle this differently
61+ // For now, we'll create a dummy library file to satisfy the include_bytes! macro
62+ let lib_name = format ! ( "libstdbuf{}" , platform:: DYLIB_EXT ) ;
63+ let dest_path = Path :: new ( & out_dir) . join ( & lib_name) ;
64+
65+ // Create an empty file as a placeholder
66+ // The actual library will be provided by the dependency
67+ fs:: write ( & dest_path, [ ] ) . expect ( "Failed to create placeholder libstdbuf" ) ;
68+ return ;
69+ }
70+
5571 // Create a separate build directory for libstdbuf to avoid conflicts
5672 let build_dir = Path :: new ( & out_dir) . join ( "libstdbuf-build" ) ;
5773 fs:: create_dir_all ( & build_dir) . expect ( "Failed to create build directory" ) ;
@@ -66,11 +82,8 @@ fn main() {
6682 // See the tracking issue: https://github.com/rust-lang/cargo/issues/9096
6783 let mut cmd = Command :: new ( & cargo) ;
6884 cmd. env_clear ( ) . envs ( env:: vars ( ) ) ;
69- cmd. current_dir ( Path :: new ( "src/libstdbuf" ) ) . args ( [
70- "build" ,
71- "--target-dir" ,
72- build_dir. to_str ( ) . unwrap ( ) ,
73- ] ) ;
85+ cmd. current_dir ( libstdbuf_src)
86+ . args ( [ "build" , "--target-dir" , build_dir. to_str ( ) . unwrap ( ) ] ) ;
7487
7588 // Get the current profile
7689 let profile = env:: var ( "PROFILE" ) . unwrap_or_else ( |_| "debug" . to_string ( ) ) ;
0 commit comments