zshipko / ocaml-rs

OCaml extensions in Rust
https://docs.rs/ocaml
ISC License
259 stars 31 forks source link

bytecode compatibility #110

Open mimoo opened 1 year ago

mimoo commented 1 year ago

I'm trying to run ocamldebug on some OCaml code that is linked to a Rust library (using ocaml-rs). I need to build to the bytecode format before I can do that with dune build some/path.bc but I get the following error:

Error: Error on dynamically loaded library: ./src/lib/crypto/kimchi_bindings/stubs/dllwires_15_stubs.so: Truncated file

I'm wondering if there's a way to make this work? Or if this is because FFI can't happen due to the bytecode format of OCaml

tizoc commented 1 year ago

Hi, just pinged you. I had this same issue some time ago, but it is unrelated to ocaml-rs. Just copy the file manually after a regular build and before you try to build the bytecode program:

cp ./_build/cargo_kimchi_bindgen/debug/libwires_15_stubs.so src/lib/crypto/kimchi_bindings/stubs/dllwires_15_stubs.so
mimoo commented 1 year ago

ah, Imma try that!

A coworker told me that this change also made it work: https://github.com/MinaProtocol/mina/commit/b3ae083da7caf3714a47d01dc676e37ec975bd01 but that it wouldn't work on mac

mimoo commented 1 year ago

btw I think I don't have .so because I'm on mac?

❯ ls ./_build/cargo_kimchi_stubs/release 
build                  examples               libwires_15_stubs.a    libwires_15_stubs.rlib wires_15_stubs.d
deps                   incremental            libwires_15_stubs.d    wires_15_stubs
tizoc commented 1 year ago

hmmm weird, I would expect to see a .dylib instead, but it is not there.

And the docs confirm that the "cdylib" crate type should produce that (EDIT: that change in the commit you linked was reverted later, but you need that "cdylib" there, I had to add it a while back when I hit the same issue as you)

--crate-type=cdylib, #![crate_type = "cdylib"] - A dynamic system library will be produced. This is used when compiling a dynamic library to be loaded from another language. This output type will create .so files on Linux, .dylib files on macOS, and *.dll files on Windows.