Skip to content

Conversation

@loumalouomega
Copy link

This PR introduces a single-header, amalgamated version of the library to simplify distribution and integration for end-users. Consumers can now include the entire library in their project by simply dropping in a single .hpp file.


Description

Purpose 🎯

The primary goal of this change is to lower the barrier to entry for using this library. Instead of requiring users to manage multiple files, set up include paths, and link source files with their build system, they can now use a single, self-contained header. This "header-only" approach is common for C++ utility libraries and significantly improves the user experience.

Implementation 🛠️

This was achieved by using the amalgamate.py script to combine all necessary source and header files into one file.

  * A config.json has been added to define the source files, include paths, and the target output file.
  * The resulting amalgamated file is located at dist/nlohmann-json-schema-validator.hpp.

Usage 🚀

To use the library, users can now copy dist/nlohmann-json-schema-validator.hpp into their project and include it directly:

#include "nlohmann-json-schema-validator.hpp"

Next Steps

This generated file is not intended to be edited directly. Future development should continue in the source files within src/. The amalgamation process should be re-run before a new release to ensure the distributed header is up-to-date. This process can be integrated into our CI/CD pipeline to automate releases.

For Maintainers: How to Update

The single-header file is generated and should not be edited directly. All development must continue in the src/ directory.

To regenerate the amalgamated header after making changes, run the following command from the project root:

# Ensure you have amalgamate.py available
# https://bitbucket.org/erikedlund/amalgamate/src/master/
python path/to/amalgamate.py -c config.json -s .

Changelog

@loumalouomega
Copy link
Author

What is the status of this @pboettch ?

@pboettch
Copy link
Owner

I can't get my head around this idea. I'm really unsure this amalgated version solves any real problem. But I'm oldschool and I like find-package and cmake.

Could anyone enlighten me why this would be needed and in which practical use case this is a better than "traditional" compile and link?

@loumalouomega
Copy link
Author

I can't get my head around this idea. I'm really unsure this amalgated version solves any real problem. But I'm oldschool and I like find-package and cmake.

Could anyone enlighten me why this would be needed and in which practical use case this is a better than "traditional" compile and link?

The primary benefit is simply convenience. A header-only or single-file library eliminates integration friction and linking issues.

Actually, the specific reason I created this version was to bypass a stubborn linking error I was facing in MSVC; this was the most straightforward fix. Since major libraries like nlohmann/json already use automatic amalgamation, it felt like a pragmatic solution to dependency management.

@LecrisUT
Copy link
Collaborator

Header only libraries have a bunch of pitfalls themselves particularly when they could be compiled in multiple libraries. Doing it proper is not something I would recommend unless there's proper time to research it. Projects are moving away from header-only design, particularly with the cxx-modules.

As for the technicalities of this PR, I will only highlight one issue right now for you to consider: it is unsustainable since this is not automatically generated and kept in sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants