lib: add picolibc compatibility for embedded builds - #308
Conversation
442a7c5 to
916f7a3
Compare
picolibc is the C library used by most bare-metal and RTOS targets
(Zephyr, etc.). Like the Windows layer in fy-win32.h, it lacks a few
POSIX facilities that previously broke the build. This adds support in
the same spirit: a small compatibility header plus capability-gated
branches, keyed on the C library's own __PICOLIBC__ macro rather than on
any OS, so builds against a full-featured C library (glibc, newlib) are
unaffected.
- src/util/fy-picolibc.h: new compatibility header, the picolibc analog
of fy-win32.h. Double-guarded (FY_PICOLIBC_H + #ifdef __PICOLIBC__) so
it is a no-op everywhere else. Provides isatty() and the STD*_FILENO
macros that picolibc omits, each #ifndef-guarded, via fy_picolibc_*
helpers macro-aliased to the POSIX names.
- libfyaml-util.h: provide struct iovec and SSIZE_MAX (no <sys/uio.h>),
mirroring the existing _WIN32 arm.
- libfyaml-endian.h: derive byte order from the compiler __BYTE_ORDER__
builtins, extending the existing per-OS include selection.
- libfyaml-align.h: use C11 aligned_alloc() (no posix_memalign()).
- fy-input.c: picolibc has no <sys/mman.h>; skip the mmap optimization
and fall through to the existing stdio/read path.
- fy-utils.{c,h}: skip <termios.h>/<sys/uio.h>; stub the terminal-size
query; report emit-to-string (open_memstream) unsupported.
- fy-diag.c, fy-emit.c: include the picolibc shim for isatty()/STD*_FILENO.
All picolibc branches nest inside the existing non-Windows paths; the
Windows and POSIX/glibc branches are byte-for-byte unchanged. The new
header is registered in both build systems (src/Makefile.am EXTRA_DIST
and CMakeLists.txt). No public API or ABI change.
Signed-off-by: Anuj Deshpande <anuj@makerville.io>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Make libfyaml usable as a Zephyr west module for in-memory YAML 1.2 /
JSON parsing (parse from a RAM buffer or a streamed pull callback; no
filesystem required).
- zephyr/module.yml, CMakeLists.txt, Kconfig: build glue. CONFIG_LIBFYAML
builds the core parser, document model and emitter. The allocator
subsystem, parse cache, BLAKE3, threading, generic and reflection
subsystems are excluded (not needed for the classic document tree).
- zephyr/include/config.h: forced build configuration, replacing the
autotools/CMake-probed config.h.
- samples/parse_string: parses a YAML config blob from an in-memory
buffer and reads values back; builds and runs on native_sim and
builds for nrf52840dk (picolibc). Includes a twister sample.yaml.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: Anuj Deshpande <anuj@makerville.io>
916f7a3 to
4d1322e
Compare
|
@pantoniou thoughts? Anything I can do better here to help this get through |
|
Hi Anuj,
I've seen the PR. I will have some detailed comments in a couple of days.
Sorry, I'm in the middle of some rather large refactoring.
…On Wed, Jun 17, 2026 at 7:01 AM Anuj Deshpande ***@***.***> wrote:
*anujdeshpande* left a comment (pantoniou/libfyaml#308)
<#308 (comment)>
@pantoniou <https://github.com/pantoniou> thoughts? Anything I can do
better here to help this get through
—
Reply to this email directly, view it on GitHub
<#308?email_source=notifications&email_token=AAQGJWSAZ6AR3RLKHA7AT7T5AIJ2XA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTINZSGU3TQNJTGMY2M4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-4725785331>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAQGJWRRSXBXDEOMMRAN46L5AIJ2XAVCNFSNUABFKJSXA33TNF2G64TZHMZDAOBXHAYDGNRRHNEXG43VMU5TINJYGUYDAOJTGU2KC5QC>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
pantoniou
left a comment
There was a problem hiding this comment.
Needs a few changes.
On a different note, I don't want to see a Claude sign off message, and I don't like the verbose style of claude commit messages.
We all use AI agents but for something to be mergeable a human must take ownership. First part of that is having the commit message being written by one.
I don't mind over-terse messages, but I want to know that someone looked over it.
|
|
||
| size = FY_ALIGN(align, size); | ||
| #ifndef _WIN32 | ||
| #if defined(__PICOLIBC__) |
There was a problem hiding this comment.
Since you already have a picolib.h file that implements the set of posix apis that you need, add a posix_memalign wrapper there.
Then this #ifdef can be removed.
| #include <errno.h> | ||
| #include <stdarg.h> | ||
| #include <ctype.h> | ||
| #ifndef _WIN32 |
There was a problem hiding this comment.
You don't need to do that, add your picolib include in fy-utils.h
| #include <limits.h> | ||
| #include <ctype.h> | ||
| #include <errno.h> | ||
| #ifndef _WIN32 |
| case fyit_fd: | ||
|
|
||
| if (fyi->addr) { | ||
| #if !defined(__PICOLIBC__) |
There was a problem hiding this comment.
Add mmap/munmap wrappers in your picolib.h header.
They will fail and then fall-back.
|
|
||
| /* only map if not zero (and is not disabled) */ | ||
| /* only map if not zero (and is not disabled); | ||
| * picolibc has no mmap, fall through to the stdio/read path */ |
There was a problem hiding this comment.
Try to avoid peppering PICOLIB all over the place - use your wrapper header.
| return NULL; | ||
| memset(fyms, 0, sizeof(*fyms)); | ||
| #if !defined(_WIN32) | ||
| #if defined(__PICOLIBC__) |
There was a problem hiding this comment.
There is fully working open_memstream implementation in src/util/fy-utils.c originally added for older mac os version that lacked one that was internal. See if you can use it if picolib supports funopen
picolibc is the C library used by most Zephyr (and other bare-metal) targets. Unlike glibc/newlib it does not expose a number of POSIX facilities, which previously broke the build. This adds support in the same spirit as the existing Windows layer (fy-win32.h): a small compatibility shim plus capability-gated branches, keyed on the C library's own PICOLIBC macro rather than on any OS.