Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only build native executables by default #2851

Merged
1 commit merged into from Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@
`homepage`, and `documentation` of `dune-project` can now be overriden on a
per-package basis. (#2774, @nojb)

- Change the default `modes` field of executables to `(mode exe)`. If
one wants to build a bytecode program, it now needs to be explicitly
requested via `(modes byte exe)`. (#2851, @diml)

1.11.4 (09/10/2019)
-------------------

Expand Down
16 changes: 9 additions & 7 deletions doc/dune-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,14 @@ format of executable stanzas is as follows:
<optional-fields>)

``<name>`` is a module name that contains the main entry point of the
executable. There can be additional modules in the current directory, you only
need to specify the entry point. Given an ``executable`` stanza with ``(name
<name>)``, dune will know how to build ``<name>.exe``, ``<name>.bc`` and
``<name>.bc.js``. ``<name>.exe`` is a native code executable, ``<name>.bc`` is a
bytecode executable which requires ``ocamlrun`` to run and ``<name>.bc.js`` is a
JavaScript generated using js_of_ocaml.
executable. There can be additional modules in the current directory,
you only need to specify the entry point. Given an ``executable``
stanza with ``(name <name>)``, dune will know how to build
``<name>.exe``. If requested, it will also know how to build
``<name>.bc`` and ``<name>.bc.js``. ``<name>.exe`` is a native code
executable, ``<name>.bc`` is a bytecode executable which requires
``ocamlrun`` to run and ``<name>.bc.js`` is a JavaScript generated
using js_of_ocaml.

Note that in case native compilation is not available, ``<name>.exe``
will in fact be a custom byte-code executable. Custom in the sense of
Expand Down Expand Up @@ -615,7 +617,7 @@ Executables can also be linked as object or shared object files. See
...)`` field of `library`_

- ``(modes (<modes>))`` sets the `linking modes`_. The default is
``(byte exe)``
``(exe)``. Before 2.0, it used to be ``(byte exe)``.

- ``(preprocess <preprocess-spec>)`` is the same as the ``(preprocess ...)``
field of `library`_
Expand Down
17 changes: 13 additions & 4 deletions src/dune/dune_file.ml
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,8 @@ module Mode_conf = struct
in
repeat decode >>| of_list

let default loc = of_list [ (Byte, Inherited); (Best, Requested loc) ]
let default loc : t =
{ empty with byte = Some Inherited; best = Some (Requested loc) }

module Details = struct
type t = Kind.t option
Expand Down Expand Up @@ -1460,7 +1461,13 @@ module Executables = struct
else
t

let default = of_list [ byte; exe ]
let default_for_exes ~version =
if version < (2, 0) then
of_list [ byte; exe ]
else
singleton exe

let default_for_tests = of_list [ byte; exe ]

let best_install_mode t = List.find ~f:(mem t) installable_modes
end
Expand Down Expand Up @@ -1489,14 +1496,16 @@ module Executables = struct
Dune_project.Extension.register syntax (return ((), [])) Dyn.Encoder.unit

let common =
let* dune_version = Dune_lang.Syntax.get_exn Stanza.syntax in
let+ buildable = Buildable.decode ~in_library:false ~allow_re_export:false
and+ (_ : bool) =
field "link_executables" ~default:true
(Dune_lang.Syntax.deleted_in Stanza.syntax (1, 0) >>> bool)
and+ link_deps = field "link_deps" (repeat Dep_conf.decode) ~default:[]
and+ link_flags = Ordered_set_lang.Unexpanded.field "link_flags"
and+ modes =
field "modes" Link_mode.Set.decode ~default:Link_mode.Set.default
field "modes" Link_mode.Set.decode
~default:(Link_mode.Set.default_for_exes ~version:dune_version)
and+ optional =
field_b "optional" ~check:(Dune_lang.Syntax.since Stanza.syntax (2, 0))
and+ variants = variants_field
Expand Down Expand Up @@ -2031,7 +2040,7 @@ module Tests = struct
and+ locks = field "locks" (repeat String_with_vars.decode) ~default:[]
and+ modes =
field "modes" Executables.Link_mode.Set.decode
~default:Executables.Link_mode.Set.default
~default:Executables.Link_mode.Set.default_for_tests
and+ deps =
field "deps" (Bindings.decode Dep_conf.decode) ~default:Bindings.empty
and+ enabled_if = enabled_if ~since:(Some (1, 4))
Expand Down
3 changes: 0 additions & 3 deletions src/dune/dune_file.mli
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,6 @@ module Mode_conf : sig

