Skip to content

Commit 06b0da3

Browse files
sosthene-nitrokeyrobin-nitrokey
authored andcommitted
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)
1 parent aa64d08 commit 06b0da3

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
### Changed
10+
11+
- Update littlefs to [v2.9.3](https://github.com/littlefs-project/littlefs/releases/tag/v2.9.3)
12+
- Add `multiversion` feature
13+
914
### Fixed
1015

1116
- 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))

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ categories = ["embedded", "filesystem", "no-std"]
1010
repository = "https://github.com/nickray/littlefs2-sys"
1111

1212
[build-dependencies]
13-
bindgen = { version = "0.69.4", default-features = false , features = ["runtime"] }
13+
bindgen = { version = "0.70.1", default-features = false , features = ["runtime"] }
1414
cc = "1"
1515

1616
[features]
1717
assertions = []
1818
trace = []
1919
malloc = []
2020
software-intrinsics = []
21+
multiversion = []

build.rs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::path::PathBuf;
44
fn main() -> Result<(), Box<dyn std::error::Error>> {
55
let mut builder = cc::Build::new();
66
let builder = builder
7-
.flag("-std=c11")
7+
.flag("-std=c99")
88
.flag("-DLFS_NO_DEBUG")
99
.flag("-DLFS_NO_WARN")
1010
.flag("-DLFS_NO_ERROR")
@@ -24,17 +24,42 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
2424
#[cfg(not(feature = "malloc"))]
2525
builder.flag("-DLFS_NO_MALLOC");
2626

27+
#[cfg(feature = "multiversion")]
28+
let builder = builder.flag("-DLFS_MULTIVERSION");
29+
2730
builder.compile("lfs-sys");
2831

32+
// Patch lfs.h to remove the lfs_util import because clang fails to locate the
33+
// libraries for the custom target (especially string.h)
34+
// Compilation before that succeeds because it's using gcc,
35+
// which comes as a distribution with these utils.
36+
// Turns out lfs_utils is not used in lfs.h, and clang properly finds stdint.h and stdbool,
37+
// but not string.h
38+
let lfs_h = std::fs::read_to_string("littlefs/lfs.h").expect("Reading lfs.h succeeds");
39+
println!("cargo::rerun-if-changed=littlefs/lfs.h");
40+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
41+
let out_lfs_h = out_path.join("lfs.h");
42+
std::fs::write(
43+
&out_lfs_h,
44+
lfs_h.replace(
45+
r##"#include "lfs_util.h""##,
46+
"#include <stdint.h>\n#include <stdbool.h>",
47+
),
48+
)
49+
.expect("Failed to write lfs.h");
50+
2951
let bindings = bindgen::Builder::default()
30-
.header("littlefs/lfs.h")
52+
.header(out_lfs_h.into_os_string().into_string().unwrap())
53+
.clang_arg("-std=c99")
54+
.clang_arg("-DLFS_NO_DEBUG")
55+
.clang_arg("-DLFS_NO_WARN")
56+
.clang_arg("-DLFS_NO_ERROR")
3157
.use_core()
3258
.allowlist_item("lfs_.*")
3359
.allowlist_item("LFS_.*")
3460
.generate()
3561
.expect("Unable to generate bindings");
3662

37-
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
3863
bindings
3964
.write_to_file(out_path.join("bindings.rs"))
4065
.expect("Couldn't write bindings!");

littlefs

0 commit comments

Comments
 (0)