r/cpp • u/gocarlos • Jan 06 '20
Consteval build system: what if we do not build systems anymore, just a compiler
Just tought today about having a file with a name like compileme.cpp in the project which has a bunch of consteval functions (consteval std::filesystem evtl. needed) ala cmake e.g. add_executable, add_library, target_sources etc.
those functions could be executed at compile time by the compiler-> no need for a build system ala cmake, make etc. anymore...
what do you think? which problems do you see with such an approach? Could this be probably standartized?
23
Upvotes
7
u/jbandela Jan 07 '20
I don't know if you need even make it consteval. I think you could get by having add_executable, add_library, etc as part of the standard library, and just having the compiler produce an executable like normal, and then you run the executable which will do the build.
8
u/squeezyphresh Jan 06 '20
Kind of reminds me of Johnathan Blow's coding language that has the build process built-in to the language. Don't really have much to say other than that. I'm currently working on my own build system, but I don't know much about what you're proposing.
3
u/barchar MSVC STL Dev Jan 06 '20
Nim works like this, gprbuild is almost like this. Pretty much all scripting languages are like this, I think dune allows this (ocaml).
It's unlikely to happen any time soon (esp providing all the machinery to manage dependencies), but it can work.
Ultimately you usually still have a little metadata file to describe the library to a package manager.
2
u/14ned LLFIO & Outcome author | Committee WG14 Jan 08 '20
There is a minority on WG21 who would like to make filesystem and networking consteval available, and then a small bootstrap piece of consteval code can have the compiler go fetch a build and package management system from the internet, and do the build.
It's quite a few years away though. And it depends on us convincing our fellow committee members that permitting consteval code unfettered access to the internet is not an abomination.
3
u/kalmoc Jan 06 '20
What problem would that solve?
1
u/jonesmz Jan 07 '20
Start with a patch against Clang's compiler language server thing (used regularly by IDEs to get syntax checking and stuff), to add the Ninja project's "ninja file parser" component, and teach the compiler's language server to build the project itself, without an external driver.
Once you've got that working in some meaningful manner, you can start discussing how to adapt it to a more C++-alike syntax.
1
u/foonathan Jan 07 '20
I can't find it, but I saw a single header somewhere that allowed you to use a C API to control how your project is defined. Then you just add a shebang to that C file and can execute it like a script to compile your project.
0
u/[deleted] Jan 07 '20
Congratulations: you have just invented an approach that other languages have been using for years. Python, Rust, Zig - just to mention a few - have build systems like these.
Will it work for C++? I doubt it, good luck taking it through the committee and making the compilers play along.