val decode : t Dune_lang.Decoder.t

(** Byte inherited, Best is requested *)
val default : Loc.t -> t

module Details : sig
type t = Kind.t option
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(executable
(name print_version)
(modes exe byte)
(libraries build_info)
)
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/byte-code-only/bin/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
(executable
(name toto)
(modes exe byte)
(public_name toto))
6 changes: 4 additions & 2 deletions test/blackbox-tests/test-cases/exes-with-c/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
$ cat > err/dune << EOF
> (executable
> (name foo)
> (modes exe byte)
> (foreign_stubs (language c) (names stubs)))
> EOF
$ dune build --root err @all
Entering directory 'err'
Info: Creating file dune-project with this contents:
| (lang dune 2.0)
File "dune", line 1, characters 0-68:
File "dune", line 1, characters 0-86:
1 | (executable
2 | (name foo)
3 | (foreign_stubs (language c) (names stubs)))
3 | (modes exe byte)
4 | (foreign_stubs (language c) (names stubs)))
Error: Pure bytecode executables cannot contain foreign stubs.
Hint: If you only need to build a native executable use "(modes exe)".
[1]
11 changes: 7 additions & 4 deletions test/blackbox-tests/test-cases/foreign-library/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Testsuite for the (foreign_library ...) stanza.
$ cat >dune <<EOF
> (executable
> (name main)
> (modes exe byte)
> (libraries calc)
> (modules main))
> EOF
Expand Down Expand Up @@ -398,6 +399,7 @@ Testsuite for the (foreign_library ...) stanza.
$ cat >dune <<EOF
> (executable
> (name main)
> (modes exe byte)
> (libraries calc)
> (foreign_archives lib/day)
> (modules main))
Expand All @@ -414,12 +416,13 @@ Testsuite for the (foreign_library ...) stanza.
> EOF

$ ./sdune build
File "dune", line 1, characters 0-87:
File "dune", line 1, characters 0-105:
1 | (executable
2 | (name main)
3 | (libraries calc)
4 | (foreign_archives lib/day)
5 | (modules main))
3 | (modes exe byte)
4 | (libraries calc)
5 | (foreign_archives lib/day)
6 | (modules main))
Error: Pure bytecode executables cannot contain foreign archives.
Hint: If you only need to build a native executable use "(modes exe)".
[1]
Expand Down
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/foreign-stubs/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ Testsuite for the (foreign_stubs ...) field.
> (action (run %{ocaml-config:c_compiler} -shared -o %{targets} %{deps})))
> (executable
> (name main)
> (modes exe byte)
> (libraries quad)
> (modules main))
> EOF
Expand Down Expand Up @@ -307,6 +308,7 @@ Testsuite for the (foreign_stubs ...) field.
> (action (run %{ocaml-config:c_compiler} -shared -o %{targets} %{deps})))
> (executable
> (name main)
> (modes exe byte)
> (libraries quad)
> (modules main))
> EOF
Expand Down Expand Up @@ -371,6 +373,7 @@ Testsuite for the (foreign_stubs ...) field.
> (action (run %{ocaml-config:c_compiler} -shared -o %{targets} %{deps})))
> (executable
> (name main)
> (modes exe byte)
> (libraries quad)
> (modules main))
> EOF
Expand Down