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 (95)

  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. modelkit-xgboost
  50. mpg123
  51. netlink
  52. nx < "1.0.0~alpha1"
  53. ocaml-yescrypt
  54. ocephes
  55. opasswd
  56. opencc < "transition"
  57. opencc0
  58. opencc1
  59. opencc1_1
  60. orocksdb
  61. osx-cf
  62. osx-secure-transport
  63. pari
  64. pari-bindings
  65. pg_query
  66. pkcs11-driver
  67. pkcs11-rev
  68. portaudio_c_bindings
  69. posix-getopt < "2.0.0"
  70. py
  71. qcstm >= "0.1.1"
  72. raylib-callbacks
  73. reed-solomon-erasure
  74. rune < "1.0.0~alpha3"
  75. sarek
  76. sattools
  77. sodium < "0.6.0"
  78. spoc
  79. srt
  80. stk_iconv
  81. swipl
  82. tensorflow
  83. tgls
  84. tinyfiledialogs
  85. torch
  86. tsdl
  87. tsdl-image
  88. tsdl-mixer
  89. tsdl-ttf
  90. unix-type-representations < "0.1.1"
  91. wasmer
  92. wasmtime
  93. xgboost
  94. yara
  95. yices2_bindings

Conflicts

None

Build status

Results of building ctypes-foreign with each compiler on check.ci.ocaml.org, run of against opam-repository 8d8d144. 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