Skip to content

Commit 0729291

Browse files
Better attempt to fix compilation
1 parent c6dba7b commit 0729291

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

build.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::env;
21
use std::path::PathBuf;
2+
use std::{env, fs};
33

44
fn main() -> Result<(), Box<dyn std::error::Error>> {
55
let mut builder = cc::Build::new();
@@ -31,12 +31,26 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
3131

3232
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
3333

34+
println!("cargo:rerun-if-changed=littlefs/lfs.h");
35+
let lfs_h = fs::read_to_string("littlefs/lfs.h").unwrap();
36+
// Avoid having to bring in newlib for the types that are only ever used in lfs_utils.h
37+
let corrected_lfs_h = lfs_h.replace(
38+
r#"#include "lfs_util.h""#,
39+
r#"#include <stdint.h>
40+
#include <stdbool.h>"#,
41+
);
42+
let out_path_corrected_lfs_h = out_path.join("corrected_lfs.h");
43+
fs::write(&out_path_corrected_lfs_h, corrected_lfs_h).unwrap();
44+
3445
let bindgen = bindgen::Builder::default()
35-
.header("littlefs/lfs.h")
46+
.header(
47+
out_path_corrected_lfs_h
48+
.to_str()
49+
.expect("Path must be utf-8"),
50+
)
3651
.clang_arg("-std=c99")
3752
.clang_arg("-DLFS_NO_DEBUG")
38-
.clang_arg("-DLFS_NO_WARN")
39-
.clang_arg("-DLFS_NO_ERROR");
53+
.clang_arg("-DLFS_NO_WARN");
4054
#[cfg(feature = "multiversion")]
4155
let bindgen = bindgen.clang_arg("-DLFS_MULTIVERSION");
4256

0 commit comments

Comments
 (0)