Coder Social home page Coder Social logo

Split into .c and .h files about sokol HOT 3 CLOSED

floooh avatar floooh commented on July 22, 2024
Split into .c and .h files

from sokol.

Comments (3)

floooh avatar floooh commented on July 22, 2024

Yeah, controversial topic I know, but I'll keep sokol header-only.

Some reasons:

  • configuration-defines don't spill out into the build system, instead you can put them right before the implementation includes
  • when compiling on MacOS, a .c file wouldn't work because the implementation contains Objective-C code, so there would have to be a sokol_gfx.c with just the C code, and another sokol_gfx.m file with just the Obj-C parts
  • I consider the STB headers the reference, and those have been working just fine for many projects
  • compilation time difference isn't measurable, and will most likely be less when packing all header-only libs of a project into a single implementation source file (similar to a unity build), the implementation code is skipped, not parsed (since there are no inline functions like in many C++ header-only libs), integrating sokol_gfx.h into Oryol has actually reduced compile time by a about 7 seconds

To integrate the sokol headers into a bigger project, you would basically provide the sokol.c / sokol.m file yourself:

https://github.com/floooh/sokol-samples/blob/master/sapp/sokol.c

https://github.com/floooh/sokol-samples/blob/master/sapp/sokol.m

Apologies for closing this issue, but this is one of those topics where both sides have valid arguments and it comes down to endlessly discussing personal preference ;)

from sokol.

eloraiby avatar eloraiby commented on July 22, 2024

No worries :)
these can be baked into one header file, using the same approach as nuklear using a script.

Would you merge a pull request that does that ?

from sokol.

floooh avatar floooh commented on July 22, 2024

Would you merge a pull request that does that ?

Not at the moment, I need to think more about it. Right now it's not a high priority, but this might change as more headers are added.

I'm aware of the merge-script approach that nuklear uses since quite recently, but I would need to figure out how to automate the merge during the edit/compile/test loop (could be done with a fips/cmake custom build step I guess).

FYI, sokol_gfx.h also started in separate pieces, not C-files, but one header file per 3D-backend which was then included by the top-level sokol_gfx.h.

from sokol.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.