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

Jsoo: recognize toplevel variant #6920

Merged
merged 2 commits into from
Jan 28, 2023
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
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Unreleased
enabled (#6645, @hhugo)

- Fix *js_of_ocaml* separate compilation rules when `--enable=effects`
or `--enable=use-js-string` is used. (#6714, #6828, @hhugo)
,`--enable=use-js-string` or `--toplevel` is used. (#6714, #6828, #6920, @hhugo)

- Fix *js_of_ocaml* separate compilation in presence of linkall (#6832, #6916, @hhugo)

Expand Down
26 changes: 23 additions & 3 deletions src/dune_rules/jsoo/jsoo_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,25 @@ end = struct
type t =
{ js_string : bool option
; effects : bool option
; toplevel : bool option
}

let default = { js_string = None; effects = None }
let default = { js_string = None; effects = None; toplevel = None }

let bool_opt = [ None; Some true; Some false ]

let all =
List.concat_map bool_opt ~f:(fun js_string ->
List.concat_map bool_opt ~f:(fun effects -> [ { js_string; effects } ]))
List.concat_map bool_opt ~f:(fun effects ->
List.concat_map bool_opt ~f:(fun toplevel ->
[ { js_string; effects; toplevel } ])))

let get t =
List.filter_map
[ ("use-js-string", t.js_string); ("effects", t.effects) ]
[ ("use-js-string", t.js_string)
; ("effects", t.effects)
; ("toplevel", t.toplevel)
]
~f:(fun (n, v) ->
match v with
| None -> None
Expand All @@ -38,6 +44,7 @@ end = struct
match name with
| "use-js-string" -> { acc with js_string = Some v }
| "effects" -> { acc with effects = Some v }
| "toplevel" -> { acc with toplevel = Some v }
| _ -> acc

let path t =
Expand All @@ -61,13 +68,26 @@ end = struct
let rec loop acc = function
| [] -> acc
| "--enable" :: name :: rest -> loop (set acc name true) rest
| maybe_enable :: rest
when String.is_prefix maybe_enable ~prefix:"--enable=" -> (
match String.drop_prefix maybe_enable ~prefix:"--enable=" with
| Some name -> loop (set acc name true) rest
| _ -> assert false)
| "--disable" :: name :: rest -> loop (set acc name false) rest
| maybe_disable :: rest
when String.is_prefix maybe_disable ~prefix:"--disable=" -> (
match String.drop_prefix maybe_disable ~prefix:"--disable=" with
| Some name -> loop (set acc name false) rest
| _ -> assert false)
| "--toplevel" :: rest -> loop (set acc "toplevel" true) rest
| _ :: rest -> loop acc rest
in
loop default l

let to_flags t =
List.concat_map (get t) ~f:(function
| "toplevel", true -> [ "--toplevel" ]
| "toplevel", false -> []
| name, true -> [ "--enable"; name ]
| name, false -> [ "--disable"; name ])
end
Expand Down