package extunix
Install
Dune Dependency
Authors
Maintainers
Sources
md5=c2706a62e14f64dbc347d986a38d7b1c
sha256=3ad5c6bfef5d87273f7ba91bf14c4cebee9171439cfacdb06b294427cf034bed
sha512=cccc4808a901284c26e6b268b8536d5dbfe24ccc83bf090fe38e20698647f054573fdfcd1c5709d3aedbe49c6bd45927b317e8b94bb1e8d91d6c22765915bbcb
Description
Motto: "Be to Unix, what extlib is to stdlib"
- Implement thin C bindings that directly map to underlying system API.
- Provide common consistent ocaml interface: naming convention, exceptions.
- Simple to build - no extra dependencies.
README
ExtUnix OCaml library
A collection of thin bindings to various low-level system API.
Our motto: "Be to Unix, what extlib is to stdlib"
Implement thin C bindings that directly map to underlying system API.
Provide common consistent ocaml interface: naming convention, exceptions.
Simple to build - no extra dependencies.
Homepage: https://ygrek.org/p/ocaml-extunix/
Why?
Most of the system API don't deserve fully fledged library.
The ExtUnix project aims to collect these in one place. Read the "ExtUnix integration requirements" to know what kind of system API we can integrate.
Installation
Dependencies :
OCaml, Dune, ppxlib for build and installation
(optional) oUnit2 for tests, odoc for documentation
Build and install:
make
make install
Alternatively use the underlying Dune build system directly (plain ocaml, no sh and make needed):
dune build @install
Usage example:
$ ocaml
# #use "topfind";;
# #require "extunix";;
# module U = ExtUnix.Specific;;
# U.ttyname Unix.stdout;;
- : string = "/dev/pts/8"
Run unit tests:
make test
Guidelines
For OCaml programming style, we follow Unix module:
Values and types should be named by the name of the underlying C function
Raise
Unix_error
on runtime errorsUniformly raise
Not_available
exception for functions not available on the current platformBe MT friendly by default - i.e. release runtime lock for blocking operations, (FIXME) optionally provide ST variants
Portability:
No shell scripting for build and install (think windows :) )
Write portable C code (use compiler options to catch compatibility issues), NB: msvc doesn't support C99.
Provide module (
ExtUnix.Specific
) exposing only functions available on the platform where library is built - i.e. guaranteed to not throwNot_available
exception (experimental).
Build infrastructure:
discover
is used to discover available functions during configure step.Generated
config.h
describes "features" discovered - it is responsible for inclusion of system-specific headers - this ensures coherent result at configure and build steps.Generated
extUnixConfig.ml
describes the same features for the ocaml syntax extensionppx_have
, which preprocessessrc/extUnix.pp.ml
and generates two modules:ExtUnix.All
where bindings to missing functions are rewritten to raise exception andExtUnix.Specific
which drops bindings to missing functions.
ExtUnix integration requirements
We can integrate into ExtUnix:
Official POSIX calls not in Unix module.
Drafted POSIX calls which are at least present on two systems among: Linux, *BSD, MacOS X.
System specific calls, as long as they don't need additional library, that they are marked as such in the documentation and that we have an automatic configure system test for them.
We should avoid system calls that are complex and would deserve a library on their own. For example, a family of more than 10 functions and datatypes should deserve its own library. If an external library already exists and works, like for inotify system call, we also won't consider it for integration.
Regarding Win32 portability: If there is a sane default to create a portable equivalent of the function on Windows, we can consider it. And we will mark it as such in the documentation.
Checklist for adding new bindings
Add the C code to
src
(follow the code style of existing bindings)Add the required checks to
discover/discover.ml
Add the name of the C bindings to
src/dune
Add the OCaml code to
src/extUnix.pp.ml
guarded withHAVE ... END
Add some tests to
test/test.ml
Add note to
CHANGES.txt
Run
make
Checklist for release
Review
git log
and updateCHANGES.txt
Increase VERSION in Makefile
Commit
make release
Development
Many people contribute to extunix. Please submit your patches and/or feature requests to the project bugtracker at https://github.com/ygrek/extunix/issues.
The current maintainer is reachable at mailto:ygrek@autistici.org.
Dependencies (7)
- base-unix
- base-bigarray
- base-bytes
-
ppxlib
>= "0.18" & build
-
dune-configurator
build
-
ocaml
>= "4.06" & < "5.0"
-
dune
>= "2.2"
Dev Dependencies (1)
-
ounit2
with-test
Used by (6)
Conflicts
None