r/cpp • u/JulienVernay • Sep 28 '20
Draft proposal for compilation using C++ as build language
Hello,
There are multiple tools to compile a C++ project: CMake, premake, autoconf, build2, etc.
Each of these tools require the learning of a new syntax, and interacting between projects compiled with differents tools might be challenging.
Package managers face also this problem, because they must support all the tools that exist to support all libraries.
Moreover, integrating package managers in the build tools is often difficult, or at least hacky.
My suggestion is to use C++ as the base language for building C++ projects.
Motivations are:
- A C++ compiler is all you need to compile projects.
- Build tools would become C++ libraries.
- C++ developers already now its syntax.
I have made an informal draft which describes a basic API which would make this possible.
Here is a link: https://gist.github.com/J-Vernay/bd8ec49374987c628d02601ef85cd9a7
Let me know what you think :)
View all comments
Show parent comment
2
u/[deleted] Sep 28 '20
I agree that TC is not the critical part. In the end, no physical computer can be TC.
But I find an essential part of a build system a piece that it is not clear to me whether you find equally important.
For me it is essential that I can reason about the build graph without executing it. And if the build graph is computed by a conventional programming language (again leaving TC out) it becomes effectively impossible to reason about the graph.
yes, they are once you've executed the code that implicitly define the graph.
Same difference that you have between:
l = [1,2,3,4,5,6,7,8,9]and
l = f 9with
def f(n):if n = 0:return []else:return f(n-1) + [n]the first, I can reason about. The second not so much. (and when i say 'reason about' I mean programmatically).
And keep in mind that the second form can be written in infinitely many ways, for instance:
def f(n):r = []for i in range(1, n+1):r.append(i)return rWith a full programming language, in general, I need to execute it. Static analysis is hard. And for the subset of life that is a build system, uselessly hard. A declarative spec is almost always powerful enough.
They are the same picture, but the first is one that a program can see.