-
Notifications
You must be signed in to change notification settings - Fork 412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for dune rtop
alongside dune utop
#2694
Comments
Rather than keep on adding stuff to Dune, we'd like to go in a slightly different direction. More precisely, allow to integrate with Dune from within the toplevel. For instance, you'd start any toplevel without wrapping with |
Note that in the meantime it is possible to "load" rtop from inside utop IIRC. But unfortunately I can't find again the page where I read how to do it. |
This sounds wonderful! |
It's not much really but we have other priorities at the moment. If you are happy to spend a bit of time on this, I can give you some pointers. |
Sure, please send the pointers, I'll see if I can help. Thanks. |
Great :) So at a high level, this will work as follow: Dune will install a file
We can make dune print a file that the toplevel will evaluate. For instance, we could run To add a open Stdune
open Dune
open Import
open Fiber.O
let doc = "..."
let man =
[ `S "DESCRIPTION"
; `P "..."
; `Blocks Common.help_secs
]
let info = Term.info "toplevel-init-file" ~doc ~man
let term =
let+ common = Common.term in
Common.set_common common ~targets:[];
Scheduler.go ~common (fun () ->
let* setup = Import.Main.setup common in
let sctx =
Context_name.Map.find setup.super_contexts "default"
|> Option.value_exn
in
let dir =
Path.Build.relative
(Super_context.build_dir sctx)
(Common.prefix_target common dir)
in
... (* insert code similar to the one in the [setup] function in
[src/dune/utop] to compute [requires] *)
let include_paths = Lib.L.include_paths requires in
let files = Lib.L.link_deps requires ~mode:Link_mode.Byte in
let* () = do_build (Build.paths files) in
let files_to_load =
List.filter files ~f:(fun p ->
match Path.Build.extension p with
| ".cma" | ".cmo" -> true
| _ -> false)
in
Toplevel.print_toplevel_init_file ~include_paths ~files_to_load;
Fiber.return ())
let command = (term, info) Where:
Then you just have to add |
Thanks for this nice overview! But since I am very unfamiliar with Dune, I eventually got stuck when dealing with paths:
Could you please give me some hints as to how various kinds of paths work? And also whether I'm going roughly in the right direction overall? One other thing I noticed is that originally this functionality also worked as |
Sure, so we have:
Here, some of the files to load will be built by dune and so will be in the
It looks to me that you are going in the right direction!
Here the idea is that you'd load all the libraries in the tree rooted at the current working directory. That said, we could add a new directive, or even overload the |
Thanks! I'll try to sort it out. Dune is a bit overwhelming and it takes me a lot of time to figure out what pieces there are and how they fit together but, with your guidance, it seems doable :)
Yeah, I'll happily leave that for another PR, I was just wondering :) |
I have some progress. I finished my hacky version of toplevel-init-file (mbernat@f2d1c8a) I rely on the Unix module to capture subprocess output, which I guess is bad because dune is supposed to work on Windows too? Which also leads to me the question: can't we simply expose the required functionality as a library and call it directly, instead of using a binary and going through IO? It seems topfind is using this library approach. What do you think? Anyway, at this stage, I can manually copy my new dune.exe and the toplevel script into my projects and it seems to do the right thing by loading the deps and my libs. So what remains is improving my code (since it's ugly and I'm sure it will break in all kinds of settings), and adding the toplevel script to the dune installer. How do I do these things? Many thanks :) |
For Regarding loading a library, there are a few concerns:
Overall, I feel like the system will be more flexible if we invoke
To install the script, you can use the following stanza:
(the .mlt extension is for toplevel files). Then the next step is to submit a PR so that we can review the code :) Oh, and if you could add a test and documentation that would be great! For the test, you can add a directory in For the documentation, I suppose you can add a chapter "Toplevel integration" to the manual. You can do that by creating a new |
Hello @diml, once again thanks for all the great info and sorry about taking so long to get back to you.
Oh, I see. So I suppose, I'll just use I'll also add the install stanza, a test, and docs, and post a PR ASAP. |
No problem. Looking forward to the PR! |
@diml I'm basically ready with my initial version: https://github.com/mbernat/dune/tree/toplevel But I still need to rebase that on top of the current master to be able to create a PR and am a bit stuck because of a conflict. It's about the Please help :) |
Indeed, this function is getting more complicated. I'm going to prepare a PR that refactors it a bit and adds the |
Here it is: #2937 |
Awesome! |
And it's now merged! |
Thanks! I'll post the PR tomorrow.
…On Tue, Dec 3, 2019 at 9:25 AM Jérémie Dimino ***@***.***> wrote:
And it's now merged!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#2694?email_source=notifications&email_token=AAE5DYBO33JXKKZMGEY7E53QWYJWXA5CNFSM4I5FYPEKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFYQE7I#issuecomment-561054333>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAE5DYAONISJOFKJXXNHPK3QWYJWXANCNFSM4I5FYPEA>
.
|
Welp, it's finally here. Happy to address any issues (I'm sure there'll be plenty): #2952 |
Long since fixed. |
We are using dune for a Reason project, and
dune utop
is really useful. It would be great to supportrtop
in the same way. I think the API forrtop
is identical toutop
, so it should just be a matter of changing the executable name?The text was updated successfully, but these errors were encountered: