package ctypes

Build not checked
  1. Overview
  2. Docs
Combinators for binding to C libraries without writing any C

Install

dune-project
 Dependency

Authors

Maintainers

Sources

0.21.1.tar.gz
sha256=6f2b3b0f26c202b75ed7df3867fd9580d3e592af4944875b92ec0ee3ca7e14ff
md5=8b201d932741c5096854e5eb39139b90

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

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

This version is not in the latest run; the versions below are.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
0.24.0 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