nicbarker / clay

High performance UI layout library in C.
https://nicbarker.com/clay
zlib License
1.29k stars 31 forks source link

[Feature Request] MSVC support #22

Closed mikejsavage closed 1 month ago

mikejsavage commented 2 months ago

Clay currently doesn't compile under MSVC because:

  1. It doesn't support C designated initializers
  2. It doesn't support __attribute__((packed))__
  3. It doesn't like CLAY__ALIGNMENT, #define CLAY__ALIGNMENT(type) _Alignof(type) works though

1 and 2 are not very nice to solve with Microsoft flavoured C, although I will say all of these have direct solutions if you don't mind C++

nicbarker commented 2 months ago

Thanks for opening this one! I had been putting it off until the core implementation stabilized, but we can definitely begin to address each of these

It doesn't support C designated initializers

AFAIK there should be a way at the very least for the library syntax to be compatible with both C99 designated initializers as well as C++20 designated initializers. C++20 is much more picky but should be roughly syntax equivalent if the members are in declaration order

It doesn't support attribute((packed))__

Yep nice, should be able to replace this with a #ifdef of msvc and swap out for whatever equivalent to size enums into 1 byte

It doesn't like CLAYALIGNMENT, #define CLAYALIGNMENT(type) _Alignof(type) works though

This one should be reasonably easy to #ifdef in as well.

As for supporting non C99 versions of C, the best way forward might be to compile clay as a lib and write a second set of macros / declarations that are compatible with C11 etc... 🤔

nicbarker commented 2 months ago

From my investigations so far, it looks like I'm probably going to be able to get it in line with MSVC C++20. Microsoft flavoured C though, might not be possible. I don't think I'm willing to drop to C89 for the whole library just to support those versions on MSVC. Probably would be best in that case to just compile as a lib and link in 👍

nicbarker commented 2 months ago

Follow up: Successfully compiling as C++20 with MSVC here https://github.com/nicbarker/clay/actions/runs/11083013067/job/30796749136 😁

nicbarker commented 1 month ago

I'm going to mark this as completed for now, when clay stabilizes a little more we can reopen a discussion into whether it's worth dropping to C89 for the library itself in order to support C11 and beyond 🙂

mikejsavage commented 1 month ago

Yep I've been messing with clay in our engine, it seems fine so far but I haven't done much with it yet

nicbarker commented 1 month ago

@mikejsavage Great, please let me know if you end up building something with it!