On Sat, Jun 1, 2019 at 9:00 AM Kenichi Asai <asai@is.ocha.ac.jp> wrote:
I could.  In addition to adding myFac to the argument of
jsoo_listunits:

> (action (run jsoo_listunits -o %{targets} stdlib myFac))

I inserted myFac as one of the libraries:

(executables
  (names eval)
  (libraries
    myFac
    js_of_ocaml-compiler
    js_of_ocaml-toplevel)
  (link_flags (:standard -linkall))
  (preprocess (pps js_of_ocaml-ppx)))

and added the path to the cmi file of myFac library to the argument
of js_of_ocaml.

-I /home/asai/.opam/ocaml-base-compiler.4.04.0/lib/myFac/ 

(I wonder if I always have to write this path.  Maybe it could be
automatically searched (as it is an opam library) or there is a
better way to write it rather than writing the absolute path.)

I would expect the path to not be necessary when passing a library name to jsoo_listunits
 

> As a related question, is there a document I can study that describes:
> - what jsoo_listunits does, and
> - what the --export option (and other options) of js_of_ocaml does? 

I imagine that:

- executables have to contain libraries to be used in the toplevel.
- The --export option exports to the toplevel those modules that are
  required in the toplevel.
- export.txt specifies which modules to be exported.

Correct me if I am wrong.  I still welcome any documents to study.

The set of module one want to expose in a toplevel is different from the set of module needed to build the toplevel.
`--export` is used to tell jsoo what module should be exported. Only module linked in the toplevel can be exported.

jsoo_listunits is a small helper to build that list of module from library names.
In short, what it does is: lookup {cma,cmo}s for the given libraries (using findlib) and build the list of module for theses libraries.

I encourage you to open issues on github for theses questions.


Sincerely,

--
Kenichi Asai


On Thu, May 30, 2019 at 11:19:33PM +0900,
 Kenichi Asai wrote:

> Thank you for the e-mail.  It goes great.  Going one step further, can
> I do the same if I install fac as an opam library?  Suppose I packaged
> fac.ml as a library called myFac and installed fac.cma and fac.cmi via
> opam.  Using:
>
> (action (run jsoo_listunits -o %{targets} stdlib myFac))
>
> I could compile it but I got the "Unbound module Fac" error when I
> open index.html.  Is listing myFac in the above line not enough?
>
> As a related question, is there a document I can study that describes:
> - what jsoo_listunits does, and
> - what the --export option (and other options) of js_of_ocaml does?
>
> --
> Kenichi Asai
>
>
> On Tue, May 28, 2019 at 08:41:01AM +0800,
>  hugo wrote:
>
> > You need to tell js_of_ocaml the list of cmi that you want to export.
> > [jsoo_listunits] can compute the list of cmi from a findlib library.
> > Because fac is not installed, you'll need to be explicit.
> > There might be some better wait to integrate with dune but the following
> > should change should do what you want.
> >
> > (rule
> >  (targets export.txt)
> >  (deps eval.bc fac/fac.cma)
> >  (action (run jsoo_listunits -o %{targets} stdlib fac/.fac.objs/byte/fac.cmi)))
> >
> > H
> >
> >
> > On Sun, May 26, 2019 at 2:27 PM Kenichi Asai <asai@is.ocha.ac.jp> wrote:
> >
> > > I want to create a web page where I can execute an OCaml expression
> > > that mentions a prebuilt user-defined library.  I find the following
> > > example in the js_of_ocaml/toplevel repository:
> > >
> > > https://github.com/ocsigen/js_of_ocaml/tree/master/toplevel/examples/eval
> > >
> > > Can I extend this example so that the toplevel is compiled with a
> > > user-defined library?  The attached program contains the following
> > > where the first three files are copied from the example in the
> > > js_of_ocaml/toplevel repository.
> > >
> > > toplevel/ -- dune
> > >           -- eval.ml
> > >           -- index.html
> > >           -- fac/ -- dune
> > >                   -- fac.ml
> > >
> > > I intend that fac.ml is compiled as a library and I want to use it in
> > > the toplevel.  I added "fac" in the libraries stanza of the toplevel
> > > dune file (as in the attached file):
> > >
> > > (executables
> > >   (names eval)
> > >   (libraries
> > >     fac
> > >     js_of_ocaml-compiler
> > >     js_of_ocaml-toplevel)
> > >   (link_flags (:standard -linkall))
> > >   (preprocess (pps js_of_ocaml-ppx)))
> > >
> > > Naturally, fac.ml is compiled and I can use it in the eval.ml, but it
> > > is not visible from the toplevel.  I included the following part in
> > > the index.html (as in the attached file):
> > >
> > > <script type="text/ocaml" stdout="script3" stderr="script3">
> > >   Fac.go 3;;
> > > </script>
> > > <div id="script3"> </div>
> > >
> > > but the output says:
> > >
> > > File "/dev/fake_stdin", line 2, characters 6-12:
> > > Error: Unbound module Fac
> > >
> > > Thank you in advance.
> > >
> > > --
> > > Kenichi Asai