-
Notifications
You must be signed in to change notification settings - Fork 415
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
[RFC] Add cmxs linkage for executables #1574
Conversation
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
8833dbe
to
b5db688
Compare
I would prefer if we could solve this problem without, in spirit, bundling .cmxs together because we are not able to load them. I think a solution to this question is just a question of installation and localization #1185. On the other hand, that doesn't add to much code. But still trying the right way would be better, so at least the feature should be added as experimental.
|
I am not sure I follow, but I don't see anything "hacky" about this PR. It exposes a feature of the OCaml compilation model: One easy use-case of this is linking a library together with a small "glue" module to make a plugin out of it. Yes, maybe this can also be solved by making the glue module into its own plugin and then loading both libraries in the right order, but it seems more complicated (and it is, on certain platforms 😄) than simply linking the library and the module together.
Personally I don't have a need for it (cf below, I would expect the resulting
Wherever the
I haven't looked at this yet, but I guess it should link in everything it can inside the |
I think dune has not the goal of expressing everything the compilers allows. For example the linking trick #136 became virtual libraries.
It is easier with the following restriction:
The current patch doesn't do it, and I don't know if the compiler allows it. How do you interact with the main program? The interaction library must be specified in the libraries field? But in that case it is statically linked with the .cmxs. How does that work? |
Right now I am passing the |
Regarding what features of the language Dune should provide: we should consider that Dune is a high-level interface for the OCaml language focused on the user experience. Invocations of the compiler is the assembly on which we build a consistent set of high-level and easy to use features. When we can't find the right way to nicely abstract and expose a feature of the compiler such that it is easy to document and is consistent with rest of Dune, and such a feature is important for users of Dune, then it is nice if we can provide an escape hatch for expert users. In the case of this PR, we have two choices:
For the second option, it seems to me that the only thing that is difficult currently is getting the transitive list of cmxa files to link. So for instance if we added a way to get it, then an expert user might write: (rule
(targets (:p plugin.cmxs))
(action (run ocamlopt -o %{p} %{transitive-cmxa:lwt,re}))) |
In the case of this PR, we have third:
Something similar to |
Indeed. You don't even need META files BTW, cmxs files already contain dependencies information. Given a set of cmxs files, it is possible to find out the order in which they should be loaded. We have some code for that somewhere at Jane Street. |
Thanks for the comments; adding some expert-level variables seems a better way to go about it. |
This PR introduces a new linking mode for executables allowing to link them as
.cmxs
archives. Concretely,will define a target
foo.cmxs
linking togetherbar.cmxa
andfoo.cmx
.Opinions appreciated (it has not seen much testing but it seems to work in simple cases). If there is agreement I will flesh out the patch (tests, doc, support for bytecode?)