package ctypes

All checked builds pass
  1. Overview
  2. Docs
Combinators for binding to C libraries without writing any C

Install

dune-project
 Dependency

Authors

Maintainers

Sources

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

Description

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!

To install the optional ctypes-foreign interface (which uses libffi to provide dynamic access to foreign libraries), you will need to also install the ctypes-foreign package.

opam install ctypes-foreign

This will make the ctypes-foreign ocamlfind subpackage available.

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

  1. dune-configurator
  2. integers
  3. ocaml >= "4.07.0"
  4. dune >= "3.9"

Dev Dependencies (4)

  1. odoc with-doc
  2. conf-pkg-config with-test
  3. conf-fts with-test & os != "win32"
  4. ounit2 with-test

Optional Dependencies

None

  1. ahrocksdb
  2. antic < "0.4.0"
  3. arb < "0.4.0"
  4. argon2
  5. arrayjit
  6. async_ssl >= "v0.15.0"
  7. bimage-unix
  8. bitgenerators
  9. calcium < "0.4.0"
  10. camlkit-base
  11. ceph
  12. cf
  13. checked_oint < "0.4.1"
  14. cmark
  15. cmarker
  16. corosync
  17. ctypes-build
  18. ctypes-foreign >= "0.24.0"
  19. ctypes-zarith
  20. ctypes_stubs_js
  21. cudajit
  22. directories
  23. dlm >= "0.3.3"
  24. dune >= "3.17.2"
  25. echo
  26. eigen >= "0.1.4"
  27. extism
  28. flint < "0.5.0"
  29. fsevents
  30. gccjit
  31. gdal >= "0.10.0"
  32. gl-legacy
  33. gobject-introspection
  34. gpiod
  35. gr
  36. guile
  37. hacl-star-raw >= "0.7.2"
  38. hardcaml_c
  39. hardcaml_verilator
  40. hdr_histogram
  41. hegel
  42. imguiml
  43. imguiml-raylib
  44. keynub-licdongle
  45. kqueue < "0.2.0"
  46. libbpf
  47. libbpf_maps
  48. libdash >= "0.3"
  49. libdrm
  50. libinput
  51. libirmin
  52. lilv
  53. llama-cpp-ocaml
  54. llvm >= "3.7"
  55. lp-glpk
  56. lp-gurobi
  57. luv >= "0.5.14"
  58. luv_unix
  59. lz4 >= "1.3.0"
  60. mariadb < "1.1.5" | >= "1.2.0"
  61. memcpy >= "0.2.2"
  62. metal
  63. mmdb
  64. modelkit-xgboost
  65. mpg123
  66. netlink >= "0.3.4"
  67. nx < "1.0.0~alpha1"
  68. ocaml-yescrypt
  69. opasswd
  70. opencc < "transition"
  71. opencc0
  72. opencc1
  73. opencc1_1
  74. orocksdb
  75. osx-acl
  76. osx-attr
  77. osx-cf
  78. osx-fsevents
  79. osx-membership
  80. osx-mount
  81. osx-secure-transport
  82. osx-xattr
  83. owl >= "0.9.0"
  84. pari
  85. pari-bindings
  86. pg_query
  87. pkcs11-driver
  88. pkcs11-rev
  89. portaudio_c_bindings
  90. posix-base
  91. posix-bindings < "3"
  92. posix-errno
  93. posix-getopt >= "2.0.0"
  94. posix-math2
  95. posix-resource
  96. posix-signal
  97. posix-socket
  98. posix-socket-unix
  99. posix-stat
  100. posix-time2
  101. posix-types
  102. posix-uname
  103. posix-unistd
  104. ppx_cstubs >= "0.7.0"
  105. py >= "1.1"
  106. quickjs
  107. raygui < "1.5.1"
  108. raylib
  109. reed-solomon-erasure
  110. rfc1951 >= "1.3.0" & < "1.6.0"
  111. rune < "1.0.0~alpha3"
  112. sanlock
  113. sarek
  114. sattools
  115. sodium < "0.6.0"
  116. spin >= "0.8.0"
  117. spoc
  118. srt
  119. stk_iconv
  120. swipl
  121. sys-socket
  122. sys-socket-unix
  123. tensorflow
  124. tgls >= "0.9.0"
  125. tinyfiledialogs
  126. torch
  127. tsdl >= "1.1.0"
  128. tsdl-image >= "0.3.0"
  129. tsdl-mixer
  130. tsdl-ttf >= "0.3"
  131. unix-errno >= "0.4.1" & < "0.5.0" | >= "0.6.2"
  132. unix-sys-resource
  133. unix-sys-stat
  134. unix-time
  135. unix-type-representations >= "0.1.1"
  136. uring-trace
  137. wasmer
  138. wasmtime
  139. xedbindings
  140. xgboost
  141. xxhash
  142. yaml
  143. yara
  144. yices2_bindings
  145. zstandard
  146. zstd >= "0.4"

Conflicts (1)

  1. host-system-msvc

Build status

Results of building ctypes 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