Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE REQUEST] Examples for building Dune libraries #56

Open
PSFW opened this issue Jul 24, 2024 · 5 comments
Open

[FEATURE REQUEST] Examples for building Dune libraries #56

PSFW opened this issue Jul 24, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@PSFW
Copy link

PSFW commented Jul 24, 2024

Is your feature request related to a problem? Please describe.
Currently the examples are for building executables (Dune files with the executable Stanza), and these are output into .wat files with (export "_initialize").
I am trying to output a basic library, and export the functions of that library to use within Web Assembly.

Describe the solution you'd like
I would like to be able to export multiple functions, and for examples to be provided for this.
I am not sure if this is currently possible with the tool.

Describe alternatives you've considered
I have tried the examples, as well as my own .ml & .mli files. I have also tried to use the --export and --wrap-with-fun options but these have not worked for me (they seem to be for JSOO). (I have even browsed this repo that was linked in another issue.)

@PSFW PSFW added the enhancement New feature or request label Jul 24, 2024
@OlivierNicole
Copy link
Collaborator

o1-labs/integers_stubs_js#10 is an example of adding Wasm stubs to a library. It works when using the required fork of Dune referenced in the readme. Does that help solve your problem?

@PSFW
Copy link
Author

PSFW commented Aug 4, 2024

Hey @OlivierNicole, thank you so much for your reply!

I have followed the example provided, and using that the change that I've applied has only been to add this stanza:

 (js_of_ocaml
  (javascript_files ./heyworld.js)
  (wasm_files heyworld.wat)
  )

The generated .wat file still contains only a single export though (for "_initialize").

Have you hand-crafted or edited the .wat file in the example that you've provided?

@OlivierNicole
Copy link
Collaborator

Sorry for the late reply.

The WebAssembly code is written by hand.

@PSFW
Copy link
Author

PSFW commented Aug 19, 2024

No problem, thank you for letting me know.

@OlivierNicole
Copy link
Collaborator

I might have misunderstood your question. The primitives (declared as external in the ocaml code) need to be written by hand, but OCaml functions should be compiled to Wasm.

To build a library and not an executable, the instructions in #36 should work. I don’t think separate compilation is supported by our Dune fork yet, but @vouillon knows better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants