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

test(melange): add test exercising #7104 #7204

Merged
merged 2 commits into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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