jank-lang / jank

The native Clojure dialect hosted on LLVM
https://jank-lang.org
Mozilla Public License 2.0
1.67k stars 49 forks source link

Hook jank into leiningen #29

Open jeaye opened 1 year ago

jeaye commented 1 year ago

I'm not sure how this will work yet, if jank will have a lein plugin or if something else is required. But jank will be adding support for require shortly, so we should be able to start hooking in deps, generating compilation artifacts, etc.

For now, blocked on #31.

NOTE: Keep in mind that jank will load .jank or .cljc files, but not .clj files. Just like ClojureScript.

Adding a run-main command

The jank CLI options are defined here: https://github.com/jank-lang/jank/blob/main/include/cpp/jank/util/cli.hpp The source to process them is here: https://github.com/jank-lang/jank/blob/main/src/cpp/jank/util/cli.cpp

Our run-main command will be very similar to the run command, but will load a module, rather than a file. We're using a new command, rather than a flag, since there's no point in loading a specific file from the lein project; we want to load a module, based on the class path we have.

I'd duplicate the run function we have into a run_main and use the rt_ctx to load the module. https://github.com/jank-lang/jank/blob/main/src/cpp/main.cpp#L29

We'll need a new transient string target_module option to go along with the command.

With out module loaded, we'll need to find the var for -main within that class and invoke it. The rt_ctx can be used to find the var. You can use dynamic_call on that to invoke it (don't forget to deref the var to get its root).

Passing in the command-line arguments will be more difficult, since we'll need to add CLI support for a -- flag, which then consumes everything after it. jank uses CL11 for flag handling, so you'll need to check out how to do -- there: https://github.com/CLIUtils/CLI11

The final command for lein jank run foo bar spam should look like this:

jank run-main my.program --class-path <...> -- foo bar spam
Samy-33 commented 10 months ago

@jeaye, please assign this to me