(executable
 (name main)
 (modules main)
 (libraries dynlink js_of_ocaml-compiler.dynlink)
 (modes byte))

(rule
 (target main.js)
 (deps plugin.cmo export)
 (action
  (run
   %{bin:js_of_ocaml}
   --dynlink
   --export
   export
   --pretty
   -w
   no-missing-effects-backend
   -o
   %{target}
   %{dep:main.bc})))

(rule
 (target plugin.cmo)
 (action
  (run %{bin:ocamlc} -c %{dep:./plugin.ml})))

; Dynlink loads bytecode plugins via CommonJS-style relative-path
; require, which the QuickJS shim does not implement.

(rule
 (target main.out)
 (enabled_if
  (<> %{profile} quickjs))
 (deps plugin.cmo)
 (action
  (with-outputs-to
   %{target}
   (run %{bin:node} %{dep:./main.js}))))

(rule
 (alias runtest-js)
 (enabled_if
  (<> %{profile} quickjs))
 (action
  (diff main.out.expected main.out)))
