Quantcast
Channel: OCaml - Topics tagged dune
Viewing all articles
Browse latest Browse all 536

How to use BER MetaOCaml with dune (cleanly)?

$
0
0

@ale wrote:

I’m trying to use BER MetaOCaml in a dune project. I was reading through several posts and github issues and didn’t manage to find any concrete examples. After trying many things, the following kinda works:

dune

(executable
 (name foo)
 (link_flags dynlink.cmxa compiler-libs/ocamlcommon.cmxa codelib.cmx runnative.cmx)
 (modes native))

bin/foo.ml

let string_of_code c =
  let () = Codelib.print_code Format.str_formatter c in
  Format.flush_str_formatter ()

let () =
  let c = .<1 + 2>. in
  let res = Runnative.run c in
  Printf.printf "Code: %s\nResult: %d\n" (string_of_code c) res

output of dune exec bin/foo.exe:

Code: .<1 + 2>.      

Result: 3

As you can see, there’s the horrible link_flags hack that scares children and adults alike. It also limits the mode to native (you could probably come up with a similar hack for byte mode). I would like to know if there’s a way to cleanly use metaocaml with dune. Thanks.

Relevant:

  1. https://github.com/ocaml/dune/issues/1413.
  2. https://github.com/ocaml/opam-repository/pull/13474
  3. opam switch show is 4.07.1+BER.

Posts: 9

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 536

Trending Articles