dune icon indicating copy to clipboard operation
dune copied to clipboard

Doc for building byte code incorrect

Open MSoegtropIMC opened this issue 1 year ago • 2 comments

As far as I can tell the documentation here:

https://dune.readthedocs.io/en/stable/quick-start.html#building-a-hello-world-program-in-bytecode

for building byte code executables is incorrect.

What does work for me is to add the (modes byte exe) stanza and run dune build. This does build both, the native and the byte code executable.

What does not work is running dune build foo.bc as suggested in the documentation (after adding the same stanza). I get an error

Error: Don't know how to build foo.bc

Specifications

  • Version of dune 3.15.3:
  • Operating system MacOS Sonoma:

MSoegtropIMC avatar Aug 02 '24 13:08 MSoegtropIMC

I cannot reproduce. It seems to work for me:

nojebar@PERVERSESHEAF:~/tmp/byte$ opam exec -- dune --version
3.16.0
nojebar@PERVERSESHEAF:~/tmp/byte$ cat dune
;; This declares the hello_world executable implemented by hello_world.ml
;; to be build as native (.exe) or bytecode (.bc) version.
(executable
 (name hello_world)
 (modes byte exe))
nojebar@PERVERSESHEAF:~/tmp/byte$ opam exec -- dune build --verbose hello_world.bc
Shared cache: disabled
Shared cache location: /home/nojebar/.cache/dune/db
Workspace root: /home/nojebar/tmp/byte
Auto-detected concurrency: 12
Dune context:
 { name = "default"
 ; kind = "default"
 ; profile = Dev
 ; merlin = true
 ; fdo_target_exe = None
 ; build_dir = In_build_dir "default"
 ; instrument_with = []
 }
Actual targets:
- _build/default/hello_world.bc
Running[1]: (cd _build/default && /home/nojebar/.opam/4.14.2/bin/ocamldep.opt -modules -impl hello_world.ml) > _build/default/.hello_world.eobjs/dune__exe__Hello_world.impl.d
Running[2]: (cd _build/default && /home/nojebar/.opam/4.14.2/bin/ocamlc.opt -w @[email protected]@30..39@[email protected]@[email protected] -strict-sequence -strict-formats -short-paths -keep-locs -w -49 -nopervasives -nostdlib -g -bin-annot -I .hello_world.eobjs/byte -no-alias-deps -opaque -o .hello_world.eobjs/byte/dune__exe.cmo -c -impl .hello_world.eobjs/dune__exe.ml-gen)
Running[3]: (cd _build/default && /home/nojebar/.opam/4.14.2/bin/ocamldep.opt -modules -intf hello_world.mli) > _build/default/.hello_world.eobjs/dune__exe__Hello_world.intf.d
Running[4]: (cd _build/default && /home/nojebar/.opam/4.14.2/bin/ocamlc.opt -w @[email protected]@30..39@[email protected]@[email protected] -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I .hello_world.eobjs/byte -no-alias-deps -opaque -open Dune__exe -o .hello_world.eobjs/byte/dune__exe__Hello_world.cmi -c -intf hello_world.mli)
Running[5]: (cd _build/default && /home/nojebar/.opam/4.14.2/bin/ocamlc.opt -w @[email protected]@30..39@[email protected]@[email protected] -strict-sequence -strict-formats -short-paths -keep-locs -g -bin-annot -I .hello_world.eobjs/byte -intf-suffix .ml -no-alias-deps -opaque -open Dune__exe -o .hello_world.eobjs/byte/dune__exe__Hello_world.cmo -c -impl hello_world.ml)
Running[6]: (cd _build/default && /home/nojebar/.opam/4.14.2/bin/ocamlc.opt -w @[email protected]@30..39@[email protected]@[email protected] -strict-sequence -strict-formats -short-paths -keep-locs -g -o hello_world.bc .hello_world.eobjs/byte/dune__exe.cmo .hello_world.eobjs/byte/dune__exe__Hello_world.cmo)
nojebar@PERVERSESHEAF:~/tmp/byte$ ls _build/default/
hello_world.bc  hello_world.ml  hello_world.mli
nojebar@PERVERSESHEAF:~/tmp/byte$

nojb avatar Aug 05 '24 06:08 nojb

The confusion comes (for me as a dune beginner) from how to specify what to build. Here is an example:

  • dune init project my_project add the (modes byte exe) stanza to bin/dune
  • dune build bin -> OK, builds main.bc and main.exe
  • what does not work is dune build bin.bc dune build main.bc
  • what does work is dune build bin/main.bc

In the default setup created with dune init project my_project the "exe" project has more or less 3 names, "bin", "main" and "my_project". In my setup I name these all the same, say "my_prog" but then one looses touch with what one specifies on the dune command line - folder names, project names, exe names, ... I assumed that what I give to dune build is a project name, not a folder or file name - since i name all the same it is hard to tell. I did read the manual btw. a longer time back, but forgot until I came over the .bc issue.

I think it would help to add a line in the manual stating that usually one gives folder names when calling dune build (is this so?) while when building a byte code exe one gives the relative path of the exe with bc extension.

MSoegtropIMC avatar Aug 05 '24 08:08 MSoegtropIMC