Module Luv.Require

Feature checks.

You probably don't need these!

If you installed Luv in the usual way, through either opam or esy, you can ignore this module completely. In this case, Luv internally installed a vendored libuv of a recent version, and you have all the latest APIs available — whatever is exposed by your version of Luv is actually implemented by libuv.

However, if you installed Luv through a system package manager, or tweaked your Luv installation so that it links to a system or other external libuv — or if your users will do so — that external libuv might be of a considerably older version than Luv expects. Not all features normally exposed by Luv might actually be available.

For that case, this module provides a bunch of useful feature checks, so that you can control the behavior of your downstream project and/or prevent its compilation with too old a libuv.

This module itself is present since Luv 0.5.7.

type 'a feature constraint 'a = 'run_time * 'compile_time

A value of type 'a feature is physically either a bool or an int.

The constraint notation can be ignored. It's part of this module's internal type machinery for implementing compile-time feature checking.

Specific features (see below) have types like _40 feature or _true feature. The first is an int feature whose run-time value is 40, and the second is a bool feature whose run-time value is true.

As you can see, the run-time value can be seen from the type, and therefore from the docs, at a glance. So, you can quickly find out what your libuv supports by generating the docs for your Luv installation and looking at this module.

Of course, if you installed Luv through opam/esy and are using its vendored libuv, the int features will simply be the corresponding libuv version, and all the bool features will be _true.

