@@ -95,20 +95,60 @@ 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 ! ( "/usr/lib/gcc-cross/arm-none-eabi/{}/include" , gcc_version. trim( ) )
127
+ } ) ;
128
+
98
129
let bindings = bindgen:: builder ( )
99
130
. use_core ( )
100
131
. derive_default ( true )
101
132
. header ( device. input_header ( ) . display ( ) . to_string ( ) )
133
+ // Add GCC includes first
134
+ . clang_arg ( format ! ( "-I{}" , gcc_include) )
135
+ // Then ARM includes with Debian paths
136
+ . clang_arg ( "-I/usr/arm-none-eabi/include" )
137
+ . clang_arg ( "-I/usr/include/arm-none-eabi" ) // Debian specific path
138
+ . clang_arg ( "-I/usr/lib/arm-none-eabi/include" )
139
+ // Device specific flags
102
140
. clang_args ( device. target ( ) )
103
141
. clang_args ( device. device_flags ( ) )
142
+ // SDK includes
104
143
. clang_args (
105
144
device
106
145
. sdk_includes ( )
107
146
. into_iter ( )
108
147
. map ( |inc| sdk_path. join ( inc) )
109
148
. map ( |path| format ! ( "-I{}" , path. display( ) ) ) ,
110
149
)
111
- . clang_arg ( "-I/usr/arm-none-eabi/include" )
150
+ . clang_arg ( format ! ( "-I{}" , sdk_path. display( ) ) )
151
+ . clang_arg ( format ! ( "-I{}/include" , sdk_path. display( ) ) )
112
152
. generate ( )
113
153
. expect ( "able to generate bindings" ) ;
114
154
bindings
0 commit comments