Giter VIP home page Giter VIP logo

Comments (6)

yallop avatar yallop commented on May 26, 2024 1

It works like this:

  1. you use the same ctypes API to describe structs, functions, etc.
    (so you should be able to keep your existing code mostly intact)
  2. you place the descriptions from step 1 inside functors that accept modules of type Ctypes.TYPE (for the structs) and Ctypes.FOREIGN (for the functions).
  3. you pass the functors to Cstubs.write_ml and Cstubs.write_c to generate code that you can statically link into your program.

Conceptually, the idea is to give the ctypes bindings DSL a different interpretation so that it works as a compiler than an interpreter. The tradeoffs are similar to the interpreter/compiler tradeoff, too: it's a bit more work to set up the build, but in return you get faster code and better type-checking (since the generated code is checked against library headers).

If you decide to try this route there are various examples around, such as ocaml-mariadb or ocaml-yaml that it might be useful to copy.

from libdash.

yallop avatar yallop commented on May 26, 2024

Out of interest, have you considered using ctypes without dynamic linking?

from libdash.

mgree avatar mgree commented on May 26, 2024

No, I hadn't, because I didn't know you could. You've got my attention! How does it work?

from libdash.

mgree avatar mgree commented on May 26, 2024

That sounds very promising! I'll take a look.

I would need ocamlmklib call that just included the .a file from the original library along with the .o from those generated stubs, right? I'd generate the stubs at build time and then be able to ship a single, statically linked .cmxa?

from libdash.

yallop avatar yallop commented on May 26, 2024

I would need ocamlmklib call that just included the .a file from the original library along with the .o from those generated stubs, right?

Yes, along with the .cmx code from the generated OCaml.

I'd generate the stubs at build time and then be able to ship a single, statically linked .cmxa?

Yes.

from libdash.

mgree avatar mgree commented on May 26, 2024

Resolved in #29.

from libdash.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.