Skip to content

Commit 0567200

Browse files
committed
update paths
1 parent 0d38d80 commit 0567200

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

bolos-sys/build.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,63 @@ fn main() {
9595
let output = PathBuf::from(env::var("OUT_DIR").expect("OUT_DIR set in build script"))
9696
.join("bindings.rs");
9797

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+
98132
let bindings = bindgen::builder()
99133
.use_core()
100134
.derive_default(true)
101135
.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
102143
.clang_args(device.target())
103144
.clang_args(device.device_flags())
145+
// SDK includes
104146
.clang_args(
105147
device
106148
.sdk_includes()
107149
.into_iter()
108150
.map(|inc| sdk_path.join(inc))
109151
.map(|path| format!("-I{}", path.display())),
110152
)
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()))
112155
.generate()
113156
.expect("able to generate bindings");
114157
bindings

0 commit comments

Comments
 (0)