Skip to content

Commit

Permalink
adds support for loading plugins in toplevels
Browse files Browse the repository at this point in the history
Uses virtual libraries to select the proper dynamic linker
facility. To load in the toplevel add `dune-site.toplevel` library as
the dependency to your toplevel.

Signed-off-by: Ivan Gotovchits <[email protected]>
  • Loading branch information
ivg committed Aug 17, 2022
1 parent d4bcecb commit a3e0aff
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion otherlibs/site/src/plugins/dune
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
(dune_site
(plugins)
(data_module dune_site_plugins_data)))
(libraries dune-site dune-private-libs.meta_parser dynlink))
(libraries dune-site dune-private-libs.meta_parser linker))
5 changes: 5 additions & 0 deletions otherlibs/site/src/plugins/linker/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(library
(name linker)
(public_name dune-site.linker)
(virtual_modules linker)
(default_implementation dune-site.dynlink))
6 changes: 6 additions & 0 deletions otherlibs/site/src/plugins/linker/dynlink/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(library
(name dune_site_dynlink_linker)
(modes native)
(public_name dune-site.dynlink)
(implements dune-site.linker)
(libraries dynlink))
1 change: 1 addition & 0 deletions otherlibs/site/src/plugins/linker/dynlink/linker.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let load = Dynlink.loadfile
1 change: 1 addition & 0 deletions otherlibs/site/src/plugins/linker/linker.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val load : string -> unit
6 changes: 6 additions & 0 deletions otherlibs/site/src/plugins/linker/toplevel/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(library
(name dune_site_toplevel_linker)
(modes byte)
(public_name dune-site.toplevel)
(implements dune-site.linker)
(libraries compiler-libs.toplevel))
1 change: 1 addition & 0 deletions otherlibs/site/src/plugins/linker/toplevel/linker.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let load = Topdirs.dir_load Format.err_formatter
2 changes: 1 addition & 1 deletion otherlibs/site/src/plugins/plugins.ml
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ let load_gen ~load_requires dirs name =
List.iter
(fun p ->
let file = Filename.concat directory p in
Dynlink.loadfile file)
Linker.load file)
plugins)

let rec load_requires name =
Expand Down

0 comments on commit a3e0aff

Please sign in to comment.