Skip to content

Commit

Permalink
Disallow (wasm_of_ocaml (sourcemap file))
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Vouillon <[email protected]>
  • Loading branch information
vouillon committed Nov 5, 2024
1 parent 17e954a commit aea189c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion doc/reference/dune/executable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ options using ``(wasm_of_ocaml (<wasm_of_ocaml-options>))``.
- ``(wasm_files (<files-list>))`` to specify ``wasm_of_ocaml``
Wasm runtime files.

For the ``(sourcemap <config>)`` option, source maps are generated when ``<config>>`` is either ``file`` or ``inline``. They are put within the ``.bc.wasm.assets`` directory in both cases.
For the ``(sourcemap <config>)`` option, ``<config>`` 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.
Expand Down
4 changes: 2 additions & 2 deletions src/dune_rules/dune_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions src/dune_rules/jsoo/js_of_ocaml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 }))
;;
Expand Down Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/jsoo/js_of_ocaml.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 8 additions & 6 deletions src/dune_rules/jsoo/jsoo_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down

0 comments on commit aea189c

Please sign in to comment.