@@ -95,20 +95,63 @@ fn main() {
95
95
let output = PathBuf :: from ( env:: var ( "OUT_DIR" ) . expect ( "OUT_DIR set in build script" ) )
96
96
. join ( "bindings.rs" ) ;
97
97
98
+ // Try both Ubuntu and Debian paths for GCC
99
+ let gcc_paths = [
100
+ "/usr/lib/gcc/arm-none-eabi" ,
101
+ "/usr/lib/gcc-cross/arm-none-eabi" , // Debian specific path
102
+ "/usr/arm-none-eabi" ,
103
+ "/usr/lib/arm-none-eabi" ,
104
+ ] ;
105
+
106
+ // Find the GCC version directory
107
+ let gcc_version = std:: process:: Command :: new ( "arm-none-eabi-gcc" )
108
+ . arg ( "-dumpversion" )
109
+ . output ( )
110
+ . ok ( )
111
+ . and_then ( |output| String :: from_utf8 ( output. stdout ) . ok ( ) )
112
+ . unwrap_or_else ( || "10.3.1" . to_string ( ) ) ;
113
+
114
+ // Try to find the correct include path
115
+ let mut found_gcc_include = None ;
116
+ for base_path in gcc_paths. iter ( ) {
117
+ let test_path = format ! ( "{}/{}/include" , base_path, gcc_version. trim( ) ) ;
118
+ if std:: path:: Path :: new ( & test_path) . exists ( ) {
119
+ found_gcc_include = Some ( test_path) ;
120
+ break ;
121
+ }
122
+ }
123
+
124
+ let gcc_include = found_gcc_include. unwrap_or_else ( || {
125
+ println ! ( "cargo:warning=Could not find GCC include directory, using default path" ) ;
126
+ format ! (
127
+ "/usr/lib/gcc-cross/arm-none-eabi/{}/include" ,
128
+ gcc_version. trim( )
129
+ )
130
+ } ) ;
131
+
98
132
let bindings = bindgen:: builder ( )
99
133
. use_core ( )
100
134
. derive_default ( true )
101
135
. header ( device. input_header ( ) . display ( ) . to_string ( ) )
136
+ // Add GCC includes first
137
+ . clang_arg ( format ! ( "-I{}" , gcc_include) )
138
+ // Then ARM includes with Debian paths
139
+ . clang_arg ( "-I/usr/arm-none-eabi/include" )
140
+ . clang_arg ( "-I/usr/include/arm-none-eabi" ) // Debian specific path
141
+ . clang_arg ( "-I/usr/lib/arm-none-eabi/include" )
142
+ // Device specific flags
102
143
. clang_args ( device. target ( ) )
103
144
. clang_args ( device. device_flags ( ) )
145
+ // SDK includes
104
146
. clang_args (
105
147
device
106
148
. sdk_includes ( )
107
149
. into_iter ( )
108
150
. map ( |inc| sdk_path. join ( inc) )
109
151
. map ( |path| format ! ( "-I{}" , path. display( ) ) ) ,
110
152
)
111
- . clang_arg ( "-I/usr/arm-none-eabi/include" )
153
+ . clang_arg ( format ! ( "-I{}" , sdk_path. display( ) ) )
154
+ . clang_arg ( format ! ( "-I{}/include" , sdk_path. display( ) ) )
112
155
. generate ( )
113
156
. expect ( "able to generate bindings" ) ;
114
157
bindings
0 commit comments