Skip to content

[FEATURE] Add NAM_NO_FILESYSTEM option for bare-metal targets#306

Open
elcamino wants to merge 1 commit into
sdatkinson:mainfrom
elcamino:no-filesystem-option
Open

[FEATURE] Add NAM_NO_FILESYSTEM option for bare-metal targets#306
elcamino wants to merge 1 commit into
sdatkinson:mainfrom
elcamino:no-filesystem-option

Conversation

@elcamino

Copy link
Copy Markdown

Problem

The core cannot be linked into bare-metal firmware (Arm Cortex-M, newlib), because NAM/dsp.h unconditionally includes <filesystem> and the loaders in get_dsp.cpp/dsp.cpp reference std::filesystem/std::ifstream. libstdc++'s filesystem implementation calls POSIX syscalls that newlib does not provide, so the link fails even if the application never loads a model from a path. Minimal reproduction (Arm GNU Toolchain 15.2, -mcpu=cortex-m7, newlib/nosys) with a single call to std::filesystem::exists():

ld: libstdc++.a(fs_ops.o): undefined reference to `truncate'

The affected targets are exactly where NAM increasingly runs: guitar pedals on MCUs (Daisy, Teensy). Embedded wrappers currently pin old core versions or carry local patches because of this; models on those targets load from embedded memory via the JSON/dspData entry points, never from a filesystem.

Change

An opt-in NAM_NO_FILESYSTEM define guards the <filesystem>/<fstream> includes and the path-based loader entry points (the two get_dsp(std::filesystem::path, ...) overloads and get_dsp_legacy). The JSON/dspData entry points are untouched. Without the define, the preprocessor output is identical to main, so existing builds cannot be affected.

Validation

  • Default and -DCMAKE_CXX_FLAGS=-DNAM_USE_INLINE_GEMM builds: run_tests green (clang, Debug, same matrix as CI)
  • All 13 NAM translation units compile with -DNAM_NO_FILESYSTEM; nm shows no filesystem/fstream symbols in any object
  • In production use in a Teensy 4.1 (i.MX RT1062) firmware

Happy to add a CI configuration for the define if you want coverage.

Guard the <filesystem>/<fstream> includes and the std::filesystem::path
loader entry points behind #ifndef NAM_NO_FILESYSTEM. Bare-metal
toolchains (e.g. newlib on ARM Cortex-M) lack the POSIX syscalls that
libstdc++'s std::filesystem needs; with the define set, models load
through the JSON/dspData entry points instead. The default build is
unchanged.
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.

1 participant