Remix.run Logo
ranger_danger 3 days ago

The one big downside I see is that if you want to actually work on the library itself, it's a pain to have to re-compile the entire thing every time you change something.

Nuklear (https://github.com/Immediate-Mode-UI/Nuklear) uses separate files with a deploy script that combines them all into a single header; I think that approach is quicker for iterating on the code.

colleagueRiley 3 days ago | parent | next [-]

Sure, but the library is also relatively small, so it compiles quickly. Although if you want to you can compile it on its own.

It's also possible to compile it on its own using `gcc -c -x c -D RGFW_IMPLEMENTATION RGFW.h`

Nuklear is not a true single-header style library, it only uses that as a format. The difference is that the design is far less compact and lightweight than a stb-style library.

I'm pretty sure GLFW has some files that are nearly the same size as RGFW, for example.

ranger_danger 3 days ago | parent [-]

Why do you claim Nuklear is not a "true single-header style library"? And who gets to say what that even means?

colleagueRiley 3 days ago | parent [-]

It is a single-header library in terms of the format, yes. But it is also not designed to be a single-header library, unlike an STB-style library.

Nuklear is a full-sized library that can be compiled into and used as one file. However, RGFW and STB are designed to be lightweight and minimalistic. That's the distinctive part of single-header libraries, also known as STB-style libraries.

To be clear, I don't mean this to hate on Nuklear, it's a cool UI library, but its design doesn't match the single-header format.

ranger_danger 3 days ago | parent [-]

How is it not designed to be a single-header library? The README even directly states "Single-header library".

How is it not designed to be lightweight and minimalistic?

How do you think the design differs from your idea (which is what exactly?) of a "single-header format"?

colleagueRiley 3 days ago | parent [-]

https://github.com/SasLuca/glfw-single-header/blob/master/ex...

ranger_danger 3 days ago | parent [-]

What is this supposed to be telling me? This also looks like it was multiple files concatenated together because there are multiple different header guards throughout the file.

CyberDildonics 3 days ago | parent | prev [-]

Have you actually tried? This is 287 KB of C. MSVC on computers from 15 years ago will compile C at about 60 MB/s. I'm skeptical this is actually a problem.

SQLite is distributed as a single 6 MB .c file and compiles in ... 0.1 seconds.

jstimpfle 3 days ago | parent [-]

That may be true for extremely simple source code, but it's almost too good to be true. Your number sounded so impressive that I tried with gcc (12.2) on my Linux VM. With -O0, it takes around 27s, with -O2 it's 1m07s.

With -E (only preprocess) we are at around 0.320s for the 260K lines of sqlite3.c. Which makes sense, 1M lines/s for the preprocessor and maybe also the AST should be doable (that may be where you got your 60MB/s number from). But compiling is something else.

MSVC may be faster here or not, I haven't tested it.

A more modern machine (mine is a i5-7600K from 2018) may be 2x or more faster, and running on multiple threads will speed up the build as well.

CyberDildonics 3 days ago | parent | next [-]

(that may be where you got your 60MB/s number from)

It's not that. I think I messed up and the 0.1 seconds was tcc and msvc was 1 or 2 seconds. Nothing was 27 seconds. Try tcc, even though you are in a VM it should be very fast as a baseline for what's possible.

The point is that some people talk about single header files being slow are really saying "what if". C is incredibly fast to compile and the slow parts are the overhead from each compilation unit and the optimizers.

287 KB of source code added to a compilation unit is nothing in the modern era. Not only that, but you can just choose to put a lot of them in the same compilation unit and not touch it again.

Every time I've used single file header libraries it makes things simple and fast. I'm not going to change them so dumping them all into a single compilation unit is fine.

mandarax8 3 days ago | parent | prev [-]

What exactly did you try to compile and how?

  $ time gcc -x c  -c RGFW.h -D RGFW_IMPLEMENTATION -fPIC -D RGFW_EXPORT
  0.42s user 0.03s system 93% cpu 0.485 total
jstimpfle 3 days ago | parent [-]

sqlite3, if you read carefully again.