val get : ('run_time * _) feature -> 'run_time

Returns the value of a feature at run time — in the ordinary way. Examples:

  • Luv.Require.(get luv05) returns 7 at the time of this writing — the current patch version of Luv (0.5.7).
  • Luv.Require.(get random) returns true if Luv was linked with a libuv late enough that it supports uv_random (1.33.0 or higher).
val (>=) : (int * 'compile_time) feature -> 'compile_time number -> unit

Triggers a compile-time check of an int feature.

For example, take Luv.Require.(libuv1 >= _33).

If the linked libuv has version 1.33.0 or higher, this check compiles. The compiled check then does nothing at run time — it is zero-cost.

If libuv has version less than 1.33.0, compilation of this expression triggers a type error. If that is too severe, you can relax to a run-time check by doing Luv.Require.(get libuv1) >= 33 instead.

The compile-time numbers _0_99 are defined for use with Luv.Require.(>=). They are hidden from this documentation to reduce visual noise.

These compile-time checks are modular in the sense that you can spread them throughout your project, locally where various features of libuv are being used, so that you don't have to do a survey of all your code in order to figure out the overall minimum libuv version. During build, your project will compile only if all the checks in its modules pass. They will then be optimized away.

val has : _true feature -> unit

Triggers a compile-time check of a bool feature.

For example, take Luv.Require.(has random).

If the linked libuv has uv_random, this check compiles, and is fully optimized away.

If libuv lacks uv_random, compilation of this check triggers a type error. The check can be relaxed to run time by doing Luv.Require.(get random) instead.

As with Luv.Require.(>=), you can insert these checks throughout your program, locally near where you use libuv features. The project will compile only if all the checks pass.


val libuv1 : _42 feature

libuv minor version in the 1.x series.

val luv05 : _7 feature

Luv patch version in the 0.5.x series.

val disconnect : _true feature

See `DISCONNECT in Luv.Poll.Event.t. Requires libuv 1.9.0.

val eftype : _true feature

See `EFTYPE in Luv.Error.t. Requires libuv 1.21.0.

val eilseq : _true feature

See `EILSEQ in Luv.Error.t. Requires libuv 1.32.0.

val enotty : _true feature

See `ENOTTY in Luv.Error.t. Requires libuv 1.16.0.

val eoverflow : _true feature

See `EOVERFLOW in Luv.Error.t. Requires libuv 1.42.0.

val esocktnosupport : _true feature

See `ESOCKTNOSUPPORT in Luv.Error.t. Requires libuv 1.42.0.

val err_name_r : _true feature

See Luv.Error.err_name. Requires libuv 1.22.0.

val fs_copyfile : _true feature

See Luv.File.copyfile. Requires libuv 1.14.0.

val fs_copyfile_ficlone : _true feature

See signature of Luv.File.copyfile. Requires libuv 1.20.0.

val fs_lutime : _true feature

See Luv.File.lutime. Requires libuv 1.36.0.

val fs_lchown : _true feature

See Luv.File.lchown. Requires libuv 1.21.0.

val fs_mkstemp : _true feature

See Luv.File.mkstemp. Requires libuv 1.34.0.

val fs_o_filemap : _true feature

See `FILEMAP Luv.File.Open_flag.t. Requires libuv 1.31.0.

val fs_realpath : _true feature

See Luv.File.realpath. Requires libuv 1.8.0.

val fs_statfs : _true feature

See Luv.File.statfs. Requires libuv 1.31.0.

val get_constrained_memory : _true feature

See Luv.Resource.constrained_memory. Requires libuv 1.29.0.

val get_osfhandle : _true feature

See Luv.File.get_osfhandle. Requires libuv 1.12.0.

val gettimeofday : _true feature

See Luv.Time.gettimeofday. Requires libuv 1.28.0.

val if_indextoiid : _true feature

See Luv.Network.if_indextoiid. Requires libuv 1.16.0.

val if_indextoname : _true feature

See Luv.Network.if_indextoname. Requires libuv 1.16.0.

val library_shutdown : _true feature

See Luv.Loop.library_shutdown. Requires libuv 1.38.0.

val loop_fork : _true feature

See Luv.Loop.fork. Requires libuv 1.12.0.

val maxhostnamesize : _true feature

Used internally. Requires libuv 1.26.0.

val metrics_idle_time : _true feature

See Luv.Metrics.idle_time. Requires libuv 1.39.0.

val mutex_init_recursive : _true feature

See Luv.Mutex.init. Requires libuv 1.15.0.

val open_osfhandle : _true feature

See Luv.File.open_osfhandle. Requires libuv 1.23.0.

val os_environ : _true feature

See Luv.Env.environ. Requires libuv 1.31.0.

val os_homedir : _true feature

See Luv.Path.homedir. Requires libuv 1.6.0.

val os_get_passwd : _true feature

See Luv.Passwd.get_passwd. Requires libuv 1.9.0.

val os_getenv : _true feature

See Luv.Env.getenv. Requires libuv 1.12.0.

val os_gethostname : _true feature

See Luv.Network.gethostname. Requires libuv 1.12.0.

val os_getpid : _true feature

See Luv.Pid.getpid. Requires libuv 1.18.0.

val os_getppid : _true feature

See Luv.Pid.getppid. Requires libuv 1.16.0.

val os_priority : _true feature

See Luv.Resource.setpriority. Requires libuv 1.23.0.

val os_tmpdir : _true feature

See Luv.Path.tmpdir. Requires libuv 1.9.0.

val os_uname : _true feature

See Luv.System_info.uname. Requires libuv 1.25.0.

val overlapped_pipe : _true feature

See Luv.Process.to_parent_pipe. Requires libuv 1.21.0.

val pipe : _true feature

See Luv.Pipe.pipe Requires libuv 1.41.0.

val pipe_chmod : _true feature

See Luv.Pipe.chmod. Requires libuv 1.16.0.

val prioritized : _true feature

See `PRIORITIZED in Luv.Poll.Event.t. Requires libuv 1.14.0.

val process_windows_hide_console : _true feature

See Luv.Process.spawn. Requires libuv 1.24.0.

val process_windows_hide_gui : _true feature

See Luv.Process.spawn. Requires libuv 1.24.0.

val random : _true feature

See Luv.Random.random. Requires libuv 1.33.0.

val readdir : _true feature

See Luv.File.readdir. Requires libuv 1.28.0.

val signal_start_oneshot : _true feature

See Luv.Signal.start_oneshot. Requires libuv 1.12.0.

val sleep : _true feature

See Luv.Time.sleep. Requires libuv 1.34.0.

val socketpair : _true feature

See Luv.TCP.socketpair. Requires libuv 1.41.0.

val strerror_r : _true feature

See Luv.Error.strerror. Requires libuv 1.22.0.

val tcp_close_reset : _true feature

See Luv.TCP.close_reset. Requires libuv 1.32.0.

val tcp_init_ex : _true feature

See Luv.TCP.init. Requires libuv 1.7.0.

val timer_get_due_in : _true feature

See Luv.Timer.get_due_in. Requires libuv 1.40.0.

val thread_stack_size : _true feature

See Luv.Thread.create. Requires libuv 1.26.0.

val translate_sys_error : _true feature

See Luv.Error.translate_sys_error. Requires libuv 1.10.0.

val try_write2 : _true feature

See Luv.Stream.try_write2. Requires libuv 1.42.0.

val tty_vterm_state : _true feature

See Luv.TTY.set_vterm_state. Requires libuv 1.33.0.

val udp_connect : _true feature

See Luv.UDP.Connected. Requires libuv 1.27.0.

val udp_init_ex : _true feature

See Luv.UDP.init. Requires libuv 1.7.0.

val udp_mmsg_chunk : _true feature

See `MMSG_CHUNK in Luv.UDP.Recv_flag.t. Requires libuv 1.35.0.

val udp_mmsg_free : _true feature

See `MMSG_FREE in Luv.UDP.Recv_flag.t. Requires libuv 1.40.0.

val udp_recvmmsg : _true feature

See Luv.UDP.init. Requires libuv 1.37.0.

val udp_set_source_membership : _true feature

See Luv.UDP.set_source_membership. Requires libuv 1.32.0.

val udp_using_recvmmsg : _true feature

See Luv.UDP.using_recvmmsg. Requires libuv 1.39.0.