Conversation
3c35724 to
8122af8
Compare
doc/wasmoo.rst
Outdated
| .. code:: console | ||
|
|
||
| $ dune build ./foo.bc.wasm.js | ||
| $ node _build/default/foo.bc.wasm.js |
There was a problem hiding this comment.
Why do I need to specify the submodes here? Dune could find out what to build for this wasm.js target on its own, isn't it?
There was a problem hiding this comment.
The documentation has not been updated. That should be the following above:
(executable (name foo) (modes wasm))
But yes, you can just use dune build.
Not that this was just copied from the Js_of_ocaml part of the doc:
Lines 38 to 44 in b409963
83731d5 to
ec321a5
Compare
hhugo
left a comment
There was a problem hiding this comment.
From a quick look, I think I prefer this approach better.
It seems you have not implemented the generation of a bc.js when js_of_ocaml is disabled, do you still want it ?
src/dune_rules/exe_rules.ml
Outdated
| Js_of_ocaml.Mode.Set.inter jsoo_enabled_modes jsoo_is_whole_program | ||
| in | ||
| let bytecode_exe_needed = | ||
| L.Map.foldi |
src/dune_rules/inline_tests.ml
Outdated
| | Wasm -> Exe.Linkage.wasm | ||
| in | ||
| if Js_of_ocaml.Mode.Pair.select ~mode:jsoo_mode jsoo_is_whole_program | ||
| then [ Exe.Linkage.byte_for_jsoo; linkage ] |
There was a problem hiding this comment.
Don't we have an issue if byte_for_jsoo appears twice (once for js and once for wasm)
src/dune_rules/jsoo/js_of_ocaml.ml
Outdated
| | JS | ||
| | Wasm | ||
|
|
||
| let equal = Poly.equal |
There was a problem hiding this comment.
| let equal = Poly.equal | |
| let equal (a : t) b = Poly.equal a b |
src/dune_rules/jsoo/js_of_ocaml.ml
Outdated
| let union = Pair.map2 ~f:( || ) | ||
| let is_empty (x : t) = not (x.js || x.wasm) | ||
|
|
||
| let to_list (x : t) = |
There was a problem hiding this comment.
| let to_list (x : t) = | |
| let to_list ({ wasm; js}: t) = |
src/dune_rules/jsoo/js_of_ocaml.ml
Outdated
| match mode with | ||
| | Mode.JS -> "js" |
There was a problem hiding this comment.
| match mode with | |
| | Mode.JS -> "js" | |
| match (mode : Mode.t) with | |
| | JS -> "js" |
src/dune_rules/jsoo/js_of_ocaml.ml
Outdated
| ; sourcemap = None | ||
| ; runtest_alias = None | ||
| ; flags = Flags.default ~profile | ||
| ; enabled_if = Some Blang.true_ |
There was a problem hiding this comment.
This is so that we don't need a case for None there:
dune/src/dune_rules/jsoo/jsoo_rules.ml
Lines 18 to 20 in ec321a5
dune/src/dune_rules/jsoo/jsoo_rules.ml
Lines 603 to 605 in ec321a5
There was a problem hiding this comment.
I think it would be either to read if there were less hidden invariants. What do you think of the following ?
diff --git a/src/dune_rules/jsoo/js_of_ocaml.ml b/src/dune_rules/jsoo/js_of_ocaml.ml
index dc2fad30a..2c8c8e185 100644
--- a/src/dune_rules/jsoo/js_of_ocaml.ml
+++ b/src/dune_rules/jsoo/js_of_ocaml.ml
@@ -358,7 +358,7 @@ module Env = struct
; sourcemap = None
; runtest_alias = None
; flags = Flags.default ~profile
- ; enabled_if = Some Blang.true_
+ ; enabled_if = None
}
;;
end
diff --git a/src/dune_rules/jsoo/jsoo_rules.ml b/src/dune_rules/jsoo/jsoo_rules.ml
index b10ac8f27..98b29afeb 100644
--- a/src/dune_rules/jsoo/jsoo_rules.ml
+++ b/src/dune_rules/jsoo/jsoo_rules.ml
@@ -12,18 +12,16 @@ let compute_env ~mode =
let local = Js_of_ocaml.Mode.select ~mode local.js_of_ocaml local.wasm_of_ocaml in
let* parent = parent in
let+ enabled_if =
- match local.enabled_if with
- | None ->
- Memo.return
- (match parent.enabled_if with
- | Some (Const default) -> default
- | _ -> assert false)
- | Some enabled_if -> Expander.eval_blang expander enabled_if
+ match Option.first_some local.enabled_if parent.enabled_if with
+ | Some enabled_if ->
+ let+ v = Expander.eval_blang expander enabled_if in
+ Some (Blang.Const v)
+ | None -> Memo.return None
in
{ Js_of_ocaml.Env.compilation_mode =
Option.first_some local.compilation_mode parent.compilation_mode
; sourcemap = Option.first_some local.sourcemap parent.sourcemap
- ; enabled_if = Some (Const enabled_if)
+ ; enabled_if
; runtest_alias = Option.first_some local.runtest_alias parent.runtest_alias
; flags =
Js_of_ocaml.Flags.make
@@ -601,8 +599,8 @@ let jsoo_enabled
| None ->
let* js_of_ocaml = jsoo_env ~dir ~mode in
(match js_of_ocaml.enabled_if with
- | Some (Const default) -> Memo.return default
- | _ -> assert false)
+ | Some enabled_if -> eval enabled_if
+ | None -> Memo.return true)
;;
let jsoo_enabled_modes ~expander ~dir ~in_context =| | None -> js_of_ocaml_sourcemap sctx ~dir ~mode | ||
| | Some x -> Memo.return x | ||
| in | ||
| let runtime_files = javascript_files @ wasm_files in |
There was a problem hiding this comment.
This looks weird. Is it the case that wasm_files is always empty when mode is js ?
There was a problem hiding this comment.
Yes, that's the case:
dune/src/dune_rules/jsoo/js_of_ocaml.ml
Lines 227 to 234 in ec321a5
There was a problem hiding this comment.
Maybe we could add an assertion.
|
@vouillon could you submit a version of ocsigen/js_of_ocaml#1724 using this PR ? |
It does not fit well. For the wasm_of_ocaml test suite, I have switched to using dune test stanzas and only had to add a few rules to copy a bc.wasm.js file to bc.js. |
9f3eb50 to
4a389d5
Compare
|
This looks good, I left one last suggestion. The documentation still needs to be updated |
04c28d2 to
a837c52
Compare
Signed-off-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
Signed-off-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
Signed-off-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
Signed-off-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
Signed-off-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
Signed-off-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
| ~f:(List.rev_map ~f:(fun f -> Section.Lib, f)) | ||
| (let { Mode.Dict.byte; native } = Lib_info.archives lib in | ||
| let jsoo_files = | ||
| (* A same runtime file can be used both for jsoo and wasmoo *) |
There was a problem hiding this comment.
Does that comment still make sense now that jsoo and wasm options are different ?
There was a problem hiding this comment.
Yes, it still makes sense. In particular, one may want to pass a JavaScript file to wasm_of_ocaml to get some primitive purity information. Or one need to include some JavaScript code both when generating JavaScript and Wasm code. For instance, I have this for the virtual_dom package:
(js_of_ocaml
(javascript_files ../lib/virtualdom.compiled.js ./thunk.js ./hooks.js))
(wasm_of_ocaml
(javascript_files ../lib/virtualdom.compiled.js ./thunk.js ./hooks.js))
src/dune_rules/jsoo/jsoo_rules.ml
Outdated
| let name = Path.basename fn in | ||
| let dir = in_build_dir build_context ~config [ lib_name ] in | ||
| let in_context = | ||
| { Js_of_ocaml.In_context.flags = Js_of_ocaml.Flags.standard |
There was a problem hiding this comment.
Should this be Js_of_ocaml.In_context.default ?
There was a problem hiding this comment.
This is your code...
But yes, that should work.
src/dune_rules/stanzas/buildable.ml
Outdated
| (Js_of_ocaml.In_buildable.decode ~executable ~mode:JS) | ||
| ~default:Js_of_ocaml.In_buildable.default | ||
| and+ wasm_of_ocaml = | ||
| let executable = |
There was a problem hiding this comment.
this could be lifted up and shared with the one inside js_of_ocaml above
I don't know either. We could also let dune complain if one tries to use |
daa107e to
be2bd4a
Compare
Or rather it should complain for |
src/dune_rules/jsoo/js_of_ocaml.ml
Outdated
| "compilation_mode" | ||
| (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> Compilation_mode.decode) | ||
| else return None | ||
| only_in_library |
There was a problem hiding this comment.
This should be only_in_executable
Signed-off-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
734967d to
aea189c
Compare
| ================= | ||
|
|
||
| Dune has full support for building wasm_of_ocaml libraries and executables transparently. | ||
| There's no need to customise or enable anything to compile OCaml |
There was a problem hiding this comment.
Should the documentation mention the external dependencies that are required for the build ?
There was a problem hiding this comment.
I now explicitly point to the github repository above.
hhugo
left a comment
There was a problem hiding this comment.
Approved. One will need to squash commits before merging
Signed-off-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
Signed-off-by: Jérôme Vouillon <jerome.vouillon@gmail.com>
9c5c761 to
f76b05e
Compare
|
I have made another clean-up pass. |
.github/workflows/workflow.yml
Outdated
| with: | ||
| ocaml-compiler: 4.14.x | ||
| opam-pin: false | ||
| opam-depext: false |
There was a problem hiding this comment.
Opam depext is unused in setup-ocaml v3
|
LGTM. Feel free to send the docs in another PR |
CHANGES: ### Fixed - Show the context name for errors happening in non-default contexts. (ocaml/dune#10414, fixes ocaml/dune#10378, @jchavarri) - Correctly declare dependencies of indexes so that they are rebuilt when needed. (ocaml/dune#10623, @voodoos) - Don't depend on coq-stdlib being installed when expanding variables of the `coq.version` family (ocaml/dune#10631, fixes ocaml/dune#10629, @gares) - Error out if no files are found when using `copy_files`. (ocaml/dune#10649, @jchavarri) - Re_export dune-section private library in the dune-site library stanza, in order to avoid failure when generating and building sites modules with implicit_transitive_deps = false. (ocaml/dune#10650, fixes ocaml/dune#9661, @MA0100) - Expect test fixes: support multiple modes and fix dependencies when there is a custom runner (ocaml/dune#10671, @vouillon) - In a `(library)` stanza with `(extra_objects)` and `(foreign_stubs)`, avoid double linking the extra object files in the final executable. (ocaml/dune#10783, fixes ocaml/dune#10785, @nojb) - Map `(re_export)` library dependencies to the `exports` field in `META` files, and vice-versa. This field was proposed in to https://discuss.ocaml.org/t/proposal-a-new-exports-field-in-findlib-meta-files/13947. The field is included in Dune-generated `META` files only when the Dune lang version is >= 3.17. (ocaml/dune#10831, fixes ocaml/dune#10830, @nojb) - Fix staged pps preprocessors on Windows (which were not working at all previously) (ocaml/dune#10869, fixes ocaml/dune#10867, @nojb) - Fix `dune describe` when an executable is disabled with `enabled_if`. (ocaml/dune#10881, fixes ocaml/dune#10779, @moyodiallo) - Fix an issue where C stubs would be rebuilt whenever the stderr of Dune was redirected. (ocaml/dune#10883, fixes ocaml/dune#10882, @nojb) - Format long lists in s-expressions to fill the line instead of formatting them in a vertical way (ocaml/dune#10892, fixes ocaml/dune#10860, @nojb) - Fix the URL opened by the command `dune ocaml doc`. (ocaml/dune#10897, @gridbugs) - Fix the file referred to in the error/warning message displayed due to the dune configuration version not supporting a particular configuration stanza in use. (ocaml/dune#10923, @H-ANSEN) - Fix `enabled_if` when it uses `env` variable. (ocaml/dune#10936, fixes ocaml/dune#10905, @moyodiallo) - Fix exec -w for relative paths with --root argument (ocaml/dune#10982, @gridbugs) - Do not ignore the `(locks ..)` field in the `test` and `tests` stanza (ocaml/dune#11081, @rgrinberg) - Tolerate files without extension when generating merlin rules. (ocaml/dune#11128, @anmonteiro) ### Added - Make Merlin/OCaml-LSP aware of "hidden" dependencies used by `(implicit_transitive_deps false)` via the `-H` compiler flag. (ocaml/dune#10535, @voodoos) - Add support for the -H flag (introduced in OCaml compiler 5.2) in dune (requires lang versions 3.17). This adaptation gives the correct semantics for `(implicit_transitive_deps false)`. (ocaml/dune#10644, fixes ocaml/dune#9333, ocsigen/tyxml#274, ocaml/dune#2733, ocaml/dune#4963, @MA0100) - Add support for specifying Gitlab organization repositories in `source` stanzas (ocaml/dune#10766, fixes ocaml/dune#6723, @H-ANSEN) - New option to control jsoo sourcemap generation in env and executable stanza (ocaml/dune#10777, fixes ocaml/dune#10673, @hhugo) - One can now control jsoo compilation_mode inside an executable stanza (ocaml/dune#10777, fixes ocaml/dune#10673, @hhugo) - Add support for specifying default values of the `authors`, `maintainers`, and `license` stanzas of the `dune-project` file via the dune config file. Default values are set using the `(project_defaults)` stanza (ocaml/dune#10835, @H-ANSEN) - Add names to source tree events in performance traces (ocaml/dune#10884, @jchavarri) - Add `codeberg` as an option for defining project sources in dune-project files. For example, `(source (codeberg user/repo))`. (ocaml/dune#10904, @nlordell) - `dune runtest` can now run individual tests with `dune runtest mytest.t` (ocaml/dune#11041, @Alizter). - Wasm_of_ocaml support (ocaml/dune#11093, @vouillon) - Add a `coqdep_flags` field to the `coq` field of the `env` stanza, and to the `coq.theory` stanza, allowing to configure `coqdep` flags. (ocaml/dune#11094, @rlepigre) ### Changed - Remove all remnants of the experimental `patch-back-source-tree`. (ocaml/dune#10771, @rgrinberg) - Change the preset value for author and maintainer fields in the `dune-project` file to encourage including emails. (ocaml/dune#10848, @punchagan) - Tweak the preset value for tags in the `dune-project` file to hint at topics not having a special meaning. (ocaml/dune#10849, @punchagan) - Change some colors to improve readability in light-mode terminals (ocaml/dune#10890, @gridbugs) - Forward the linkall flag to jsoo in whole program compilation as well (ocaml/dune#10935, @hhugo) - Configurator uses `pkgconf` as pkg-config implementation when available and forwards it the `target` of `ocamlc -config`. (ocaml/dune#10937, @pirbo) - Enable Dune cache by default. Add a new Dune cache setting `enabled-except-user-rules`, which enables the Dune cache, but excludes user-written rules from it. This is a conservative choice that can avoid breaking rules whose dependencies are not correctly specified. This is the current default. (ocaml/dune#10944, ocaml/dune#10710, @nojb, @ElectreAAS) - Do not add `dune` dependency in `dune-project` when creating projects with `dune init proj`. The Dune dependency is implicitely added when generating opam files (ocaml/dune#11129, @Leonidas-from-XIV)
CHANGES: ### Fixed - Show the context name for errors happening in non-default contexts. (ocaml/dune#10414, fixes ocaml/dune#10378, @jchavarri) - Correctly declare dependencies of indexes so that they are rebuilt when needed. (ocaml/dune#10623, @voodoos) - Don't depend on coq-stdlib being installed when expanding variables of the `coq.version` family (ocaml/dune#10631, fixes ocaml/dune#10629, @gares) - Error out if no files are found when using `copy_files`. (ocaml/dune#10649, @jchavarri) - Re_export dune-section private library in the dune-site library stanza, in order to avoid failure when generating and building sites modules with implicit_transitive_deps = false. (ocaml/dune#10650, fixes ocaml/dune#9661, @MA0100) - Expect test fixes: support multiple modes and fix dependencies when there is a custom runner (ocaml/dune#10671, @vouillon) - In a `(library)` stanza with `(extra_objects)` and `(foreign_stubs)`, avoid double linking the extra object files in the final executable. (ocaml/dune#10783, fixes ocaml/dune#10785, @nojb) - Map `(re_export)` library dependencies to the `exports` field in `META` files, and vice-versa. This field was proposed in to https://discuss.ocaml.org/t/proposal-a-new-exports-field-in-findlib-meta-files/13947. The field is included in Dune-generated `META` files only when the Dune lang version is >= 3.17. (ocaml/dune#10831, fixes ocaml/dune#10830, @nojb) - Fix staged pps preprocessors on Windows (which were not working at all previously) (ocaml/dune#10869, fixes ocaml/dune#10867, @nojb) - Fix `dune describe` when an executable is disabled with `enabled_if`. (ocaml/dune#10881, fixes ocaml/dune#10779, @moyodiallo) - Fix an issue where C stubs would be rebuilt whenever the stderr of Dune was redirected. (ocaml/dune#10883, fixes ocaml/dune#10882, @nojb) - Fix the URL opened by the command `dune ocaml doc`. (ocaml/dune#10897, @gridbugs) - Fix the file referred to in the error/warning message displayed due to the dune configuration version not supporting a particular configuration stanza in use. (ocaml/dune#10923, @H-ANSEN) - Fix `enabled_if` when it uses `env` variable. (ocaml/dune#10936, fixes ocaml/dune#10905, @moyodiallo) - Fix exec -w for relative paths with --root argument (ocaml/dune#10982, @gridbugs) - Do not ignore the `(locks ..)` field in the `test` and `tests` stanza (ocaml/dune#11081, @rgrinberg) - Tolerate files without extension when generating merlin rules. (ocaml/dune#11128, @anmonteiro) ### Added - Make Merlin/OCaml-LSP aware of "hidden" dependencies used by `(implicit_transitive_deps false)` via the `-H` compiler flag. (ocaml/dune#10535, @voodoos) - Add support for the -H flag (introduced in OCaml compiler 5.2) in dune (requires lang versions 3.17). This adaptation gives the correct semantics for `(implicit_transitive_deps false)`. (ocaml/dune#10644, fixes ocaml/dune#9333, ocsigen/tyxml#274, ocaml/dune#2733, ocaml/dune#4963, @MA0100) - Add support for specifying Gitlab organization repositories in `source` stanzas (ocaml/dune#10766, fixes ocaml/dune#6723, @H-ANSEN) - New option to control jsoo sourcemap generation in env and executable stanza (ocaml/dune#10777, fixes ocaml/dune#10673, @hhugo) - One can now control jsoo compilation_mode inside an executable stanza (ocaml/dune#10777, fixes ocaml/dune#10673, @hhugo) - Add support for specifying default values of the `authors`, `maintainers`, and `license` stanzas of the `dune-project` file via the dune config file. Default values are set using the `(project_defaults)` stanza (ocaml/dune#10835, @H-ANSEN) - Add names to source tree events in performance traces (ocaml/dune#10884, @jchavarri) - Add `codeberg` as an option for defining project sources in dune-project files. For example, `(source (codeberg user/repo))`. (ocaml/dune#10904, @nlordell) - `dune runtest` can now run individual tests with `dune runtest mytest.t` (ocaml/dune#11041, @Alizter). - Wasm_of_ocaml support (ocaml/dune#11093, @vouillon) - Add a `coqdep_flags` field to the `coq` field of the `env` stanza, and to the `coq.theory` stanza, allowing to configure `coqdep` flags. (ocaml/dune#11094, @rlepigre) ### Changed - Remove all remnants of the experimental `patch-back-source-tree`. (ocaml/dune#10771, @rgrinberg) - Change the preset value for author and maintainer fields in the `dune-project` file to encourage including emails. (ocaml/dune#10848, @punchagan) - Tweak the preset value for tags in the `dune-project` file to hint at topics not having a special meaning. (ocaml/dune#10849, @punchagan) - Change some colors to improve readability in light-mode terminals (ocaml/dune#10890, @gridbugs) - Forward the linkall flag to jsoo in whole program compilation as well (ocaml/dune#10935, @hhugo) - Configurator uses `pkgconf` as pkg-config implementation when available and forwards it the `target` of `ocamlc -config`. (ocaml/dune#10937, @pirbo) - Enable Dune cache by default. Add a new Dune cache setting `enabled-except-user-rules`, which enables the Dune cache, but excludes user-written rules from it. This is a conservative choice that can avoid breaking rules whose dependencies are not correctly specified. This is the current default. (ocaml/dune#10944, ocaml/dune#10710, @nojb, @ElectreAAS) - Do not add `dune` dependency in `dune-project` when creating projects with `dune init proj`. The Dune dependency is implicitely added when generating opam files (ocaml/dune#11129, @Leonidas-from-XIV)
@hhugo @rgrinberg This is an alternative design. What do you think about it?
This adds a
wasmmode. All thejs_of_ocamloptions are duplicated aswasm_of_ocamloptions. There is a(js_of_ocaml (enabled_if <blang expression>))and(wasm_of_ocaml (enabled_if <blang expression>))option inenvandexecutablestanzas to control whether thejsandwasmmodes are enabled.I have not updated the documentation yet.