Skip to content

Commit

Permalink
test(melange): add test exercising #7104 (#7204)
Browse files Browse the repository at this point in the history
* test(melange): add test exercising #7104

Signed-off-by: Antonio Nuno Monteiro <anmonteiro@gmail.com>
  • Loading branch information
anmonteiro committed Mar 1, 2023
1 parent 5de6e9f commit b21df14
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
(executable
(name ml)
(modules ml)
(libraries vlib impl_ml))

(melange.emit
(target output)
(alias melange)
(entries mel)
(libraries vlib impl_melange)
(module_system commonjs))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(lang dune 3.8)

(using melange 0.1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(library
(name impl_melange)
(modes melange)
(implements vlib))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let t = "melange"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(library
(name impl_ml)
(implements vlib))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let t = "ml"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
print_endline Virt.t
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_endline Vlib_impl.hello
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Test virtual lib in an exe / melange environment

The native build passes

$ dune exec ./ml.exe --display=short
ocamldep impl_ml/.impl_ml.objs/virt.impl.d
ocamldep vlib/.vlib.objs/shared.impl.d
ocamldep vlib/.vlib.objs/virt.intf.d
ocamldep vlib/.vlib.objs/vlib_impl.impl.d
ocamlc vlib/.vlib.objs/byte/virt.{cmi,cmti}
ocamlc vlib/.vlib.objs/byte/vlib_impl.{cmi,cmo,cmt}
ocamlopt vlib/.vlib.objs/native/vlib_impl.{cmx,o}
ocamlc vlib/.vlib.objs/byte/shared.{cmi,cmo,cmt}
ocamlc .ml.eobjs/byte/dune__exe__Ml.{cmi,cmti}
ocamlopt vlib/.vlib.objs/native/shared.{cmx,o}
ocamlopt impl_ml/.impl_ml.objs/native/virt.{cmx,o}
ocamlopt .ml.eobjs/native/dune__exe__Ml.{cmx,o}
ocamlopt impl_ml/impl_ml.{a,cmxa}
ocamlopt ml.exe
Hello from ml

Melange can't produce a `.cmj` solely from a virtual module `.cmi`, because it
needs to consult the `.cmj` files of dependencies to know where the require
call should be emitted
$ dune build @melange --display=short
ocamldep impl_melange/.impl_melange.objs/virt.impl.d
melc vlib/.vlib.objs/melange/virt.{cmi,cmti}
melc vlib/.vlib.objs/melange/vlib_impl.{cmi,cmj,cmt} (exit 2)
File "vlib/vlib_impl.ml", line 1:
Error: Virt not found, it means either the module does not exist or it is a namespace
[1]
$ output=_build/default/output/mel.js
$ test -f "$output" && node "$output"
[1]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(library
(name vlib)
(wrapped false)
(modes :standard melange)
(virtual_modules virt))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let t = Vlib_impl.hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
val t : string
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let hello = "Hello from " ^ Virt.t

0 comments on commit b21df14

Please sign in to comment.