caml-list - the Caml user's mailing list
 help / Atom feed
* [Caml-list] make -> dune: recommended structure
@ 2019-01-13 13:31 Robert Muller
  2019-01-13 14:07 ` Nicolás Ojeda Bär
  0 siblings, 1 reply; 3+ messages in thread
From: Robert Muller @ 2019-01-13 13:31 UTC (permalink / raw)
  To: Ocaml Mailing List

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

Greetings. I have a toy compiler made up of ~20 modules:

ast.mli ast.ml symbol.mli symbol.ml ...

and a top-level in compile.ml. These sources are compiled and linked using
a Makefile which invokes ocamlc. I'll call the resulting compiler
"translate".

At present I have *all* of these files resident in a single src/ directory.
I'm considering converting the build to dune for the semester. What would
the recommended directory structure be and what would the dune file(s?) and
stanzas look like? I assume this is in the middle of dune's wheelhouse but
I wasn't able to find anything on it in the examples or documents. I
assume/hope I don't have to put the modules in a library.
Thank you,
Bob Muller

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list https://inbox.ocaml.org/caml-list
Forum: https://discuss.ocaml.org/
Bug reports: http://caml.inria.fr/bin/caml-bugs

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

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

* Re: [Caml-list] make -> dune: recommended structure
  2019-01-13 13:31 [Caml-list] make -> dune: recommended structure Robert Muller
@ 2019-01-13 14:07 ` Nicolás Ojeda Bär
  2019-01-13 14:22   ` Robert Muller
  0 siblings, 1 reply; 3+ messages in thread
From: Nicolás Ojeda Bär @ 2019-01-13 14:07 UTC (permalink / raw)
  To: Robert Muller; +Cc: Ocaml Mailing List

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

Dear Bob,

Your present directory structure is just fine. A single `dune` file at `src/dune` with the contents

    (executable
     (name compile)
     (public_name translate))

should be enough. Here I am assuming that all modules in `src/` are part of the compiler. If this is not the case you need to specify the modules you want to include as follows:

    (executable
     (name compile)
     (public_name translate)
     (modules compile ast symbol ...))

Note: if you have a file `parser.mly` in your project that needs to be processed with `ocamlyacc` then you need to declare this in its own stanza:

    (ocamlyacc parser)

Similarly an `ocamllex` file `lexer.mll` needs to be declared with

    (ocamllex lexer)

Finally, you need to make sure there is a `<foo>.opam` file at the root of your project. This file can be be empty if you do not actually use `opam` but the name `foo` is used by `dune` to identify the "package" your executable belongs to. Once these files are in place, you can build your project with

    dune build

Best wishes,
Nicolás

On Sun, 13 Jan 2019 at 14:31, Robert Muller <robert.muller2@gmail.com<mailto:robert.muller2@gmail.com>> wrote:
Greetings. I have a toy compiler made up of ~20 modules:

ast.mli ast.ml<http://ast.ml> symbol.mli symbol.ml<http://symbol.ml> ...

and a top-level in compile.ml<http://compile.ml>. These sources are compiled and linked using a Makefile which invokes ocamlc. I'll call the resulting compiler "translate".

At present I have *all* of these files resident in a single src/ directory. I'm considering converting the build to dune for the semester. What would the recommended directory structure be and what would the dune file(s?) and stanzas look like? I assume this is in the middle of dune's wheelhouse but I wasn't able to find anything on it in the examples or documents. I assume/hope I don't have to put the modules in a library.
Thank you,
Bob Muller

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list https://inbox.ocaml.org/caml-list
Forum: https://discuss.ocaml.org/
Bug reports: http://caml.inria.fr/bin/caml-bugs

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

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

* Re: [Caml-list] make -> dune: recommended structure
  2019-01-13 14:07 ` Nicolás Ojeda Bär
@ 2019-01-13 14:22   ` Robert Muller
  0 siblings, 0 replies; 3+ messages in thread
From: Robert Muller @ 2019-01-13 14:22 UTC (permalink / raw)
  To: Nicolás Ojeda Bär; +Cc: Ocaml Mailing List

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

This is fantastic, thank you. I could be wrong but I think my setup is
common enough that it would probably be helpful to have some variation of
your answer as an example in the dune documentation and possibly in the
quick-start guide. I suppose I could submit a PR to
https://github.com/ocaml/dune/tree/master/example.
Thanks again,
Bob


On Sun, Jan 13, 2019 at 9:07 AM Nicolás Ojeda Bär <
nicolas.ojeda.bar@lexifi.com> wrote:

> Dear Bob,
>
> Your present directory structure is just fine. A single `dune` file at
> `src/dune` with the contents
>
>     (executable
>      (name compile)
>      (public_name translate))
>
> should be enough. Here I am assuming that all modules in `src/` are part
> of the compiler. If this is not the case you need to specify the modules
> you want to include as follows:
>
>     (executable
>      (name compile)
>      (public_name translate)
>      (modules compile ast symbol ...))
>
> Note: if you have a file `parser.mly` in your project that needs to be
> processed with `ocamlyacc` then you need to declare this in its own stanza:
>
>     (ocamlyacc parser)
>
> Similarly an `ocamllex` file `lexer.mll` needs to be declared with
>
>     (ocamllex lexer)
>
> Finally, you need to make sure there is a `<foo>.opam` file at the root of
> your project. This file can be be empty if you do not actually use `opam`
> but the name `foo` is used by `dune` to identify the "package" your
> executable belongs to. Once these files are in place, you can build your
> project with
>
>     dune build
>
> Best wishes,
> Nicolás
>
> On Sun, 13 Jan 2019 at 14:31, Robert Muller <robert.muller2@gmail.com>
> wrote:
>
>> Greetings. I have a toy compiler made up of ~20 modules:
>>
>> ast.mli ast.ml symbol.mli symbol.ml ...
>>
>> and a top-level in compile.ml. These sources are compiled and linked
>> using a Makefile which invokes ocamlc. I'll call the resulting compiler
>> "translate".
>>
>> At present I have *all* of these files resident in a single src/
>> directory. I'm considering converting the build to dune for the semester.
>> What would the recommended directory structure be and what would the dune
>> file(s?) and stanzas look like? I assume this is in the middle of dune's
>> wheelhouse but I wasn't able to find anything on it in the examples or
>> documents. I assume/hope I don't have to put the modules in a library.
>> Thank you,
>> Bob Muller
>>
>

-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list https://inbox.ocaml.org/caml-list
Forum: https://discuss.ocaml.org/
Bug reports: http://caml.inria.fr/bin/caml-bugs

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

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-13 13:31 [Caml-list] make -> dune: recommended structure Robert Muller
2019-01-13 14:07 ` Nicolás Ojeda Bär
2019-01-13 14:22   ` Robert Muller

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