Code Monkey home page Code Monkey logo

unosolo's Introduction

unosolo

Work-in-progress Rust application that converts C++ header-only libraries to single self-contained headers.

stability license gratipay badge.rust

Disclaimer

This is my first Rust project, mainly created to start getting used to the language. My intention is to improve unosolo as I get better with Rust and the final goal is being able to successfully use it on popular libraries. (If you need a full-fledged customizable preprocessor implementation, check out pcpp.)

I also do not encourage people to create single-header libraries and use those in their projects: they're mainly useful when dealing with very complicated build systems or when experimenting on an online compiler that doesn't allow users to easily import multiple files.

Contributions and code reviews are welcome!

Build instructions

git clone https://github.com/SuperV1234/unosolo
cd unosolo
cargo build
  • cargo run -- args... can be used to build&run unosolo.

  • cargo install can be used to install unosolo on the user's system.

Overview

Given a set of paths containing the C++ header-only library's header files and a "top-level include" file where the graph traversal will start from, unosolo outputs a self-contained single-header version of the library to stdout. Here's the clap-rs auto-generated help:

unosolo 0.1.1
Vittorio Romeo <[email protected]>
transforms a C++ header-only library in a self-contained single header.

USAGE:
    unosolo [FLAGS] [OPTIONS] --topinclude <top_include>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
    -v, --verbose    Enable verbose mode

OPTIONS:
    -p, --paths <paths>...            Include paths [default: .]
    -t, --topinclude <top_include>    Top-level include file path (entrypoint)

Use cases

scelta

unosolo is currently able to transform scelta, my latest C++17 header-only library, to a single-header version. In fact, I've used unosolo to add two badges to scelta's README that allow users to try the library either on wandbox or on godbolt. This idea was taken from Michael Park's excellent variant implementation: mpark::variant.

The command used to transform scelta was:

unosolo -p"./scelta/include" -v -t"./scelta/include/scelta.hpp" > scelta_single_header.hpp

It produced this abomination.

vrm_core and vrm_pp

Since 0.1.1, unosolo supports multiple library include paths and "absolute #include directives". My vrm_core library, which depends on vrm_pp, can be transformed to a single header as follows:

git clone https://github.com/SuperV1234/vrm_pp.git
git clone https://github.com/SuperV1234/vrm_core.git
unosolo -p"./vrm_pp/include" "./vrm_core/include" -t"./vrm_core/include/vrm/core.hpp" > vrm_core_sh.hpp

It produced this beauty.

boost::hana

A single-header version of boost::hana can be created using unosolo as follows:

git clone https://github.com/boostorg/hana
unosolo -p"./hana/include" -t"./hana/include/boost/hana.hpp" > hana_sh.hpp

I haven't tested it very thorougly, but I compiled the example on hana's README without any hiccups.

unosolo's People

Contributors

vittorioromeo avatar

Stargazers

Wade Welles avatar abdul dakkak avatar Matthieu Poullet avatar Rust avatar  avatar Mohammed Makhlouf (Mak) avatar Barrett Adair avatar  avatar Luka Kakia avatar Juanpe Bolívar avatar  avatar Cristian Pallarés avatar Davide Faconti avatar Konstantin Gizdov avatar Convery avatar Sergey Ivanov avatar Ian Henriksen avatar Sean avatar  avatar  avatar  avatar  avatar Masashi Fujita avatar Alejandro Jiménez Encinas avatar Konrad Kubacki avatar  avatar

Watchers

 avatar Barrett Adair avatar  avatar

Forkers

gomson

unosolo's Issues

consider supporting X macro headers

Header files without include guards are useful for holding large X macros. Here are some examples.

For example, after expanding a header the first time, unosolo does this for the second include:

#ifdef BOOST_CLBL_TRTS_ENABLE_NOEXCEPT_TYPES
#define BOOST_CLBL_TRTS_NOEXCEPT_SPEC noexcept
#define BOOST_CLBL_TRTS_IS_NOEXCEPT std::true_type
< blank line instead of expanded header >
#undef BOOST_CLBL_TRTS_NOEXCEPT_SPEC
#undef BOOST_CLBL_TRTS_IS_NOEXCEPT
#endif // #ifdef BOOST_CLBL_TRTS_ENABLE_NOEXCEPT_TYPES

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.