Up

Module Side_effect : S with type t := unit

In some cases, we are only interested by the toplevel side effects of dynlinked modules.

Signature

type t
val load_ocaml_src_files : dynloader -> string list -> t Async.Std.Deferred.Or_error.t

Load a bunch of ocaml files source files (.ml + .mli). The last module's signature should be compatible with the signature X.repr. If the type does not match, there will be an error during OCaml compilation. The files are copied into the compilation directory, and compiled versus a generated mli file including the relevant module signature. This generated file is then dynlinked with the current executable.

The compilation happens using Dynlink.loadfile_private, meaning that the toplevel definition defined in these files are hidden (cannot be referenced) from other modules dynamically loaded afterwards

val check_ocaml_src_files : dynloader -> string list -> unit Async.Std.Deferred.Or_error.t

Similar to load_ocaml_src_files, but does not execute the plugin toplevel, just checks that compilation and dynamic linking work.

The following functions are used for step by step use, not for the casual user because they are much more error prone. Prefer load_ocaml_src_files if possible

val compile_ocaml_src_files_into_cmxs_file : dynloader -> string list -> output_file:string -> unit Async.Std.Deferred.Or_error.t

This compiles the source files into cmxs file, but does not execute the plugin toplevel. The resulting cmxs file can be loaded by blocking_load_cmxs_file either from the same process or other processes which share the same executable. If compile succeeds, it returns Ok and write the compiled cmxs file into output_file (may override existing file), otherwise it returns Error and won't write to output_file at all.

val blocking_load_cmxs_file : string -> t Core.Std.Or_error.t

Dynlink has the following not really wanted property: dynlinking a file with a given filename only works properly the first time. Further dynlinks with the same filename (even a different file) will not load the new module but instead execute the initial module. Some even says that the behavior upon reload depends on the platform. Long story short: don't do that. Dynlink files at most once.

It is worth noting too that this function only works with cmxs files produced by ocaml_plugin's compile_ocaml_src_files_into_cmxs_file. It expects the code to perform some internal library calls, thus it cannot be used with any arbitrary cmxs compiled in some other way. Furthermore this function would return an error even though the cmxs was built with ocaml_plugin when built under a different context (compiler version used, cmi dependencies version, etc.) The intended usage is to have the compilation and loading done using the same executable.