Skip to content

Add LITTLEFS_CONFIG support and adjust bindings for wasm32 target - #28

Open
AlixANNERAUD wants to merge 2 commits into
trussed-dev:mainfrom
AlixANNERAUD:main
Open

AlixANNERAUD wants to merge 2 commits into
trussed-dev:mainfrom
AlixANNERAUD:main

Conversation

@AlixANNERAUD

@AlixANNERAUD AlixANNERAUD commented Jul 25, 2025 •

Copy link
Copy Markdown

Hi,
Thanks for this very useful repository.
This pull request introduces enhancements to the build configuration in build.rs and a minor header file adjustment in string.c. The key changes include adding support for environment-based configuration and fvisibility fix for wasm32 for bindgen in the build script and replacing a header file in string.c, improving portability for bare metal environment (for example wasm32_unknown_unknown target).

@AlixANNERAUD

Copy link
Copy Markdown
Author

Any updates ?

@AlixANNERAUD

Copy link
Copy Markdown
Author

Rebased on v0.4.0. The string.c change is gone since the file was replaced by the tinyrlibc feature, so this now only touches build.rs:

  • LITTLEFS_CONFIG: when set, it's passed as LFS_CONFIG so a custom config header can replace lfs_util.h (logging, asserts, malloc, CRC...), which is otherwise not possible from Rust.
  • wasm32-unknown-unknown: bindgen needs -fvisibility=default there, otherwise the bindings are generated without the littlefs functions.

I checked that it builds with and without LITTLEFS_CONFIG, and for wasm32-unknown-unknown. It's independent from #36.

@sosthene-nitrokey sosthene-nitrokey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thank you for your contributions and sorry for the late reply, I did not have notifications on for this repo.

Comment thread build.rs Outdated
#[cfg(not(feature = "malloc"))]
builder.flag("-DLFS_NO_MALLOC");

if let Ok(lfs_config) = env::var("LITTLEFS_CONFIG") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please rename it to UNSAFE_LITTLEFS_CONFIG ?

It's technically unsafe from the Rust meaning of the term to override this.

Can you please also document this in the Readme?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, renamed to UNSAFE_LITTLEFS_CONFIG and added a section to the README.

Comment thread build.rs Outdated

if let Ok(target) = env::var("TARGET") {
if target == "wasm32-unknown-unknown" {
bindings_builder = bindings_builder.clang_arg("-fvisibility=default");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain what this does and why it's required for wasm32 specifically? 

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On wasm, clang implicitly uses -fvisibility=hidden, and bindgen skips functions that don't have default visibility. Since littlefs doesn't annotate its functions, the bindings end up with all the types but none of the lfs_* functions. -fvisibility=default restores them. It only affects how bindgen parses the headers, not the compiled C code.

While checking this I noticed wasm32-wasip1 had the same problem, so the flag is now applied to the whole wasm target family, with a comment explaining why.

Overriding the littlefs configuration is unsafe, so the variable name now
says so, and it is documented in the README.

On wasm targets, clang implicitly uses -fvisibility=hidden and bindgen
skips functions without default visibility, so the bindings had no lfs_*
functions. The flag was only passed for wasm32-unknown-unknown; it is now
passed for the whole wasm target family (wasm32-wasip1 was also affected).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants