Reduce libc surface for embedded/bare metal targets#326
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Working on tests right now to not hit codecov issues (and I suppose to make sure this all works haha) |
|
Those CI errors look to be related to the new IERS stuff and not a part of this PR |
|
Thanks Kiran! I think that is a good idea. But, we might need more compile config options still (e.g. |
0440498 to
596001b
Compare
596001b to
7d22d15
Compare
|
Yeah |
|
again pretty confused by CI stuff here |
I tend to go with simpler is (always) better. Fewer knobs means less chance of weird (unexpected) stuff and also less confusing for people trying to use them. So, I'd go with just no clock and/or no Trying to target every possible platform is bound to lead to some pain down the road with maintaining. I'd say that whatever build switches we (you) add, we also have to come up with automated tests for them in the CI to ensure they do not get broken down the line. I'm not even sure how we can test for embedded platforms in Github Actions, but surely someone has come up with a way to do that (maybe some docker images)... I'm not adamant that this must be done for this PR, but at some point in the not too distant future -- if you want the support for embedded / bare metal platforms to stay properly maintained.... |
|
The multi-arch CI has some issues (not the first time). It fails setting up the Docker images correctly, so it's nothing to do with the C stuff here. Re-running it once (or twice) usually clears it. And, eventually whoever maintains those images will fix it... :-). I've just started a re-run... |
|
It looks good to me at first glance. There is still missing code coverage. But there is no rush to get it sorted. :-) |
|
The missing coverage seems to be the failure paths of the tests, which I don't expect coverage of |
|
Oh, I see. I thought I disabled coverage tracking on the test code itself. I'm a bit surprised it is back... |
|
OK, I think I fixed the coverage on |
|
@kiranshila , I had an after thought. Setting the error handler to |
|
Ah yeah that makes sense. I'll work on the rest of the libc stuff now and see if I can get a CI build for wasm or some embedded platform |
- Add WITHOUT_LIBC=ON build mode for bare-metal/WASM targets without libc file I/O, heap, or system clock - Add NOVAS_NO_SYSTEM_CLOCK build flag for targets without system clock - Add pluggable trace/error message handler (novas_set_error_handler) - Fix is*() functions to cast to unsigned char - Remove spurious stdlib.h includes - Fix novas_set_catalog() NUL-termination - CI: add embedded ARM cross-compile build (WITHOUT_LIBC=1)
- Add WITHOUT_LIBC=ON build mode for bare-metal/WASM targets without libc file I/O, heap, or system clock - Add NOVAS_NO_SYSTEM_CLOCK build flag for targets without system clock - Add pluggable trace/error message handler (novas_set_error_handler) - Fix is*() functions to cast to unsigned char - Remove spurious stdlib.h includes - Fix novas_set_catalog() NUL-termination - CI: add embedded ARM cross-compile build (WITHOUT_LIBC=1)
- Add WITHOUT_LIBC=ON build mode for bare-metal/WASM targets without libc file I/O, heap, or system clock - Add NOVAS_NO_SYSTEM_CLOCK build flag for targets without system clock - Add pluggable trace/error message handler (novas_set_error_handler) - Fix is*() functions to cast to unsigned char - Remove spurious stdlib.h includes - Fix novas_set_catalog() NUL-termination - CI: add embedded ARM cross-compile build (WITHOUT_LIBC=1)
Motivation
I'm working on a safe Rust wrapper for SuperNOVAS and realized that we're quite close to having a library that would work on resource-constrained targets. This is potentially useful as this could enable SuperNOVAS on microcontrollers (maybe simple antenna drive electronics) or web-based analysis tools with WASM. Looking through the code base, there really is not that much that needs the C runtime or an allocator (which is the limiting factor for these targets). While this PR isn't everything (there are still calls to errno and snprintf, in which removal would enable true bare-metal support), this should get us most of the way there for another PR.
Changes
timescale.c:NOVAS_NO_SYSTEM_CLOCKbuild flagnovas_set_current_timeis the only function in the C99 core that needs system time information. On targets with no clock, this change allows users to build with-DNOVAS_NO_SYSTEM_CLOCK. Then, this function returns -1 with an error and descriptions. However, on bare-metal targets we then can avoid use ofnovas_set_current_timeand not get linker errors!The default behavior is of course unchanged.
util.c: pluggable trace/error message handlerThis is perhaps the biggest change. Currently, the debug/trace handling always uses stdio for its output. On other bare-metal platforms, there is either some hook for stdio (which we don't want to use), or some way to get IO. I'm thinking mainly on embedded, there are nice out-of-band logging frameworks that would be really nice to hook in here.
As such, I've replaced the fprintf calls in the five tracing helpers with a function-pointer hook.
This introduces a new public API:
So:
Future Work
For full bare-metal support we need to remove the snprintf calls and errno writes, but that was a bit more work and I thought we'd start with this. Already with this PR we should be able to run on some WASM platforms.