nim-lang / RFCs

A repository for your Nim proposals.
137 stars 23 forks source link

`nim c --dump:out.json main`: dump compiler output metadata (dependencies etc) to json #412

Open timotheecour opened 3 years ago

timotheecour commented 3 years ago

proposal

add a flag --dump:filename to nim cmdline which allows generating compiler output metadata to a json file, which can then be used for tooling; eg:

design goals

why json?

because it's simple and universal and will not cause a performance bottleneck for the data being generated. In particular, nim genDepend main generates a custom text format deps file which can't be extended without introducing a breaking change, whereas json output can be extended by adding additional fields without a breaking change

why not nim genDepend main ?

why not nim dump main ?

that's a separate command, it doesn't compose with other commands (eg nim c main) and can't be used for such purposes

why not nim c --genScript main ?

--genScript serves a different purpose (generating a compile script), and doesn't compose with other commands (eg nim js or nim r or nim check etc); it also modifies behavior of nim c as it doesn't actually generate object files and a binary but instead is used as precursor for another command

That said, a lot of the code can be shared and reused in the implementation of --dump since it also generates a json file in nimcache

Varriount commented 3 years ago

I wonder if a reevaluation of Nim's CLI interface isn't in order. Not necessarily a redesign, but just some analysis for issues and redundancies - looking at the current full help is... a lot.

Rather than dumping a selection of metadata to a file, what about: