From 06b0da3ed694a7150f68b3746e5f80873b4fe61f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sosth=C3=A8ne=20Gu=C3=A9don?= Date: Fri, 7 Apr 2023 10:56:10 +0200 Subject: [PATCH] Bump littlefs version This patch: - Bumps the littlefs version to the latest released (v2.9.3) - Adds a "multiversion" feature flag that exposes the littlefs feature of the same name - Patch lfs.h before building to avoid errors from clang failing to find the string.h header (this step is not required for the compilation because compilation is done through gcc by default) --- CHANGELOG.md | 5 +++++ Cargo.toml | 3 ++- build.rs | 31 ++++++++++++++++++++++++++++--- littlefs | 2 +- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37be451..c6d0082 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Update littlefs to [v2.9.3](https://github.com/littlefs-project/littlefs/releases/tag/v2.9.3) + - Add `multiversion` feature + ### Fixed - Fix build script for platforms where the Rust target is not equal to the clang target ([#16](https://github.com/trussed-dev/littlefs2-sys/pull/16)) diff --git a/Cargo.toml b/Cargo.toml index a5e07c0..84260fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ categories = ["embedded", "filesystem", "no-std"] repository = "https://github.com/nickray/littlefs2-sys" [build-dependencies] -bindgen = { version = "0.69.4", default-features = false , features = ["runtime"] } +bindgen = { version = "0.70.1", default-features = false , features = ["runtime"] } cc = "1" [features] @@ -18,3 +18,4 @@ assertions = [] trace = [] malloc = [] software-intrinsics = [] +multiversion = [] diff --git a/build.rs b/build.rs index d8ddea2..9b34197 100644 --- a/build.rs +++ b/build.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; fn main() -> Result<(), Box> { let mut builder = cc::Build::new(); let builder = builder - .flag("-std=c11") + .flag("-std=c99") .flag("-DLFS_NO_DEBUG") .flag("-DLFS_NO_WARN") .flag("-DLFS_NO_ERROR") @@ -24,17 +24,42 @@ fn main() -> Result<(), Box> { #[cfg(not(feature = "malloc"))] builder.flag("-DLFS_NO_MALLOC"); + #[cfg(feature = "multiversion")] + let builder = builder.flag("-DLFS_MULTIVERSION"); + builder.compile("lfs-sys"); + // Patch lfs.h to remove the lfs_util import because clang fails to locate the + // libraries for the custom target (especially string.h) + // Compilation before that succeeds because it's using gcc, + // which comes as a distribution with these utils. + // Turns out lfs_utils is not used in lfs.h, and clang properly finds stdint.h and stdbool, + // but not string.h + let lfs_h = std::fs::read_to_string("littlefs/lfs.h").expect("Reading lfs.h succeeds"); + println!("cargo::rerun-if-changed=littlefs/lfs.h"); + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + let out_lfs_h = out_path.join("lfs.h"); + std::fs::write( + &out_lfs_h, + lfs_h.replace( + r##"#include "lfs_util.h""##, + "#include \n#include ", + ), + ) + .expect("Failed to write lfs.h"); + let bindings = bindgen::Builder::default() - .header("littlefs/lfs.h") + .header(out_lfs_h.into_os_string().into_string().unwrap()) + .clang_arg("-std=c99") + .clang_arg("-DLFS_NO_DEBUG") + .clang_arg("-DLFS_NO_WARN") + .clang_arg("-DLFS_NO_ERROR") .use_core() .allowlist_item("lfs_.*") .allowlist_item("LFS_.*") .generate() .expect("Unable to generate bindings"); - let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); bindings .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); diff --git a/littlefs b/littlefs index 4c9146e..d01280e 160000 --- a/littlefs +++ b/littlefs @@ -1 +1 @@ -Subproject commit 4c9146ea539f72749d6cc3ea076372a81b12cb11 +Subproject commit d01280e64934a09ba16cac60cf9d3a37e228bb66