From 5ee8a5b5c07ce40e3f5e0a089476a8d16518defe Mon Sep 17 00:00:00 2001 From: ivg Date: Wed, 17 Aug 2022 16:05:33 -0400 Subject: [PATCH] adds support for loading plugins in toplevels 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: ivg --- otherlibs/site/src/plugins/dune | 2 +- otherlibs/site/src/plugins/linker/dune | 5 +++++ otherlibs/site/src/plugins/linker/dynlink/dune | 5 +++++ otherlibs/site/src/plugins/linker/dynlink/linker.ml | 1 + otherlibs/site/src/plugins/linker/linker.mli | 1 + otherlibs/site/src/plugins/linker/toplevel/dune | 6 ++++++ otherlibs/site/src/plugins/linker/toplevel/linker.ml | 1 + otherlibs/site/src/plugins/plugins.ml | 2 +- 8 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 otherlibs/site/src/plugins/linker/dune create mode 100644 otherlibs/site/src/plugins/linker/dynlink/dune create mode 100644 otherlibs/site/src/plugins/linker/dynlink/linker.ml create mode 100644 otherlibs/site/src/plugins/linker/linker.mli create mode 100644 otherlibs/site/src/plugins/linker/toplevel/dune create mode 100644 otherlibs/site/src/plugins/linker/toplevel/linker.ml diff --git a/otherlibs/site/src/plugins/dune b/otherlibs/site/src/plugins/dune index 378af3bb8750..cbaf5cd3efac 100644 --- a/otherlibs/site/src/plugins/dune +++ b/otherlibs/site/src/plugins/dune @@ -6,6 +6,6 @@ (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) (instrumentation (backend bisect_ppx))) diff --git a/otherlibs/site/src/plugins/linker/dune b/otherlibs/site/src/plugins/linker/dune new file mode 100644 index 000000000000..ce852a1e35b5 --- /dev/null +++ b/otherlibs/site/src/plugins/linker/dune @@ -0,0 +1,5 @@ +(library + (name linker) + (public_name dune-site.linker) + (virtual_modules linker) + (default_implementation dune-site.dynlink)) diff --git a/otherlibs/site/src/plugins/linker/dynlink/dune b/otherlibs/site/src/plugins/linker/dynlink/dune new file mode 100644 index 000000000000..851802c02d98 --- /dev/null +++ b/otherlibs/site/src/plugins/linker/dynlink/dune @@ -0,0 +1,5 @@ +(library + (name dune_site_dynlink_linker) + (public_name dune-site.dynlink) + (implements dune-site.linker) + (libraries dynlink)) diff --git a/otherlibs/site/src/plugins/linker/dynlink/linker.ml b/otherlibs/site/src/plugins/linker/dynlink/linker.ml new file mode 100644 index 000000000000..73bf7a03a50f --- /dev/null +++ b/otherlibs/site/src/plugins/linker/dynlink/linker.ml @@ -0,0 +1 @@ +let load = Dynlink.loadfile diff --git a/otherlibs/site/src/plugins/linker/linker.mli b/otherlibs/site/src/plugins/linker/linker.mli new file mode 100644 index 000000000000..63fbb5a31860 --- /dev/null +++ b/otherlibs/site/src/plugins/linker/linker.mli @@ -0,0 +1 @@ +val load : string -> unit diff --git a/otherlibs/site/src/plugins/linker/toplevel/dune b/otherlibs/site/src/plugins/linker/toplevel/dune new file mode 100644 index 000000000000..c56cd49f8249 --- /dev/null +++ b/otherlibs/site/src/plugins/linker/toplevel/dune @@ -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)) diff --git a/otherlibs/site/src/plugins/linker/toplevel/linker.ml b/otherlibs/site/src/plugins/linker/toplevel/linker.ml new file mode 100644 index 000000000000..563590db4366 --- /dev/null +++ b/otherlibs/site/src/plugins/linker/toplevel/linker.ml @@ -0,0 +1 @@ +let load = Topdirs.dir_load Format.err_formatter diff --git a/otherlibs/site/src/plugins/plugins.ml b/otherlibs/site/src/plugins/plugins.ml index 581a8b9f803a..7d848890f7bd 100644 --- a/otherlibs/site/src/plugins/plugins.ml +++ b/otherlibs/site/src/plugins/plugins.ml @@ -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 =