Up

module Ocaml_compiler

: sig

This module offers an higher level api over Ocaml_dynloader. This retrieves the compiler and a bunch of cmi files embedded in the current executable, and use them to do the compilation of ocaml source files, before loading them using Dynlink. The compilation steps happen in Async.

This is meant to be used in unix only, in particular because it uses /proc to determine the location of the exec code being run.

#
type t

mutable type to get the compiler and the cmi which must have been embedded in the executable

#
val config_file : string
#
type 'a create_arguments = (?persistent_archive_dirpath:string -> 'a) Ocaml_dynloader.create_arguments
#
val create : (unit -> [
| `this_needs_manual_cleaning_after of t
] Async.Std.Deferred.Or_error.t) create_arguments

This is a special utilisation of the Generic Loader. It relies on a few assumptions, such as a file called ocamlopt.opt is present in the archive, as well as some cmi files, and uses a tmp compilation_directory. A call to this function will retrieve the embedded part of the code, and extract it in the current corresponding directory. The most common use and the default value for code_file is `my_code. Currently this library works with native code only. Called in bytecode, this function will return the exception Ocaml_dynloader.Is_not_native See the documentation of ocaml_dynloader for other flags, they are passed internally to that module to create the internal dynloader (in _dir, custom_warnings_spec, etc.).

/!\ By using this manual create, you take the responsibility to call clean t when you're done with all the compilation that you want to do with this compiler. Consider using with_compiler, Make or load_ocaml_src_files if this makes your life simpler.

#
val with_compiler : (f:(t -> 'a Async.Std.Deferred.Or_error.t) -> unit -> 'a Async.Std.Deferred.Or_error.t) create_arguments

Call create, do something with the compiler, and then take care of calling clean. In case an exception or a shutdown happen and f never returns, an attempt to clean the compiler is still done via an at_shutdown execution.

#
val loader : t -> Ocaml_dynloader.t

Get the loader using this compiler and these cmi

#
val clean : t -> unit Async.Std.Deferred.Or_error.t

This will delete the temporary directory created, and remove all the files, included the files generated by the loader. This function should be used when the compiler has been created using create for advanced use of this module. For a simpler usage, look at with_compiler or the functor below.

#
module type S = sig
#
type t
#
val load_ocaml_src_files : (string list -> t Async.Std.Deferred.Or_error.t) create_arguments
#
val check_ocaml_src_files : (string list -> unit Async.Std.Deferred.Or_error.t) create_arguments
#
val check_plugin_cmd : Async.Std.Command.t

Command that checks that the anon files given compile and match the interface X given. Also provides a -ocamldep mode allowing only the main file to be passed on the command line.

#
module Load : Ocaml_dynloader.S with type t := t

Load contains functions similar to the ones above, and can be used if you want to separate extraction of the compiler from building/loading files. It can be useful if you want to extract the compiler upfront (to improve latency a bit) or if you want to share the cost of extracting the compiler for the current executable over multiple compilations. Probably not needed by the casual user

end
#
module Make : functor (X : Ocaml_dynloader.Module_type) -> S with type t := X.t

This is a wrapper for the similar module in Ocaml_dynloader that takes care of cleaning the compiler afterwards.

#
module Side_effect : S with type t := unit

In some cases, we are not interested by the module, but rather because it uses a side effect registering mechanism.

end