@@ -68,20 +68,64 @@ fn main()
6868
6969 println ! ( "completed `make library` call" ) ;
7070
71- let bindings = bindgen:: Builder :: default ( ) . clang_arg ( format ! ( "-I{}/src/include" ,
72- out_path. to_str( ) . unwrap( ) ) )
73- . clang_arg ( "-std=gnu11" )
74- . header ( "liburing-rs/include/liburing_wrapper.h" )
75- . anon_fields_prefix ( "__liburing_anon_" )
76- . prepend_enum_name ( false )
77- . derive_default ( true )
78- . generate ( )
79- . expect ( "Unable to generate bindings" ) ;
80-
81- // Write the bindings to the $OUT_DIR/bindings.rs file.
82-
83- bindings. write_to_file ( out_path. join ( "liburing_bindings.rs" ) )
84- . expect ( "Couldn't write bindings!" ) ;
71+ if cfg ! ( feature = "bindgen-cli" ) {
72+ let bindgen_cmd = match env:: var ( "BINDGEN_PATH" ) {
73+ Ok ( s) => s,
74+ Err ( _) => String :: from ( "bindgen" ) ,
75+ } ;
76+
77+ // I hate this hack for getting the rustc version to pass to bindgen, and maybe there's a better way.
78+ let output = std:: process:: Command :: new ( "rustc" ) . arg ( "--version" )
79+ . output ( )
80+ . expect ( "Failed to run rustc" ) ;
81+
82+ // ❯ rustc --version
83+ // rustc 1.90.0 (1159e78c4 2025-09-14)
84+ // ❯ rustc +nightly --version
85+ // rustc 1.92.0-nightly (4da69dfff 2025-10-01)
86+ let rustc_version = String :: from_utf8 ( output. stdout ) . unwrap ( ) ;
87+ let parts: Vec < & str > = rustc_version. split_whitespace ( ) . collect ( ) ;
88+ let rustc_version = parts[ 1 ] ;
89+
90+ let rustc_version = rustc_version. split ( "-" ) . next ( ) . unwrap ( ) ;
91+
92+ let r = std:: process:: Command :: new ( & bindgen_cmd) . args ( [ "liburing-rs/include/liburing_wrapper.h" ,
93+ "--anon-fields-prefix" ,
94+ "__liburing_anon_" ,
95+ "--no-prepend-enum-name" ,
96+ "--with-derive-default" ,
97+ "--rust-edition" , "2024" ,
98+ "--rust-target" , rustc_version,
99+ "--output" ,
100+ out_path. join ( "liburing_bindings.rs" )
101+ . to_str ( )
102+ . unwrap ( ) ,
103+ "--" ,
104+ "-std=gnu11" ,
105+ & format ! ( "-I{}/src/include" ,
106+ out_path. to_str( ) . unwrap( ) ) ,
107+ ] )
108+ . output ( )
109+ . unwrap ( ) ;
110+
111+ std:: io:: stderr ( ) . write_all ( & r. stderr ) . unwrap ( ) ;
112+ assert ! ( r. status. success( ) ) ;
113+ } else {
114+ let bindings = bindgen:: Builder :: default ( ) . clang_arg ( format ! ( "-I{}/src/include" ,
115+ out_path. to_str( ) . unwrap( ) ) )
116+ . clang_arg ( "-std=gnu11" )
117+ . header ( "liburing-rs/include/liburing_wrapper.h" )
118+ . anon_fields_prefix ( "__liburing_anon_" )
119+ . prepend_enum_name ( false )
120+ . derive_default ( true )
121+ . generate ( )
122+ . expect ( "Unable to generate bindings" ) ;
123+
124+ // Write the bindings to the $OUT_DIR/bindings.rs file.
125+
126+ bindings. write_to_file ( out_path. join ( "liburing_bindings.rs" ) )
127+ . expect ( "Couldn't write bindings!" ) ;
128+ }
85129
86130 println ! ( "generated bindings" ) ;
87131
0 commit comments