diff --git a/doc/reference/dune/executable.rst b/doc/reference/dune/executable.rst index 39111b274294..9fad1969f56a 100644 --- a/doc/reference/dune/executable.rst +++ b/doc/reference/dune/executable.rst @@ -297,7 +297,7 @@ options using ``(wasm_of_ocaml ())``. - ``(wasm_files ())`` to specify ``wasm_of_ocaml`` Wasm runtime files. -For the ``(sourcemap )`` option, source maps are generated when ``>`` is either ``file`` or ``inline``. They are put within the ``.bc.wasm.assets`` directory in both cases. +For the ``(sourcemap )`` option, ```` must be one of ``no`` or ``inline``. Source maps are put within the ``.bc.wasm.assets`` directory. The default values for ``flags``, ``compilation_mode`` and ``sourcemap`` depend on the selected build profile. The build profile ``dev`` (the default) will enable sourcemaps, separate compilation and pretty Wasm output. diff --git a/src/dune_rules/dune_env.ml b/src/dune_rules/dune_env.ml index 7411f9b2d681..b0aeffb4808e 100644 --- a/src/dune_rules/dune_env.ml +++ b/src/dune_rules/dune_env.ml @@ -225,14 +225,14 @@ let js_of_ocaml_field = field "js_of_ocaml" ~default:Js_of_ocaml.Env.empty - (Dune_lang.Syntax.since Stanza.syntax (3, 0) >>> Js_of_ocaml.Env.decode) + (Dune_lang.Syntax.since Stanza.syntax (3, 0) >>> Js_of_ocaml.Env.decode ~mode:JS) ;; let wasm_of_ocaml_field = field "wasm_of_ocaml" ~default:Js_of_ocaml.Env.empty - (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> Js_of_ocaml.Env.decode) + (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> Js_of_ocaml.Env.decode ~mode:Wasm) ;; let bin_annot = field_o "bin_annot" (Dune_lang.Syntax.since Stanza.syntax (3, 8) >>> bool) diff --git a/src/dune_rules/jsoo/js_of_ocaml.ml b/src/dune_rules/jsoo/js_of_ocaml.ml index 40b21d5eb530..9411c647efc9 100644 --- a/src/dune_rules/jsoo/js_of_ocaml.ml +++ b/src/dune_rules/jsoo/js_of_ocaml.ml @@ -74,7 +74,11 @@ module Sourcemap = struct | Inline | File - let decode = enum [ "no", No; "inline", Inline; "file", File ] + let decode ~mode = + match (mode : Mode.t) with + | JS -> enum [ "no", No; "inline", Inline; "file", File ] + | Wasm -> enum [ "no", No; "inline", Inline ] + ;; let equal x y = match x, y with @@ -232,7 +236,7 @@ module In_buildable = struct only_in_executable (field_o "sourcemap" - (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> Sourcemap.decode)) + (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> Sourcemap.decode ~mode)) in { flags; enabled_if; javascript_files; wasm_files; compilation_mode; sourcemap })) ;; @@ -301,13 +305,13 @@ module Env = struct ; enabled_if : Blang.t option } - let decode = + let decode ~mode = fields @@ let+ compilation_mode = field_o "compilation_mode" Compilation_mode.decode and+ sourcemap = field_o "sourcemap" - (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> Sourcemap.decode) + (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> Sourcemap.decode ~mode) and+ runtest_alias = field_o "runtest_alias" Dune_lang.Alias.decode and+ flags = Flags.decode and+ enabled_if = diff --git a/src/dune_rules/jsoo/js_of_ocaml.mli b/src/dune_rules/jsoo/js_of_ocaml.mli index 2201ecee6c39..82e590835fab 100644 --- a/src/dune_rules/jsoo/js_of_ocaml.mli +++ b/src/dune_rules/jsoo/js_of_ocaml.mli @@ -127,7 +127,7 @@ module Env : sig val map : f:('a -> 'b) -> 'a t -> 'b t val equal : Ordered_set_lang.Unexpanded.t t -> Ordered_set_lang.Unexpanded.t t -> bool - val decode : Ordered_set_lang.Unexpanded.t t Dune_lang.Decoder.t + val decode : mode:Mode.t -> Ordered_set_lang.Unexpanded.t t Dune_lang.Decoder.t val default : profile:Profile.t -> string list t val empty : Ordered_set_lang.Unexpanded.t t end diff --git a/src/dune_rules/jsoo/jsoo_rules.ml b/src/dune_rules/jsoo/jsoo_rules.ml index 79399ac1bdf0..c20e4d776678 100644 --- a/src/dune_rules/jsoo/jsoo_rules.ml +++ b/src/dune_rules/jsoo/jsoo_rules.ml @@ -259,12 +259,14 @@ let js_of_ocaml_rule | Compile -> S [] | Link -> A "link" | Build_runtime -> A "build-runtime") - ; (match (sourcemap : Js_of_ocaml.Sourcemap.t), mode with - | No, _ -> A "--no-source-map" - | Inline, _ | File, Wasm -> - (* With wasm_of_ocaml, source maps are always inline *) - A "--source-map-inline" - | File, JS -> + ; (match (sourcemap : Js_of_ocaml.Sourcemap.t) with + | No -> A "--no-source-map" + | Inline -> A "--source-map-inline" + | File -> + assert ( + match mode with + | JS -> true + | Wasm -> false); S [ A "--source-map" ; Hidden_targets [ Path.Build.set_extension target ~ext:".map" ]