There are a number of fundamental use cases of C++ implementations, such as:
- compiling a C++ source file into an object file
- linking object files into a static library
- linking object files into a dynamic library
- linking object files, static libraries and dynamic libraries into programs
- coming soon: do stuff with modules
Each of these has a plethora of complex options.
I see two problems with the status quo:
- Each implementation has a different syntax for expressing the input, output and options of each of these use cases.
- The options are expressed through the command-line, which, as a data model, is essentially a dumb std::vector<std::string> with some kind of embedded implementation-specific DSL. Some of the rules around that DSL are downright insane. The result is expressed through an int exit code and semi-structured text with a non-standard format on STDERR.
For a taste of this look at:
I've been wondering whether it would be at all interesting if we proposed a standard API for implementations. Perhaps this could even be a C++ API.
As a quick scribble, along the lines of:
namespace std {
compilation_result compile_source_file(
const filesystem::path& output_object_file,
const filesystem::path& source_file,
const vector<filesystem::path>& include_paths,
const map<string, string>& defines,
etc
);
linking_result link_program( etc );
...other types / functions
}
The idea here is that the parameters and return type of each function are strongly typed, standardized, with well-specified semantics (like a normal API). People building atop them only have to write the client code once, and it will work across all standard implementations and platforms. The interface would also be far more robust (less error-prone) than the CLI DSL and "error scanners".
Thoughts?