Skip to content

Commit

Permalink
Merge pull request #11124 from vouillon/wasm-fix
Browse files Browse the repository at this point in the history
Js_of_ocaml rules: fix whole program compilation
  • Loading branch information
rgrinberg authored Nov 16, 2024
2 parents 3642425 + 21dbfe0 commit d8f7631
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/dune_rules/exe_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ let executables_rules
let* linkages =
let+ jsoo_enabled_modes =
Jsoo_rules.jsoo_enabled_modes ~expander ~dir ~in_context:js_of_ocaml
and+ jsoo_is_whole_program = Jsoo_rules.jsoo_is_whole_program sctx ~dir
and+ jsoo_is_whole_program =
Jsoo_rules.jsoo_is_whole_program sctx ~dir ~in_context:js_of_ocaml
and+ dynamically_linked_foreign_archives =
Context.dynamically_linked_foreign_archives ctx
in
Expand Down
4 changes: 3 additions & 1 deletion src/dune_rules/inline_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ include Sub_system.Register_end_point (struct
| Jsoo JS -> Exe.Linkage.js
| Jsoo Wasm -> Exe.Linkage.wasm)
in
let+ jsoo_is_whole_program = Jsoo_rules.jsoo_is_whole_program sctx ~dir in
let+ jsoo_is_whole_program =
Jsoo_rules.jsoo_is_whole_program sctx ~dir ~in_context:js_of_ocaml
in
if List.exists modes ~f:(fun mode ->
match (mode : Mode_conf.t) with
| Jsoo mode -> Js_of_ocaml.Mode.Pair.select ~mode jsoo_is_whole_program
Expand Down
17 changes: 14 additions & 3 deletions src/dune_rules/jsoo/jsoo_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -618,14 +618,25 @@ let jsoo_enabled_modes ~expander ~dir ~in_context =
{ Js_of_ocaml.Mode.Pair.js; wasm }
;;

let jsoo_is_whole_program t ~dir =
let jsoo_compilation_mode
t
~dir
~(in_context : Js_of_ocaml.In_context.t Js_of_ocaml.Mode.Pair.t)
~mode
=
match (Js_of_ocaml.Mode.Pair.select ~mode in_context).compilation_mode with
| None -> js_of_ocaml_compilation_mode t ~dir ~mode
| Some x -> Memo.return x
;;

let jsoo_is_whole_program t ~dir ~in_context =
let is_whole_program (mode : Js_of_ocaml.Compilation_mode.t) =
match mode with
| Whole_program -> true
| Separate_compilation -> false
in
let+ js = js_of_ocaml_compilation_mode t ~dir ~mode:JS
and+ wasm = js_of_ocaml_compilation_mode t ~dir ~mode:Wasm in
let+ js = jsoo_compilation_mode t ~dir ~in_context ~mode:JS
and+ wasm = jsoo_compilation_mode t ~dir ~in_context ~mode:Wasm in
{ Js_of_ocaml.Mode.Pair.js = is_whole_program js; wasm = is_whole_program wasm }
;;

Expand Down
7 changes: 1 addition & 6 deletions src/dune_rules/jsoo/jsoo_rules.mli
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,5 @@ val jsoo_enabled_modes
val jsoo_is_whole_program
: Super_context.t
-> dir:Path.Build.t
-> in_context:Js_of_ocaml.In_context.t Js_of_ocaml.Mode.Pair.t
-> Js_of_ocaml.Mode.Set.t Memo.t

val js_of_ocaml_compilation_mode
: Super_context.t
-> dir:Path.Build.t
-> mode:Js_of_ocaml.Mode.t
-> Js_of_ocaml.Compilation_mode.t Memo.t
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/jsoo/whole_program.t/a.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_endline "a: ok"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b: ok
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/jsoo/whole_program.t/b.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_endline "b: ok"
4 changes: 4 additions & 0 deletions test/blackbox-tests/test-cases/jsoo/whole_program.t/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(tests
(names a b)
(js_of_ocaml (compilation_mode whole_program))
(modes js))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.17)
4 changes: 4 additions & 0 deletions test/blackbox-tests/test-cases/jsoo/whole_program.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tests stanza with jsoo

$ dune build @runtest
a: ok
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/wasmoo/whole_program.t/a.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_endline "a: ok"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
b: ok
1 change: 1 addition & 0 deletions test/blackbox-tests/test-cases/wasmoo/whole_program.t/b.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = print_endline "b: ok"
4 changes: 4 additions & 0 deletions test/blackbox-tests/test-cases/wasmoo/whole_program.t/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(tests
(names a b)
(wasm_of_ocaml (compilation_mode whole_program))
(modes wasm))
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.17)
4 changes: 4 additions & 0 deletions test/blackbox-tests/test-cases/wasmoo/whole_program.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tests stanza with wasmoo

$ dune build @runtest
a: ok

0 comments on commit d8f7631

Please sign in to comment.