package ctypes-foreign

All checked builds pass
  1. Overview
  2. Docs
Dynamic access to foreign C libraries using Ctypes

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.24.0.tar.gz
sha256=249c5604c8554659761a7282db4ad200aa8c0fdc408cdb53102bd70feeb51955
md5=064316aaf508a9db203f114bb8401dee

Description

This installs the ctypes-foreign interface which uses libffi to provide dynamic access to foreign libraries.

Tags

org:mirage

Added to opam-repository:

README

ctypes is a library for binding to C libraries using pure OCaml. The primary aim is to make writing C extensions as straightforward as possible.

The core of ctypes is a set of combinators for describing the structure of C types -- numeric types, arrays, pointers, structs, unions and functions. You can use these combinators to describe the types of the functions that you want to call, then bind directly to those functions -- all without writing or generating any C!

GitHub Actions status

Usage

Suppose you want to bind to the following C functions:

   int sigemptyset(sigset_t *set);
   int sigfillset(sigset_t *set);
   int sigaddset(sigset_t *set, int signum);
   int sigdelset(sigset_t *set, int signum);
   int sigismember(const sigset_t *set, int signum);

Using ctypes you can describe the interfaces to these functions as follows:

   let sigemptyset = foreign "sigemptyset" (ptr sigset_t @-> returning int)
   let sigfillset = foreign "sigfillset" (ptr sigset_t @-> returning int)
   let sigaddset = foreign "sigaddset" (ptr sigset_t @-> int @-> returning int)
   let sigdelset = foreign "sigdelset" (ptr sigset_t @-> int @-> returning int)
   let sigismember = foreign "sigismember" (ptr sigset_t @-> int @-> returning int)

The names bound by this code have the types you might expect:

   val sigemptyset : sigset_t ptr -> int
   val sigfillset : sigset_t ptr -> int
   val sigaddset : sigset_t ptr -> int -> int
   val sigdelset : sigset_t ptr -> int -> int
   val sigismember : sigset_t ptr -> int -> int

That's all there is to it. Unlike the usual way of writing C extensions, there are no C "stub" functions to write, so there's much less opportunity for error.

The documentation and source distribution contain more complex examples, involving structs, unions, arrays, callback functions, and so on, and show how to create and use C values (like instances of sigset_t ptr) in OCaml.

Dependencies (6)

  1. conf-libffi >= "2.0.0"
  2. conf-pkg-config
  3. dune-configurator
  4. ctypes = version
  5. ocaml >= "4.07.0"
  6. dune >= "3.9"

Dev Dependencies (6)

  1. odoc with-doc
  2. conf-fts with-test & os != "win32"
  3. conf-ncurses with-test
  4. ounit2 with-test
  5. lwt with-test & >= "2.4.7"
  6. integers with-test & >= "0.2.2"

Optional Dependencies

None

Used by (94)

  1. argon2
  2. arrayjit
  3. async_ssl
  4. bimage-unix
  5. bls12-381 = "0.3.15"
  6. bls12-381-legacy < "0.4.4"
  7. bls12-381-unix < "1.0.2"
  8. camlkit-base
  9. cf
  10. checked_oint < "0.4.1"
  11. cmark
  12. cmarker
  13. corosync
  14. ctypes < "0.21.1"
  15. ctypes-zarith
  16. cudajit
  17. directories < "0.3"
  18. echo
  19. extism
  20. flock
  21. gccjit
  22. gdal
  23. gl-legacy
  24. gobject-introspection
  25. gpiod
  26. gr
  27. guile
  28. hacl-star-raw < "0.4.4"
  29. hardcaml_c
  30. hardcaml_verilator
  31. hdr_histogram
  32. hegel
  33. imguiml
  34. keynub-licdongle
  35. libbpf_maps
  36. libdash
  37. libdrm
  38. libinput
  39. libirmin
  40. libudev
  41. lilv
  42. llama-cpp-ocaml
  43. lmdb < "1.0"
  44. lp-glpk < "0.4.0"
  45. lp-gurobi
  46. memtrace_viewer < "v0.15.0"
  47. metal
  48. mmdb
  49. mpg123
  50. netlink
  51. nx < "1.0.0~alpha1"
  52. ocaml-yescrypt
  53. ocephes
  54. opasswd
  55. opencc < "transition"
  56. opencc0
  57. opencc1
  58. opencc1_1
  59. orocksdb
  60. osx-cf
  61. osx-secure-transport
  62. pari
  63. pari-bindings
  64. pg_query
  65. pkcs11-driver
  66. pkcs11-rev
  67. portaudio_c_bindings
  68. posix-getopt < "2.0.0"
  69. py
  70. qcstm >= "0.1.1"
  71. raylib-callbacks
  72. reed-solomon-erasure
  73. rune < "1.0.0~alpha3"
  74. sarek
  75. sattools
  76. sodium < "0.6.0"
  77. spoc
  78. srt
  79. stk_iconv
  80. swipl
  81. tensorflow
  82. tgls
  83. tinyfiledialogs
  84. torch
  85. tsdl
  86. tsdl-image
  87. tsdl-mixer
  88. tsdl-ttf
  89. unix-type-representations < "0.1.1"
  90. wasmer
  91. wasmtime
  92. xgboost
  93. yara
  94. yices2_bindings

Conflicts

None

Build status

Results of building ctypes-foreign with each compiler on check.ci.ocaml.org, run of against opam-repository 7cdc698. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
0.24.0 (this version) good good good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure