caml-list - the Caml user's mailing list
 help / Atom feed
* [Caml-list] How can I use a library in a toplevel created by js_of_ocaml?
@ 2019-05-26  6:27 Kenichi Asai
  2019-05-28  0:41 ` hugo
  0 siblings, 1 reply; 9+ messages in thread
From: Kenichi Asai @ 2019-05-26  6:27 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1391 bytes --]

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

[-- Attachment #2: toplevel.tar.gz --]
[-- Type: application/x-tar-gz, Size: 2149 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] How can I use a library in a toplevel created by js_of_ocaml?
@ 2019-05-27 18:35 Quaker Quickoats
  2019-05-29  0:40 ` Kenichi Asai
  0 siblings, 1 reply; 9+ messages in thread
From: Quaker Quickoats @ 2019-05-27 18:35 UTC (permalink / raw)
  To: asai; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 3536 bytes --]

Looking to solve your problem in 2-toplevel.tar.gz code, I've proceeded to
notice that out of all the js_of_ocaml libraries installed here, there is
missing js_of_ocaml-toplevel -- here is what happened when I try to
download and install it with OPAM (2.0.4~):

~/Downloads/p/toplevel $ opam install js_of_ocaml-toplevel
The following actions will be performed:
  ∗ install js_of_ocaml-toplevel 3.4.0

<><> Gathering sources
><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[js_of_ocaml-toplevel.3.4.0] found in cache

<><> Processing actions
<><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] The compilation of js_of_ocaml-toplevel failed at
"/home/user/.opam/opam-init/hooks/sandbox.sh build dune build -p
js_of_ocaml-toplevel -j
        1".

#=== ERROR while compiling js_of_ocaml-toplevel.3.4.0
=========================#
# context              2.0.4 | linux/x86_64 | ocaml-base-compiler.4.07.1 |
https://opam.ocaml.org#a7ba7031
# path
~/.opam/default/.opam-switch/build/js_of_ocaml-toplevel.3.4.0
# command              ~/.opam/opam-init/hooks/sandbox.sh build dune build
-p js_of_ocaml-toplevel -j 1
# exit-code            1
# env-file             ~/.opam/log/js_of_ocaml-toplevel-3670-05296d.env
# output-file          ~/.opam/log/js_of_ocaml-toplevel-3670-05296d.out
### output ###
# Error: Unbound module Js_of_ocaml_compiler.Stdlib
# [...]
# (cd _build/default && /home/user/.opam/default/bin/ocamlc.opt -w -40 -g
-bin-annot -I toplevel/lib/.js_of_ocaml_toplevel.objs/byte -I
/home/user/.opam/default/lib/biniou -I /home/user/.opam/default/lib/bytes
-I /home/user/.opam/default/lib/easy-format -I
/home/user/.opam/default/lib/js_of_ocaml -I
/home/user/.opam/default/lib/js_of_ocaml-compiler -I
/home/user/.opam/default/lib/[...]
# File "toplevel/lib/jsooTopPpx.ml", line 20, characters 5-32:
# Error: Unbound module Js_of_ocaml_compiler.Stdlib
#       ocamlc
toplevel/lib/.js_of_ocaml_toplevel.objs/byte/js_of_ocaml_toplevel__JsooTop.{cmo,cmt}
(exit 2)
# (cd _build/default && /home/user/.opam/default/bin/ocamlc.opt -w -40 -g
-bin-annot -I toplevel/lib/.js_of_ocaml_toplevel.objs/byte -I
/home/user/.opam/default/lib/biniou -I /home/user/.opam/default/lib/bytes
-I /home/user/.opam/default/lib/easy-format -I
/home/user/.opam/default/lib/js_of_ocaml -I
/home/user/.opam/default/lib/js_of_ocaml-compiler -I
/home/user/.opam/default/lib/[...]
# File "toplevel/lib/jsooTop.ml", line 22, characters 5-32:
# Error: Unbound module Js_of_ocaml_compiler.Stdlib
#     ocamlopt
toplevel/lib/.js_of_ocaml_toplevel.objs/native/js_of_ocaml_toplevel__JsooTopPpx.{cmx,o}
(exit 2)
# (cd _build/default && /home/user/.opam/default/bin/ocamlopt.opt -w -40 -g
-I toplevel/lib/.js_of_ocaml_toplevel.objs/byte -I
toplevel/lib/.js_of_ocaml_toplevel.objs/native -I
/home/user/.opam/default/lib/biniou -I /home/user/.opam/default/lib/bytes
-I /home/user/.opam/default/lib/easy-format -I
/home/user/.opam/default/lib/js_of_ocaml -I
/home/user/.opam/default/lib/js_of_ocaml-co[...]
# File "toplevel/lib/jsooTopPpx.ml", line 20, characters 5-32:
# Error: Unbound module Js_of_ocaml_compiler.Stdlib



<><> Error report
<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
┌─ The following actions failed
│ λ build js_of_ocaml-toplevel 3.4.0
└─
╶─ No changes have been performed
~/Downloads/p/toplevel $ opam install js_of_ocaml-compiler
[NOTE] Package js_of_ocaml-compiler is already installed (current version
is 3.3.0).

[-- Attachment #2: Type: text/html, Size: 4353 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] How can I use a library in a toplevel created by js_of_ocaml?
  2019-05-26  6:27 [Caml-list] How can I use a library in a toplevel created by js_of_ocaml? Kenichi Asai
@ 2019-05-28  0:41 ` hugo
  2019-05-30 14:20   ` Kenichi Asai
  0 siblings, 1 reply; 9+ messages in thread
From: hugo @ 2019-05-28  0:41 UTC (permalink / raw)
  To: Kenichi Asai; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 2006 bytes --]

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
>

[-- Attachment #2: Type: text/html, Size: 3205 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] How can I use a library in a toplevel created by js_of_ocaml?
  2019-05-27 18:35 Quaker Quickoats
@ 2019-05-29  0:40 ` Kenichi Asai
  2019-05-29 20:27   ` Quaker Quickoats
  0 siblings, 1 reply; 9+ messages in thread
From: Kenichi Asai @ 2019-05-29  0:40 UTC (permalink / raw)
  To: Quaker Quickoats; +Cc: caml-list

Thanks for the e-mail.  Yes, you need js_of_ocaml-toplevel and some
other js_of_ocaml packages.  I also installed them with opam 2.0.4:

> js_of_ocaml             3.4.0
> js_of_ocaml-compiler    3.4.0
> js_of_ocaml-ppx         3.4.0
> js_of_ocaml-toplevel    3.4.0

On MacOS, I had no problem installing them...

-- 
Kenichi Asai

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] How can I use a library in a toplevel created by js_of_ocaml?
  2019-05-29  0:40 ` Kenichi Asai
@ 2019-05-29 20:27   ` Quaker Quickoats
  2019-05-30  0:45     ` hugo
  0 siblings, 1 reply; 9+ messages in thread
From: Quaker Quickoats @ 2019-05-29 20:27 UTC (permalink / raw)
  To: Kenichi Asai, caml-list

[-- Attachment #1: Type: text/plain, Size: 526 bytes --]

okay, not sure, still cannot install js_of_ocaml-toplevel with the same
error after opam full update

On Tue, 28 May 2019 at 20:40, Kenichi Asai <asai@is.ocha.ac.jp> wrote:

> Thanks for the e-mail.  Yes, you need js_of_ocaml-toplevel and some
> other js_of_ocaml packages.  I also installed them with opam 2.0.4:
>
> > js_of_ocaml             3.4.0
> > js_of_ocaml-compiler    3.4.0
> > js_of_ocaml-ppx         3.4.0
> > js_of_ocaml-toplevel    3.4.0
>
> On MacOS, I had no problem installing them...
>
> --
> Kenichi Asai
>

[-- Attachment #2: Type: text/html, Size: 876 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] How can I use a library in a toplevel created by js_of_ocaml?
  2019-05-29 20:27   ` Quaker Quickoats
@ 2019-05-30  0:45     ` hugo
  0 siblings, 0 replies; 9+ messages in thread
From: hugo @ 2019-05-30  0:45 UTC (permalink / raw)
  To: Quaker Quickoats; +Cc: Kenichi Asai, caml-list

[-- Attachment #1: Type: text/plain, Size: 896 bytes --]

We are missing some constraints in opam.

js_of_ocaml-toplevel.3.4.0 requires js_of_ocaml-compiler.3.4.0 but you have
version 3.3.0 installed.

> [NOTE] Package js_of_ocaml-compiler is already installed (current version
is 3.3.0).

try to upgrade your packages

On Thu, May 30, 2019 at 4:28 AM Quaker Quickoats <quakerquickoats@gmail.com>
wrote:

> okay, not sure, still cannot install js_of_ocaml-toplevel with the same
> error after opam full update
>
> On Tue, 28 May 2019 at 20:40, Kenichi Asai <asai@is.ocha.ac.jp> wrote:
>
>> Thanks for the e-mail.  Yes, you need js_of_ocaml-toplevel and some
>> other js_of_ocaml packages.  I also installed them with opam 2.0.4:
>>
>> > js_of_ocaml             3.4.0
>> > js_of_ocaml-compiler    3.4.0
>> > js_of_ocaml-ppx         3.4.0
>> > js_of_ocaml-toplevel    3.4.0
>>
>> On MacOS, I had no problem installing them...
>>
>> --
>> Kenichi Asai
>>
>

[-- Attachment #2: Type: text/html, Size: 1603 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] How can I use a library in a toplevel created by js_of_ocaml?
  2019-05-28  0:41 ` hugo
@ 2019-05-30 14:20   ` Kenichi Asai
  2019-06-01  1:01     ` Kenichi Asai
  0 siblings, 1 reply; 9+ messages in thread
From: Kenichi Asai @ 2019-05-30 14:20 UTC (permalink / raw)
  To: hugo; +Cc: caml-list

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] How can I use a library in a toplevel created by js_of_ocaml?
  2019-05-30 14:20   ` Kenichi Asai
@ 2019-06-01  1:01     ` Kenichi Asai
  2019-06-06  1:05       ` hugo
  0 siblings, 1 reply; 9+ messages in thread
From: Kenichi Asai @ 2019-06-01  1:01 UTC (permalink / raw)
  To: hugo; +Cc: caml-list

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.)

> 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.

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [Caml-list] How can I use a library in a toplevel created by js_of_ocaml?
  2019-06-01  1:01     ` Kenichi Asai
@ 2019-06-06  1:05       ` hugo
  0 siblings, 0 replies; 9+ messages in thread
From: hugo @ 2019-06-06  1:05 UTC (permalink / raw)
  To: Kenichi Asai; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 5221 bytes --]

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
<https://github.com/ocsigen/js_of_ocaml/issues/new> 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
>

[-- Attachment #2: Type: text/html, Size: 7947 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, back to index

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-26  6:27 [Caml-list] How can I use a library in a toplevel created by js_of_ocaml? Kenichi Asai
2019-05-28  0:41 ` hugo
2019-05-30 14:20   ` Kenichi Asai
2019-06-01  1:01     ` Kenichi Asai
2019-06-06  1:05       ` hugo
2019-05-27 18:35 Quaker Quickoats
2019-05-29  0:40 ` Kenichi Asai
2019-05-29 20:27   ` Quaker Quickoats
2019-05-30  0:45     ` hugo

caml-list - the Caml user's mailing list

Archives are clonable: git clone --mirror https://inbox.ocaml.org/caml-list

AGPL code for this site: git clone https://public-inbox.org/ public-inbox