{"id":15724319,"url":"https://github.com/cedlemo/ocaml-gi-ctypes-bindings-generator","last_synced_at":"2025-10-10T13:33:48.281Z","repository":{"id":144939690,"uuid":"116711934","full_name":"cedlemo/OCaml-GI-ctypes-bindings-generator","owner":"cedlemo","description":"gi-bindings-generator : OCaml Loader that uses GObject-Introspection in order to automatically create Ctypes bindings for Gnome libraries.","archived":false,"fork":false,"pushed_at":"2020-01-01T14:04:02.000Z","size":1205,"stargazers_count":6,"open_issues_count":14,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-26T18:11:44.675Z","etag":null,"topics":["ctypes-bindings","gobject-introspection","ocaml"],"latest_commit_sha":null,"homepage":"","language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cedlemo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-01-08T18:19:14.000Z","updated_at":"2024-04-22T20:46:40.000Z","dependencies_parsed_at":"2023-04-04T21:03:04.282Z","dependency_job_id":null,"html_url":"https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedlemo%2FOCaml-GI-ctypes-bindings-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedlemo%2FOCaml-GI-ctypes-bindings-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedlemo%2FOCaml-GI-ctypes-bindings-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cedlemo%2FOCaml-GI-ctypes-bindings-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cedlemo","download_url":"https://codeload.github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243318767,"owners_count":20272136,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ctypes-bindings","gobject-introspection","ocaml"],"created_at":"2024-10-03T22:16:09.911Z","updated_at":"2025-10-10T13:33:43.251Z","avatar_url":"https://github.com/cedlemo.png","language":"OCaml","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/cedlemo/OCaml-GI-ctypes-bindings-generator.svg?branch=master)](https://travis-ci.org/cedlemo/OCaml-GI-ctypes-bindings-generator)\n\n# gi-bindings-generator OCaml package\n\n## A GObject-Introspection Ctypes bindings generator library.\n\nThe idea is to use the gobject-introspection library in order to generate a\nconfigurable loader that will be able to construct automatically most of the\nCtypes bindings of any C GObject libraries (not all but at least a big part).\n\n## gi-bindings-generator and Dune (jbuilder)\n\nDune allows to easily use a [custom code generator](http://dune.readthedocs.io/en/latest/quick-start.html#using-a-custom-code-generator). Let's take the example\nof the [gi-glib2 package : OCaml-GLib2 ctypes bindings](https://github.com/cedlemo/OCaml-GLib2).\n\nHere is the directory tree of the repository:\n\n```\nλ › tree                                                                                                                                                                                                  OCaml-c/OCaml-GLib2  dllist_string\n.\n├── config\n│   ├── discover.ml\n│   └── jbuild\n├── COPYING\n├── generator\n│   ├── gen.ml\n│   └── jbuild\n├── gi-glib2.opam\n├── gpl-3.0.txt\n├── lib\n│   ├── Core.ml\n│   ├── Dllist.ml\n│   ├── dyn_load_constants_stubs.c\n│   └── jbuild\n├── README.md\n├── tests\n│   ├── jbuild\n│   ├── ...\n├── tools\n│   ├── jbuild\n│   └── list_targets.ml\n└── travis\n    ├── ...\n```\n\nAll the code of the bindings will be in the *lib/* directory. The *jbuild* file\nof this directory define the rules to construct the lib. In it there is this part:\n\n```sexp\n(rule\n ((targets (\n\t    Ascii_type.ml Ascii_type.mli\n\t    Bookmark_file_error.ml Bookmark_file_error.mli\n\t    ; ...\n\t    ; the names of the files that will be generated\n\t    ; ...\n\t    Date_time.ml Date_time.mli\n\t    Time_val.ml Time_val.mli\n\t    Time_type.ml Time_type.mli\n\t    Time_zone.ml Time_zone.mli\n\t    ))\n  (deps    (../generator/gen.exe)) ; the name, path of the generator.\n  (action  (run ${\u003c} -o ${@}))))   ; the command to run it.\n```\n\nThe code of the bindings generator is in the *generator/* directory. And here is\nthe code:\n\n```OCaml\nmodule BG = GI_bindings_generator\nmodule Loader = BG.Loader\n\n(** The namespace to be loaded: ie. the lib for which the bindings will be\n *  generated. *)\nlet namespace = \"GLib\"\n\n(** A suffix for the filenames of the raw bindings of the Core part. For example,\n *  all the constants and functions defined directly in the namespace are defined\n *  in a \"Core\" module and generated in \"Core.ml\" and \"Core.mli\" files. But, in\n *  in order to be able to tweak those automatically generated bindings, a\n *  suffix is added. Here, all the constants and functions of the namespaces\n *  will be found in the module Core_raw. Then in the lib/Core.ml file, I just\n *  load/open the Core_raw. *)\nlet files_suffix = \"Raw\"\n\n(** Instead of generate all the data structures (and theirs related methods or\n *  constants), the idea is to choose what is needed. *)\nlet data_structures =\n  [\"Error\"; \"Rand\"; \"Date\"; \"DateTime\"; \"TimeVal\"; \"TimeZone\";]\n\n(** One can choose to skip the bindings of some constants because they are not\n *  needed or because you want to create manually the bindings in the \"Core.ml\"\n *  file. *)\nlet const_to_skip = [\"MAJOR_VERSION\"; \"MINOR_VERSION\"; \"MICRO_VERSION\"]\n\n(** Like for the data_structures, you have to choose with function should have\n *  its bindings generated. *)\nlet functions = [\"random_double\"; \"random_double_range\";\n                 \"random_int\"; \"random_int_range\";\n                 \"get_current_time\";\n                 \"filename_to_uri\"; \"get_charset\";\n                 \"dir_make_tmp\"]\n\nlet sources = Loader.generate_files (\"Core\" ^ files_suffix)\n\nlet () =\n  let _ = Loader.write_constant_bindings_for namespace sources const_to_skip in\n  let _ = Loader.write_function_bindings_for namespace sources functions in\n  let _ = Loader.write_enum_and_flag_bindings_for namespace in\n  let _ = Loader.write_bindings_for namespace data_structures in\n  BG.Binding_utils.Sources.close sources\n```\n\nAfter that when you build your lib, all the files are generated and added in\nthe *_build/default/lib* directory before the compilation and test part.\n\n## Try:\n\n```\ngit clone git@github.com:cedlemo/OCaml-GObject-Introspection\nopam pin add gobject-introspection OCaml-GObject-Introspection\ngit clone git@github.com:cedlemo/OCaml-GI-ctypes-bindings-generator\n```\n\n## API:\n\nhttps://cedlemo.github.io/OCaml-GI-ctypes-bindings-generator/\n\n## Wiki :\n\nhttps://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#introduction\n\n###  table of content.\n\n- [GI_bindings_generator.Loader](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki)\n  - [Loader Implementation](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#loader-implementation)\n  - [Loader Progress](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#loader-progress)\n    - [Builders Started](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#builders-started)\n    - [Builders Next](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#builders-next)\n  - [Builder Code rules](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#builder-code-rules)\n    - [Module constants](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#module-constants)\n    - [Structures and Unions](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#structures-and-unions)\n    - [Enumerations](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#enumerations)\n      - [Simple Enumerations](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#simple-enumerations)\n      - [Flags : enumerations for bitwise operations](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#flags--enumerations-for-bitwise-operations)\n    - [Functions](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#functions)\n      - [Functions with only in arguments](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#functions-with-only-in-arguments)\n      - [Functions with out arguments](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#functions-with-out-arguments)\n      - [Functions with in/out arguments](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#functions-with-inout-arguments)\n      - [Recognizable patterns in functions](https://github.com/cedlemo/OCaml-GI-ctypes-bindings-generator/wiki#patterns)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedlemo%2Focaml-gi-ctypes-bindings-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcedlemo%2Focaml-gi-ctypes-bindings-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcedlemo%2Focaml-gi-ctypes-bindings-generator/lists"}