-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Originally posted by @andrewrk in #24558
But one of the main use cases for zig libc is freestanding. So these functions should be exported when the target is
freestandingorother
I agree that this is a good use case for libzigc. From the PR description of #23529:
I repurposed the existing "universal libc" code to do this. That code hadn't seen development beyond basic string functions in years, and was only usable-ish on freestanding. I think that if we want to seriously pursue the idea of Zig providing a freestanding libc, we should do so only after defining clear goals (and non-goals) for it. See also #22240 for a similar case.
What I meant by this is that we should define a clear subset of the C standard library that we are interested in providing in freestanding libzigc. This will also mean answering various ABI questions; for example, it's easy to say that we want to have all the string and math functions, but is our char unsigned or signed? What's our wchar_t defined as? What about double on platforms like AVR (where it's sometimes, but not always, equal to float)? So on and so forth. We also need to figure out if we want to provide more complex functions that might require memory allocation or system interaction, and if so, how we want to allow users to fill in the missing bits (e.g. malloc), which will mean defining a stable "system <-> libc ABI" of sorts.
Implementing a universal libc, especially one that works on freestanding, is not as straightforward as it sounds due to issues like this, and I think we'd be doing a disservice to potential contributors if we don't have answers to at least some of these questions before we open this task up for contributions, since they might write code that we decide we're actually not satisfied with.