@@ -9,28 +9,6 @@ use std::fs;
99use std:: path:: Path ;
1010use std:: process:: Command ;
1111
12- #[ cfg( any(
13- target_os = "linux" ,
14- target_os = "android" ,
15- target_os = "freebsd" ,
16- target_os = "netbsd" ,
17- target_os = "openbsd" ,
18- target_os = "dragonfly"
19- ) ) ]
20- mod platform {
21- pub const DYLIB_EXT : & str = ".so" ;
22- }
23-
24- #[ cfg( target_vendor = "apple" ) ]
25- mod platform {
26- pub const DYLIB_EXT : & str = ".dylib" ;
27- }
28-
29- #[ cfg( target_os = "cygwin" ) ]
30- mod platform {
31- pub const DYLIB_EXT : & str = ".dll" ;
32- }
33-
3412fn main ( ) {
3513 println ! ( "cargo:rerun-if-changed=build.rs" ) ;
3614 println ! ( "cargo:rerun-if-changed=src/libstdbuf/src/libstdbuf.rs" ) ;
@@ -58,14 +36,25 @@ fn main() {
5836 let out_dir = env:: var ( "OUT_DIR" ) . expect ( "OUT_DIR not set" ) ;
5937 let target = env:: var ( "TARGET" ) . unwrap_or_else ( |_| "unknown" . to_string ( ) ) ;
6038
39+ let target_os = env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) ;
40+ let target_vendor = env:: var ( "CARGO_CFG_TARGET_VENDOR" ) . unwrap ( ) ;
41+
42+ let dylib_ext = if target_vendor == "apple" {
43+ ".dylib"
44+ } else if target_os == "windows" || target_os == "cygwin" {
45+ ".dll"
46+ } else {
47+ ".so"
48+ } ;
49+
6150 // Check if we're building from the repository (where src/libstdbuf exists)
6251 // or from crates.io (where it doesn't)
6352 let libstdbuf_src = Path :: new ( "src/libstdbuf" ) ;
6453 if !libstdbuf_src. exists ( ) {
6554 // When building from crates.io, libstdbuf is already available as a dependency
6655 // We can't build it here, so we'll need to handle this differently
6756 // For now, we'll create a dummy library file to satisfy the include_bytes! macro
68- let lib_name = format ! ( "libstdbuf{}" , platform :: DYLIB_EXT ) ;
57+ let lib_name = format ! ( "libstdbuf{dylib_ext}" ) ;
6958 let dest_path = Path :: new ( & out_dir) . join ( & lib_name) ;
7059
7160 // Create an empty file as a placeholder
@@ -108,11 +97,12 @@ fn main() {
10897 assert ! ( status. success( ) , "Failed to build libstdbuf" ) ;
10998
11099 // Copy the built library to OUT_DIR for include_bytes! to find
111- #[ cfg( target_os = "cygwin" ) ]
112- let lib_name = format ! ( "stdbuf{}" , platform:: DYLIB_EXT ) ;
113- #[ cfg( not( target_os = "cygwin" ) ) ]
114- let lib_name = format ! ( "libstdbuf{}" , platform:: DYLIB_EXT ) ;
115- let dest_path = Path :: new ( & out_dir) . join ( format ! ( "libstdbuf{}" , platform:: DYLIB_EXT ) ) ;
100+ let lib_name = if target_os == "cygwin" {
101+ format ! ( "stdbuf{dylib_ext}" )
102+ } else {
103+ format ! ( "libstdbuf{dylib_ext}" )
104+ } ;
105+ let dest_path = Path :: new ( & out_dir) . join ( format ! ( "libstdbuf{dylib_ext}" ) ) ;
116106
117107 // Check multiple possible locations for the built library
118108 let possible_paths = if !target. is_empty ( ) && target != "unknown" {
0 commit comments