diff --git a/build.rs b/build.rs index b39be17..1d02885 100644 --- a/build.rs +++ b/build.rs @@ -1,5 +1,5 @@ -use std::env; use std::path::PathBuf; +use std::{env, fs}; fn main() -> Result<(), Box> { let mut builder = cc::Build::new(); @@ -31,12 +31,26 @@ fn main() -> Result<(), Box> { let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + println!("cargo:rerun-if-changed=littlefs/lfs.h"); + let lfs_h = fs::read_to_string("littlefs/lfs.h").unwrap(); + // Avoid having to bring in newlib for the types that are only ever used in lfs_utils.h + let corrected_lfs_h = lfs_h.replace( + r#"#include "lfs_util.h""#, + r#"#include +#include "#, + ); + let out_path_corrected_lfs_h = out_path.join("corrected_lfs.h"); + fs::write(&out_path_corrected_lfs_h, corrected_lfs_h).unwrap(); + let bindgen = bindgen::Builder::default() - .header("littlefs/lfs.h") + .header( + out_path_corrected_lfs_h + .to_str() + .expect("Path must be utf-8"), + ) .clang_arg("-std=c99") .clang_arg("-DLFS_NO_DEBUG") - .clang_arg("-DLFS_NO_WARN") - .clang_arg("-DLFS_NO_ERROR"); + .clang_arg("-DLFS_NO_WARN"); #[cfg(feature = "multiversion")] let bindgen = bindgen.clang_arg("-DLFS_MULTIVERSION");