From 40ac0100ae240f1c71dbdbbefba67ecdc0094788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Tue, 4 Jul 2023 15:27:47 +0200 Subject: [PATCH 1/7] Add wasm_files option and wasmoo_runtime META file entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Vouillon --- doc/reference/dune/executable.rst | 3 +++ src/dune_findlib/meta.ml | 9 +++++++-- src/dune_findlib/package0.ml | 1 + src/dune_findlib/package0.mli | 1 + src/dune_rules/dune_package.ml | 4 ++++ src/dune_rules/findlib.ml | 2 ++ src/dune_rules/gen_meta.ml | 5 +++++ src/dune_rules/inline_tests.ml | 2 +- src/dune_rules/install_rules.ml | 8 +++++++- src/dune_rules/jsoo/js_of_ocaml.ml | 13 ++++++++++++- src/dune_rules/jsoo/js_of_ocaml.mli | 2 ++ src/dune_rules/jsoo/jsoo_rules.ml | 9 ++++++++- src/dune_rules/lib_info.ml | 7 +++++++ src/dune_rules/lib_info.mli | 2 ++ src/dune_rules/stanzas/library.ml | 4 ++++ 15 files changed, 66 insertions(+), 6 deletions(-) diff --git a/doc/reference/dune/executable.rst b/doc/reference/dune/executable.rst index 6521f17a652..c4453f4b155 100644 --- a/doc/reference/dune/executable.rst +++ b/doc/reference/dune/executable.rst @@ -258,6 +258,9 @@ options using ``(js_of_ocaml ())``. - ``(javascript_files ())`` to specify ``js_of_ocaml`` JavaScript runtime files. +- ``(wasm_files ())`` to specify ``wasm_of_ocaml`` + JavaScript and Wasm runtime files. + - ``(compilation_mode )`` where ``>`` is either ``whole_program`` or ``separate``. This is only available inside ``executable`` stanzas. diff --git a/src/dune_findlib/meta.ml b/src/dune_findlib/meta.ml index 34715f2c013..b05db277f81 100644 --- a/src/dune_findlib/meta.ml +++ b/src/dune_findlib/meta.ml @@ -332,8 +332,13 @@ let pp_print_string s = let pp_quoted_value var = match var with - | "archive" | "plugin" | "requires" | "ppx_runtime_deps" | "linkopts" | "jsoo_runtime" - -> pp_print_text + | "archive" + | "plugin" + | "requires" + | "ppx_runtime_deps" + | "linkopts" + | "jsoo_runtime" + | "wasmoo_runtime" -> pp_print_text | _ -> pp_print_string ;; diff --git a/src/dune_findlib/package0.ml b/src/dune_findlib/package0.ml index 8d42b30791c..5e8152c1612 100644 --- a/src/dune_findlib/package0.ml +++ b/src/dune_findlib/package0.ml @@ -25,6 +25,7 @@ let make_archives t var preds = let version t = Vars.get t.vars "version" Ps.empty let description t = Vars.get t.vars "description" Ps.empty let jsoo_runtime t = get_paths t "jsoo_runtime" Ps.empty +let wasmoo_runtime t = get_paths t "wasmoo_runtime" Ps.empty let requires t = Vars.get_words t.vars "requires" preds diff --git a/src/dune_findlib/package0.mli b/src/dune_findlib/package0.mli index 83e8ff5b809..e736926ac5e 100644 --- a/src/dune_findlib/package0.mli +++ b/src/dune_findlib/package0.mli @@ -11,6 +11,7 @@ val meta_fn : Filename.t val version : t -> string option val description : t -> string option val jsoo_runtime : t -> Path.t list +val wasmoo_runtime : t -> Path.t list val requires : t -> Lib_name.t list val exports : t -> Lib_name.t list val ppx_runtime_deps : t -> Lib_name.t list diff --git a/src/dune_rules/dune_package.ml b/src/dune_rules/dune_package.ml index d14728342ba..8aa155f9b65 100644 --- a/src/dune_rules/dune_package.ml +++ b/src/dune_rules/dune_package.ml @@ -104,6 +104,7 @@ module Lib = struct in let melange_runtime_deps = additional_paths (Lib_info.melange_runtime_deps info) in let jsoo_runtime = Lib_info.jsoo_runtime info in + let wasmoo_runtime = Lib_info.wasmoo_runtime info in let virtual_ = Option.is_some (Lib_info.virtual_ info) in let instrumentation_backend = Lib_info.instrumentation_backend info in let native_archives = @@ -137,6 +138,7 @@ module Lib = struct ; paths "foreign_dll_files" foreign_dll_files ; paths "native_archives" native_archives ; paths "jsoo_runtime" jsoo_runtime + ; paths "wasmoo_runtime" wasmoo_runtime ; Lib_dep.L.field_encode requires ~name:"requires" ; libs "ppx_runtime_deps" ppx_runtime_deps ; field_o "implements" (no_loc Lib_name.encode) implements @@ -212,6 +214,7 @@ module Lib = struct and+ foreign_dll_files = paths "foreign_dll_files" and+ native_archives = paths "native_archives" and+ jsoo_runtime = paths "jsoo_runtime" + and+ wasmoo_runtime = paths "wasmoo_runtime" and+ melange_runtime_deps = paths "melange_runtime_deps" and+ requires = field_l "requires" (Lib_dep.decode ~allow_re_export:true) and+ ppx_runtime_deps = libs "ppx_runtime_deps" @@ -281,6 +284,7 @@ module Lib = struct ~native_archives:(Files native_archives) ~foreign_dll_files ~jsoo_runtime + ~wasmoo_runtime ~preprocess ~enabled ~virtual_deps diff --git a/src/dune_rules/findlib.ml b/src/dune_rules/findlib.ml index 7a85a2f766f..4e02cf16148 100644 --- a/src/dune_rules/findlib.ml +++ b/src/dune_rules/findlib.ml @@ -141,6 +141,7 @@ let to_dune_library (t : Findlib.Package.t) ~dir_contents ~ext_lib ~external_loc let public_headers = Lib_info.File_deps.External [] in let plugins = Findlib.Package.plugins t in let jsoo_runtime = Findlib.Package.jsoo_runtime t in + let wasmoo_runtime = Findlib.Package.wasmoo_runtime t in let melange_runtime_deps = Lib_info.File_deps.External [] in let preprocess = Preprocess.Per_module.no_preprocessing () in let virtual_ = None in @@ -237,6 +238,7 @@ let to_dune_library (t : Findlib.Package.t) ~dir_contents ~ext_lib ~external_loc ~native_archives:(Files native_archives) ~foreign_dll_files:[] ~jsoo_runtime + ~wasmoo_runtime ~preprocess ~enabled ~virtual_deps diff --git a/src/dune_rules/gen_meta.ml b/src/dune_rules/gen_meta.ml index aa34cab6c62..0ff2e7dcf41 100644 --- a/src/dune_rules/gen_meta.ml +++ b/src/dune_rules/gen_meta.ml @@ -158,6 +158,11 @@ let gen_lib pub_name lib ~version = | l -> let l = List.map l ~f:Path.basename in [ rule "jsoo_runtime" [] Set (String.concat l ~sep:" ") ]) + ; (match Lib_info.wasmoo_runtime info with + | [] -> [] + | l -> + let l = List.map l ~f:Path.basename in + [ rule "wasmoo_runtime" [] Set (String.concat l ~sep:" ") ]) ] ;; diff --git a/src/dune_rules/inline_tests.ml b/src/dune_rules/inline_tests.ml index fa210531830..1f04e32a4c3 100644 --- a/src/dune_rules/inline_tests.ml +++ b/src/dune_rules/inline_tests.ml @@ -154,7 +154,7 @@ include Sub_system.Register_end_point (struct let js_of_ocaml = Js_of_ocaml.In_context.make ~dir - { lib.buildable.js_of_ocaml with javascript_files = [] } + { lib.buildable.js_of_ocaml with javascript_files = []; wasm_files = [] } in Compilation_context.create () diff --git a/src/dune_rules/install_rules.ml b/src/dune_rules/install_rules.ml index 13831329e05..a2669fd7e3e 100644 --- a/src/dune_rules/install_rules.ml +++ b/src/dune_rules/install_rules.ml @@ -110,11 +110,17 @@ end = struct (List.rev_concat_map ~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 *) + List.sort_uniq + ~compare:Path.Build.compare + (Lib_info.jsoo_runtime lib @ Lib_info.wasmoo_runtime lib) + in [ byte ; native ; foreign_archives ; Lib_info.eval_native_archives_exn lib ~modules - ; Lib_info.jsoo_runtime lib + ; jsoo_files ])) (List.rev_map ~f:(fun f -> Section.Libexec, f) (Lib_info.plugins lib).native) ;; diff --git a/src/dune_rules/jsoo/js_of_ocaml.ml b/src/dune_rules/jsoo/js_of_ocaml.ml index 3cfbf0457ab..ee3b5fc9567 100644 --- a/src/dune_rules/jsoo/js_of_ocaml.ml +++ b/src/dune_rules/jsoo/js_of_ocaml.ml @@ -120,6 +120,7 @@ module In_buildable = struct type t = { flags : Ordered_set_lang.Unexpanded.t Flags.t ; javascript_files : string list + ; wasm_files : string list ; compilation_mode : Compilation_mode.t option ; sourcemap : Sourcemap.t option } @@ -137,6 +138,7 @@ module In_buildable = struct ; link = flags (* we set link as well to preserve the old semantic *) } ; javascript_files + ; wasm_files = [] ; compilation_mode = None ; sourcemap = None }) @@ -144,6 +146,11 @@ module In_buildable = struct fields (let+ flags = Flags.decode and+ javascript_files = field "javascript_files" (repeat string) ~default:[] + and+ wasm_files = + field + "wasm_files" + (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> repeat string) + ~default:[] and+ compilation_mode = if executable then @@ -159,12 +166,13 @@ module In_buildable = struct (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> Sourcemap.decode) else return None in - { flags; javascript_files; compilation_mode; sourcemap }) + { flags; javascript_files; wasm_files; compilation_mode; sourcemap }) ;; let default = { flags = Flags.standard ; javascript_files = [] + ; wasm_files = [] ; compilation_mode = None ; sourcemap = None } @@ -175,6 +183,7 @@ module In_context = struct type t = { flags : Ordered_set_lang.Unexpanded.t Flags.t ; javascript_files : Path.Build.t list + ; wasm_files : Path.Build.t list ; compilation_mode : Compilation_mode.t option ; sourcemap : Sourcemap.t option } @@ -183,6 +192,7 @@ module In_context = struct { flags = x.flags ; javascript_files = List.map ~f:(fun name -> Path.Build.relative dir name) x.javascript_files + ; wasm_files = List.map ~f:(fun name -> Path.Build.relative dir name) x.wasm_files ; compilation_mode = x.compilation_mode ; sourcemap = x.sourcemap } @@ -191,6 +201,7 @@ module In_context = struct let default = { flags = Flags.standard ; javascript_files = [] + ; wasm_files = [] ; compilation_mode = None ; sourcemap = None } diff --git a/src/dune_rules/jsoo/js_of_ocaml.mli b/src/dune_rules/jsoo/js_of_ocaml.mli index 0716f35ebde..d471bdde081 100644 --- a/src/dune_rules/jsoo/js_of_ocaml.mli +++ b/src/dune_rules/jsoo/js_of_ocaml.mli @@ -55,6 +55,7 @@ module In_buildable : sig type t = { flags : Flags.Spec.t ; javascript_files : string list + ; wasm_files : string list ; compilation_mode : Compilation_mode.t option ; sourcemap : Sourcemap.t option } @@ -67,6 +68,7 @@ module In_context : sig type t = { flags : Flags.Spec.t ; javascript_files : Path.Build.t list + ; wasm_files : Path.Build.t list ; compilation_mode : Compilation_mode.t option ; sourcemap : Sourcemap.t option } diff --git a/src/dune_rules/jsoo/jsoo_rules.ml b/src/dune_rules/jsoo/jsoo_rules.ml index 148479f7c78..b67081dd9c8 100644 --- a/src/dune_rules/jsoo/jsoo_rules.ml +++ b/src/dune_rules/jsoo/jsoo_rules.ml @@ -460,6 +460,7 @@ let setup_separate_compilation_rules sctx components = let in_context = { Js_of_ocaml.In_context.flags = Js_of_ocaml.Flags.standard ; javascript_files = [] + ; wasm_files = [] ; compilation_mode = None ; sourcemap = None } @@ -515,7 +516,13 @@ let build_exe = let sctx = Compilation_context.super_context cc in let dir = Compilation_context.dir cc in - let { Js_of_ocaml.In_context.javascript_files; flags; compilation_mode; sourcemap } = + let { Js_of_ocaml.In_context.javascript_files + ; wasm_files = _ + ; flags + ; compilation_mode + ; sourcemap + } + = in_context in let target = Path.Build.set_extension src ~ext:Js_of_ocaml.Ext.exe in diff --git a/src/dune_rules/lib_info.ml b/src/dune_rules/lib_info.ml index 32a89a883f8..ca5d45f6536 100644 --- a/src/dune_rules/lib_info.ml +++ b/src/dune_rules/lib_info.ml @@ -316,6 +316,7 @@ type 'path t = ; native_archives : 'path native_archives ; foreign_dll_files : 'path list ; jsoo_runtime : 'path list + ; wasmoo_runtime : 'path list ; requires : Lib_dep.t list ; ppx_runtime_deps : (Loc.t * Lib_name.t) list ; preprocess : Preprocess.With_instrumentation.t Preprocess.Per_module.t @@ -371,6 +372,7 @@ let synopsis t = t.synopsis let wrapped t = t.wrapped let special_builtin_support t = t.special_builtin_support let jsoo_runtime t = t.jsoo_runtime +let wasmoo_runtime t = t.wasmoo_runtime let main_module_name t = t.main_module_name let orig_src_dir t = t.orig_src_dir let best_src_dir t = Option.value ~default:t.src_dir t.orig_src_dir @@ -414,6 +416,7 @@ let create ~native_archives ~foreign_dll_files ~jsoo_runtime + ~wasmoo_runtime ~preprocess ~enabled ~virtual_deps @@ -451,6 +454,7 @@ let create ; native_archives ; foreign_dll_files ; jsoo_runtime + ; wasmoo_runtime ; preprocess ; enabled ; virtual_deps @@ -495,6 +499,7 @@ let map t ~path_kind ~f_path ~f_obj_dir ~f_public_deps = ; foreign_dll_files = List.map ~f t.foreign_dll_files ; native_archives ; jsoo_runtime = List.map ~f t.jsoo_runtime + ; wasmoo_runtime = List.map ~f t.wasmoo_runtime ; melange_runtime_deps = File_deps.map ~f:f_public_deps t.melange_runtime_deps ; path_kind } @@ -544,6 +549,7 @@ let to_dyn ; native_archives ; foreign_dll_files ; jsoo_runtime + ; wasmoo_runtime ; preprocess = _ ; enabled = _ ; virtual_deps @@ -583,6 +589,7 @@ let to_dyn ; "native_archives", dyn_of_native_archives path native_archives ; "foreign_dll_files", list path foreign_dll_files ; "jsoo_runtime", list path jsoo_runtime + ; "wasmoo_runtime", list path wasmoo_runtime ; "requires", list Lib_dep.to_dyn requires ; "ppx_runtime_deps", list (snd Lib_name.to_dyn) ppx_runtime_deps ; "virtual_deps", list (snd Lib_name.to_dyn) virtual_deps diff --git a/src/dune_rules/lib_info.mli b/src/dune_rules/lib_info.mli index 41ea767962a..0fe1fa5868c 100644 --- a/src/dune_rules/lib_info.mli +++ b/src/dune_rules/lib_info.mli @@ -136,6 +136,7 @@ val default_implementation : _ t -> (Loc.t * Lib_name.t) option val kind : _ t -> Lib_kind.t val synopsis : _ t -> string option val jsoo_runtime : 'path t -> 'path list +val wasmoo_runtime : 'path t -> 'path list val melange_runtime_deps : 'path t -> 'path File_deps.t val obj_dir : 'path t -> 'path Obj_dir.t val virtual_ : _ t -> Modules.t Source.t option @@ -212,6 +213,7 @@ val create -> native_archives:'a native_archives -> foreign_dll_files:'a list -> jsoo_runtime:'a list + -> wasmoo_runtime:'a list -> preprocess:Preprocess.With_instrumentation.t Preprocess.Per_module.t -> enabled:Enabled_status.t Memo.t -> virtual_deps:(Loc.t * Lib_name.t) list diff --git a/src/dune_rules/stanzas/library.ml b/src/dune_rules/stanzas/library.ml index ae64703d300..44c5b9f9200 100644 --- a/src/dune_rules/stanzas/library.ml +++ b/src/dune_rules/stanzas/library.ml @@ -428,6 +428,9 @@ let to_lib_info let jsoo_runtime = List.map conf.buildable.js_of_ocaml.javascript_files ~f:(Path.Build.relative dir) in + let wasmoo_runtime = + List.map conf.buildable.js_of_ocaml.wasm_files ~f:(Path.Build.relative dir) + in let status = match conf.visibility with | Private pkg -> Lib_info.Status.Private (conf.project, pkg) @@ -566,6 +569,7 @@ let to_lib_info ~native_archives ~foreign_dll_files ~jsoo_runtime + ~wasmoo_runtime ~preprocess ~enabled ~virtual_deps From 39b83ab746aa6b7754c518aa3170b2c78cf12764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Tue, 13 Jun 2023 14:47:20 +0200 Subject: [PATCH 2/7] Compilation to Wasm using Wasm_of_ocaml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Vouillon --- src/dune_rules/dir_status.ml | 122 +++++++++-- src/dune_rules/dir_status.mli | 9 +- src/dune_rules/exe.ml | 4 +- src/dune_rules/gen_rules.ml | 12 +- src/dune_rules/inline_tests.ml | 124 ++++++----- src/dune_rules/jsoo/js_of_ocaml.ml | 91 ++++++-- src/dune_rules/jsoo/js_of_ocaml.mli | 39 +++- src/dune_rules/jsoo/jsoo_rules.ml | 305 ++++++++++++++++++-------- src/dune_rules/jsoo/jsoo_rules.mli | 8 + src/dune_rules/lib_rules.ml | 28 +-- src/dune_rules/module_compilation.ml | 24 +- src/dune_rules/stanzas/executables.ml | 2 +- src/dune_rules/test_rules.ml | 31 ++- 13 files changed, 567 insertions(+), 232 deletions(-) diff --git a/src/dune_rules/dir_status.ml b/src/dune_rules/dir_status.ml index 9047ae71529..b9ac1be90e2 100644 --- a/src/dune_rules/dir_status.ml +++ b/src/dune_rules/dir_status.ml @@ -85,6 +85,23 @@ let error_no_module_consumer ~loc (qualification : Include_subdirs.qualification ] ;; +let when_enabled ~dir ~enabled_if directory_targets = + if Path.Build.Map.is_empty directory_targets + then Memo.return directory_targets + else + (match enabled_if with + | Blang.Const const -> Memo.return const + | _ -> + (* Only evaluate the expander if the enabled_if field is + non-trivial to avoid memo cycles. If the enabled_if field is absent + from the "rule" stanza then its value will be [Const true]. *) + let* expander = Expander0.get ~dir in + Expander0.eval_blang expander enabled_if) + >>| function + | false -> Path.Build.Map.empty + | true -> directory_targets +;; + let directory_targets_of_rule ~dir { Rule_conf.targets; loc = rule_loc; enabled_if; _ } = match targets with | Infer -> @@ -114,26 +131,94 @@ let directory_targets_of_rule ~dir { Rule_conf.targets; loc = rule_loc; enabled_ completely, so just ignore this rule for now. *) acc)) in - if Path.Build.Map.is_empty directory_targets - then Memo.return directory_targets - else - (match enabled_if with - | Blang.Const const -> Memo.return const - | _ -> - (* Only evaluate the expander if the enabled_if field is - non-trivial to avoid memo cycles. If the enabled_if field is absent - from the "rule" stanza then its value will be [Const true]. *) - let* expander = Expander0.get ~dir in - Expander0.eval_blang expander enabled_if) - >>| (function - | false -> Path.Build.Map.empty - | true -> directory_targets) + when_enabled ~dir ~enabled_if directory_targets +;; + +let jsoo_wasm_enabled + ~(jsoo_submodes : + dir:Import.Path.Build.t + -> submodes:Js_of_ocaml.Submode.Set.t option + -> Js_of_ocaml.Submode.t list Memo.t) + ~dir + ~submodes + = + let+ submodes = jsoo_submodes ~dir ~submodes in + List.mem ~equal:Poly.equal submodes Wasm +;; + +let directory_targets_of_executables + ~jsoo_submodes + ~dir + { Executables.names; modes; enabled_if; buildable; _ } + = + let* directory_targets = + let* wasm_enabled = + jsoo_wasm_enabled ~jsoo_submodes ~dir ~submodes:buildable.js_of_ocaml.submodes + in + let* explicit_js_mode = + let+ scope = Scope.DB.find_by_dir dir in + let project = Scope.project scope in + Dune_project.explicit_js_mode project + in + if Executables.Link_mode.( + Map.mem modes js || ((not explicit_js_mode) && Map.mem modes byte)) + && wasm_enabled + then + Memo.List.fold_left + (Nonempty_list.to_list names) + ~init:Path.Build.Map.empty + ~f:(fun acc (_, name) -> + let dir_target = Path.Build.relative dir (name ^ Js_of_ocaml.Ext.wasm_dir) in + Path.Build.Map.set acc dir_target buildable.loc |> Memo.return) + else Memo.return Path.Build.Map.empty + in + when_enabled ~dir ~enabled_if directory_targets +;; + +let directory_targets_of_library + ~jsoo_submodes + ~dir + { Library.sub_systems; name; enabled_if; buildable; _ } + = + let* directory_targets = + match Sub_system_name.Map.find sub_systems Inline_tests_info.Tests.name with + | Some (Inline_tests_info.Tests.T { modes; loc; enabled_if; _ }) + when Inline_tests_info.Mode_conf.Set.mem modes Javascript -> + let* directory_targets = + let+ wasm_enabled = + jsoo_wasm_enabled ~jsoo_submodes ~dir ~submodes:buildable.js_of_ocaml.submodes + in + if wasm_enabled + then ( + let lib_name = snd name in + let inline_test_dir = + let inline_test_name = + sprintf "%s.inline-tests" (Lib_name.Local.to_string lib_name) + in + Path.Build.relative dir ("." ^ inline_test_name) + in + let name = + sprintf "inline_test_runner_%s" (Lib_name.Local.to_string lib_name) + in + let dir_target = + Path.Build.relative inline_test_dir (name ^ Js_of_ocaml.Ext.wasm_dir) + in + Path.Build.Map.singleton dir_target loc) + else Path.Build.Map.empty + in + when_enabled ~dir ~enabled_if directory_targets + | _ -> Memo.return Path.Build.Map.empty + in + when_enabled ~dir ~enabled_if directory_targets ;; -let extract_directory_targets ~dir stanzas = +let extract_directory_targets ~jsoo_submodes ~dir stanzas = Memo.parallel_map stanzas ~f:(fun stanza -> match Stanza.repr stanza with | Rule_conf.T rule -> directory_targets_of_rule ~dir rule + | Executables.T exes | Tests.T { exes; _ } -> + directory_targets_of_executables ~jsoo_submodes ~dir exes + | Library.T lib -> directory_targets_of_library ~jsoo_submodes ~dir lib | Coq_stanza.Theory.T m -> (* It's unfortunate that we need to pull in the coq rules here. But we don't have a generic mechanism for this yet. *) @@ -280,15 +365,16 @@ end = struct ;; end -let directory_targets t ~dir = +let directory_targets t ~jsoo_submodes ~dir = match t with | Lock_dir | Generated | Source_only _ | Is_component_of_a_group_but_not_the_root _ -> Memo.return Path.Build.Map.empty | Standalone (_, dune_file) -> - Dune_file.stanzas dune_file >>= extract_directory_targets ~dir + Dune_file.stanzas dune_file >>= extract_directory_targets ~jsoo_submodes ~dir | Group_root { components; dune_file; _ } -> let f ~dir stanzas acc = - extract_directory_targets ~dir stanzas >>| Path.Build.Map.superpose acc + extract_directory_targets ~jsoo_submodes ~dir stanzas + >>| Path.Build.Map.superpose acc in let* init = let* stanzas = Dune_file.stanzas dune_file in diff --git a/src/dune_rules/dir_status.mli b/src/dune_rules/dir_status.mli index 0980d46911d..c42a0d592ff 100644 --- a/src/dune_rules/dir_status.mli +++ b/src/dune_rules/dir_status.mli @@ -42,4 +42,11 @@ module DB : sig val get : dir:Path.Build.t -> t Memo.t end -val directory_targets : t -> dir:Path.Build.t -> Loc.t Path.Build.Map.t Memo.t +val directory_targets + : t + -> jsoo_submodes: + (dir:Import.Path.Build.t + -> submodes:Js_of_ocaml.Submode.Set.t option + -> Js_of_ocaml.Submode.t list Memo.t) + -> dir:Path.Build.t + -> Loc.t Path.Build.Map.t Memo.t diff --git a/src/dune_rules/exe.ml b/src/dune_rules/exe.ml index 368529a84fe..80fc2fff444 100644 --- a/src/dune_rules/exe.ml +++ b/src/dune_rules/exe.ml @@ -26,7 +26,7 @@ module Linkage = struct let native = { mode = Native; ext = ".exe"; flags = [] } let is_native x = x.mode = Native - let is_js x = x.mode = Byte && x.ext = Js_of_ocaml.Ext.exe + let is_js x = x.mode = Byte && x.ext = Js_of_ocaml.Ext.exe ~submode:JS let is_byte x = x.mode = Byte && not (is_js x) let custom_with_ext ~ext ocaml_version = @@ -44,7 +44,7 @@ module Linkage = struct | Ok _ -> native ;; - let js = { mode = Byte; ext = Js_of_ocaml.Ext.exe; flags = [] } + let js = { mode = Byte; ext = Js_of_ocaml.Ext.exe ~submode:JS; flags = [] } let is_plugin t = List.mem (List.map ~f:Mode.plugin_ext Mode.all) t.ext ~equal:String.equal diff --git a/src/dune_rules/gen_rules.ml b/src/dune_rules/gen_rules.ml index 8a299f2e610..150cd8ca621 100644 --- a/src/dune_rules/gen_rules.ml +++ b/src/dune_rules/gen_rules.ml @@ -137,7 +137,10 @@ end = struct js = Some (List.map (Nonempty_list.to_list exes.names) ~f:(fun (_, exe) -> - Path.Build.relative dir (exe ^ Js_of_ocaml.Ext.exe))) + [ Path.Build.relative dir (exe ^ Js_of_ocaml.Ext.exe ~submode:JS) + ; Path.Build.relative dir (exe ^ Js_of_ocaml.Ext.exe ~submode:Wasm) + ]) + |> List.flatten) }) | Alias_conf.T alias -> let+ () = Simple_rules.alias sctx alias ~dir ~expander in @@ -520,7 +523,12 @@ let gen_rules_regular_directory sctx ~src_dir ~components ~dir = in let+ rules = let+ make_rules = - let+ directory_targets = Dir_status.directory_targets dir_status ~dir in + let+ directory_targets = + Dir_status.directory_targets + dir_status + ~jsoo_submodes:Jsoo_rules.jsoo_submodes + ~dir + in let allowed_subdirs = let automatic = Automatic_subdir.subdirs components in let toplevel = diff --git a/src/dune_rules/inline_tests.ml b/src/dune_rules/inline_tests.ml index 1f04e32a4c3..18d9eeab95f 100644 --- a/src/dune_rules/inline_tests.ml +++ b/src/dune_rules/inline_tests.ml @@ -68,6 +68,18 @@ include Sub_system.Register_end_point (struct module Mode_conf = Inline_tests_info.Mode_conf module Info = Inline_tests_info.Tests + let configurations ~dir modes submodes = + let open Memo.O in + Memo.sequential_map (Mode_conf.Set.to_list modes) ~f:(fun (mode : Mode_conf.t) -> + match mode with + | Native | Best -> Memo.return [ mode, ".exe" ] + | Byte -> Memo.return [ mode, ".bc" ] + | Javascript -> + let+ submodes = Jsoo_rules.jsoo_submodes ~dir ~submodes in + List.map submodes ~f:(fun submode -> mode, Js_of_ocaml.Ext.exe ~submode)) + >>| List.flatten + ;; + let gen_rules c ~expander ~(info : Info.t) ~backends = let { Sub_system.Library_compilation_context.super_context = sctx ; dir @@ -238,17 +250,14 @@ include Sub_system.Register_end_point (struct else Sandbox_config.needs_sandboxing in let deps, sandbox = Dep_conf_eval.unnamed ~sandbox info.deps ~expander in - let action (mode : Mode_conf.t) (flags : string list Action_builder.t) + let action + (mode : Mode_conf.t) + (ext : string) + (flags : string list Action_builder.t) : Action.t Action_builder.t = (* [action] needs to run from [dir] as we use [dir] to resolve the exe path in case of a custom [runner] *) - let ext = - match mode with - | Native | Best -> ".exe" - | Javascript -> Js_of_ocaml.Ext.exe - | Byte -> ".bc" - in let custom_runner = match mode with | Native | Best | Byte -> None @@ -309,58 +318,55 @@ include Sub_system.Register_end_point (struct List.concat l in let source_files = List.concat_map source_modules ~f:Module.sources in - Memo.parallel_iter_seq - (Mode_conf.Set.to_seq info.modes) - ~f:(fun (mode : Mode_conf.t) -> - let partition_file = - Path.Build.relative inline_test_dir ("partitions-" ^ Mode_conf.to_string mode) - in - let* () = - match partitions_flags with - | None -> Memo.return () - | Some partitions_flags -> - let open Action_builder.O in - action mode partitions_flags - >>| Action.Full.make ~sandbox - |> Action_builder.with_stdout_to partition_file - |> Super_context.add_rule sctx ~dir ~loc - in - let* runtest_alias = - match mode with - | Native | Best | Byte -> Memo.return Alias0.runtest - | Javascript -> Jsoo_rules.js_of_ocaml_runtest_alias ~dir - in - Super_context.add_alias_action - sctx - ~dir - ~loc:info.loc - (Alias.make ~dir runtest_alias) - (let open Action_builder.O in - let+ actions = - let* partitions_flags = - match partitions_flags with - | None -> Action_builder.return [ None ] - | Some _ -> - let+ partitions = - Action_builder.lines_of (Path.build partition_file) - in - List.map ~f:(fun x -> Some x) partitions - in - List.map partitions_flags ~f:(fun p -> action mode (flags p)) - |> Action_builder.all - and+ () = Action_builder.paths source_files in - match actions with - | [] -> Action.Full.empty - | _ :: _ -> - let run_tests = Action.concurrent actions in - let diffs = - List.map source_files ~f:(fun fn -> - Path.as_in_build_dir_exn fn - |> Path.Build.extend_basename ~suffix:".corrected" - |> Promote.Diff_action.diff ~optional:true fn) - |> Action.concurrent - in - Action.Full.make ~sandbox @@ Action.progn [ run_tests; diffs ])) + let* confs = configurations ~dir info.modes lib.buildable.js_of_ocaml.submodes in + Memo.parallel_iter confs ~f:(fun ((mode : Mode_conf.t), ext) -> + let partition_file = + Path.Build.relative inline_test_dir ("partitions-" ^ Mode_conf.to_string mode) + in + let* () = + match partitions_flags with + | None -> Memo.return () + | Some partitions_flags -> + let open Action_builder.O in + action mode ext partitions_flags + >>| Action.Full.make ~sandbox + |> Action_builder.with_stdout_to partition_file + |> Super_context.add_rule sctx ~dir ~loc + in + let* runtest_alias = + match mode with + | Native | Best | Byte -> Memo.return Alias0.runtest + | Javascript -> Jsoo_rules.js_of_ocaml_runtest_alias ~dir + in + Super_context.add_alias_action + sctx + ~dir + ~loc:info.loc + (Alias.make ~dir runtest_alias) + (let open Action_builder.O in + let+ actions = + let* partitions_flags = + match partitions_flags with + | None -> Action_builder.return [ None ] + | Some _ -> + let+ partitions = Action_builder.lines_of (Path.build partition_file) in + List.map ~f:(fun x -> Some x) partitions + in + List.map partitions_flags ~f:(fun p -> action mode ext (flags p)) + |> Action_builder.all + and+ () = Action_builder.paths source_files in + match actions with + | [] -> Action.Full.empty + | _ :: _ -> + let run_tests = Action.concurrent actions in + let diffs = + List.map source_files ~f:(fun fn -> + Path.as_in_build_dir_exn fn + |> Path.Build.extend_basename ~suffix:".corrected" + |> Promote.Diff_action.diff ~optional:true fn) + |> Action.concurrent + in + Action.Full.make ~sandbox @@ Action.progn [ run_tests; diffs ])) ;; let gen_rules c ~(info : Info.t) ~backends = diff --git a/src/dune_rules/jsoo/js_of_ocaml.ml b/src/dune_rules/jsoo/js_of_ocaml.ml index ee3b5fc9567..90d908e4b18 100644 --- a/src/dune_rules/jsoo/js_of_ocaml.ml +++ b/src/dune_rules/jsoo/js_of_ocaml.ml @@ -1,14 +1,9 @@ open Import open Dune_lang.Decoder -module Ext = struct - type t = string - - let exe = ".bc.js" - let cmo = ".cmo.js" - let cma = ".cma.js" - let runtime = ".bc.runtime.js" -end +(* (js_of_ocaml ...) options are also used when producing Wasm code + with wasm_of_ocaml, since the compilation process is similar and + generates a JavaScript file with basically the same behavior. *) let field_oslu name = Ordered_set_lang.Unexpanded.field name @@ -100,6 +95,39 @@ module Flags = struct ;; end +module Submode = struct + type t = + | JS + | Wasm + + module Set = struct + type t = + { js : bool + ; wasm : bool + } + + let decode = + map + (repeat1 (enum [ "js", JS; "wasm", Wasm ])) + ~f:(fun l -> + List.fold_left + ~f:(fun t submode -> + match submode with + | JS -> { t with js = true } + | Wasm -> { t with wasm = true }) + ~init:{ js = false; wasm = false } + l) + ;; + + let equal x y = x.js = y.js && x.wasm = y.wasm + + let to_list x = + let l = if x.wasm then [ Wasm ] else [] in + if x.js then JS :: l else l + ;; + end +end + module Compilation_mode = struct type t = | Whole_program @@ -119,6 +147,7 @@ end module In_buildable = struct type t = { flags : Ordered_set_lang.Unexpanded.t Flags.t + ; submodes : Submode.Set.t option ; javascript_files : string list ; wasm_files : string list ; compilation_mode : Compilation_mode.t option @@ -137,6 +166,7 @@ module In_buildable = struct ; compile = flags ; link = flags (* we set link as well to preserve the old semantic *) } + ; submodes = None ; javascript_files ; wasm_files = [] ; compilation_mode = None @@ -145,6 +175,10 @@ module In_buildable = struct else fields (let+ flags = Flags.decode + and+ submodes = + field_o + "submodes" + (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> Submode.Set.decode) and+ javascript_files = field "javascript_files" (repeat string) ~default:[] and+ wasm_files = field @@ -166,11 +200,12 @@ module In_buildable = struct (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> Sourcemap.decode) else return None in - { flags; javascript_files; wasm_files; compilation_mode; sourcemap }) + { flags; submodes; javascript_files; wasm_files; compilation_mode; sourcemap }) ;; let default = { flags = Flags.standard + ; submodes = None ; javascript_files = [] ; wasm_files = [] ; compilation_mode = None @@ -182,6 +217,7 @@ end module In_context = struct type t = { flags : Ordered_set_lang.Unexpanded.t Flags.t + ; submodes : Submode.Set.t option ; javascript_files : Path.Build.t list ; wasm_files : Path.Build.t list ; compilation_mode : Compilation_mode.t option @@ -190,6 +226,7 @@ module In_context = struct let make ~(dir : Path.Build.t) (x : In_buildable.t) = { flags = x.flags + ; submodes = x.submodes ; javascript_files = List.map ~f:(fun name -> Path.Build.relative dir name) x.javascript_files ; wasm_files = List.map ~f:(fun name -> Path.Build.relative dir name) x.wasm_files @@ -200,6 +237,7 @@ module In_context = struct let default = { flags = Flags.standard + ; submodes = None ; javascript_files = [] ; wasm_files = [] ; compilation_mode = None @@ -208,12 +246,29 @@ module In_context = struct ;; end +module Ext = struct + type t = string + + let select ~submode js wasm = + match submode with + | Submode.JS -> js + | Wasm -> wasm + ;; + + let exe ~submode = select ~submode ".bc.js" ".bc.wasm.js" + let cmo ~submode = select ~submode ".cmo.js" ".wasmo" + let cma ~submode = select ~submode ".cma.js" ".wasma" + let runtime ~submode = select ~submode ".bc.runtime.js" ".bc.runtime.wasma" + let wasm_dir = ".bc.wasm.assets" +end + module Env = struct type 'a t = { compilation_mode : Compilation_mode.t option ; sourcemap : Sourcemap.t option ; runtest_alias : Alias.Name.t option ; flags : 'a Flags.t + ; submodes : Submode.Set.t option } let decode = @@ -224,20 +279,26 @@ module Env = struct "sourcemap" (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> Sourcemap.decode) and+ runtest_alias = field_o "runtest_alias" Dune_lang.Alias.decode - and+ flags = Flags.decode in + and+ flags = Flags.decode + and+ submodes = + field_o + "submodes" + (Dune_lang.Syntax.since Stanza.syntax (3, 17) >>> Submode.Set.decode) + in Option.iter ~f:Alias.register_as_standard runtest_alias; - { compilation_mode; sourcemap; runtest_alias; flags } + { compilation_mode; sourcemap; runtest_alias; flags; submodes } ;; - let equal { compilation_mode; sourcemap; runtest_alias; flags } t = + let equal { compilation_mode; sourcemap; submodes; runtest_alias; flags } t = Option.equal Compilation_mode.equal compilation_mode t.compilation_mode && Option.equal Sourcemap.equal sourcemap t.sourcemap && Option.equal Alias.Name.equal runtest_alias t.runtest_alias && Flags.equal Ordered_set_lang.Unexpanded.equal flags t.flags + && Option.equal Submode.Set.equal submodes t.submodes ;; - let map ~f { compilation_mode; sourcemap; runtest_alias; flags } = - { compilation_mode; sourcemap; runtest_alias; flags = Flags.map ~f flags } + let map ~f { compilation_mode; sourcemap; runtest_alias; flags; submodes } = + { compilation_mode; sourcemap; runtest_alias; flags = Flags.map ~f flags; submodes } ;; let empty = @@ -245,6 +306,7 @@ module Env = struct ; sourcemap = None ; runtest_alias = None ; flags = Flags.standard + ; submodes = None } ;; @@ -253,6 +315,7 @@ module Env = struct ; sourcemap = None ; runtest_alias = None ; flags = Flags.default ~profile + ; submodes = None } ;; end diff --git a/src/dune_rules/jsoo/js_of_ocaml.mli b/src/dune_rules/jsoo/js_of_ocaml.mli index d471bdde081..e0f83341c97 100644 --- a/src/dune_rules/jsoo/js_of_ocaml.mli +++ b/src/dune_rules/jsoo/js_of_ocaml.mli @@ -1,14 +1,5 @@ open Import -module Ext : sig - type t = string - - val exe : t - val cmo : t - val cma : t - val runtime : t -end - module Flags : sig type 'flags t = { build_runtime : 'flags @@ -45,6 +36,23 @@ module Sourcemap : sig | File end +module Submode : sig + type t = + | JS + | Wasm + + type submode := t + + module Set : sig + type t = + { js : bool + ; wasm : bool + } + + val to_list : t -> submode list + end +end + module Compilation_mode : sig type t = | Whole_program @@ -54,6 +62,7 @@ end module In_buildable : sig type t = { flags : Flags.Spec.t + ; submodes : Submode.Set.t option ; javascript_files : string list ; wasm_files : string list ; compilation_mode : Compilation_mode.t option @@ -67,6 +76,7 @@ end module In_context : sig type t = { flags : Flags.Spec.t + ; submodes : Submode.Set.t option ; javascript_files : Path.Build.t list ; wasm_files : Path.Build.t list ; compilation_mode : Compilation_mode.t option @@ -77,12 +87,23 @@ module In_context : sig val default : t end +module Ext : sig + type t = string + + val exe : submode:Submode.t -> t + val cmo : submode:Submode.t -> t + val cma : submode:Submode.t -> t + val runtime : submode:Submode.t -> t + val wasm_dir : t +end + module Env : sig type 'a t = { compilation_mode : Compilation_mode.t option ; sourcemap : Sourcemap.t option ; runtest_alias : Alias.Name.t option ; flags : 'a Flags.t + ; submodes : Submode.Set.t option } val map : f:('a -> 'b) -> 'a t -> 'b t diff --git a/src/dune_rules/jsoo/jsoo_rules.ml b/src/dune_rules/jsoo/jsoo_rules.ml index b67081dd9c8..dfb75e52241 100644 --- a/src/dune_rules/jsoo/jsoo_rules.ml +++ b/src/dune_rules/jsoo/jsoo_rules.ml @@ -14,6 +14,7 @@ let jsoo_env = { Js_of_ocaml.Env.compilation_mode = Option.first_some local.compilation_mode parent.compilation_mode ; sourcemap = Option.first_some local.sourcemap parent.sourcemap + ; submodes = Option.first_some local.submodes parent.submodes ; runtest_alias = Option.first_some local.runtest_alias parent.runtest_alias ; flags = Js_of_ocaml.Flags.make @@ -195,6 +196,11 @@ let jsoo ~dir sctx = "js_of_ocaml" ;; +let wasmoo ~dir sctx = + (* TODO add a hint when wasm_of_ocaml released on opam *) + Super_context.resolve_program sctx ~dir ~loc:None "wasm_of_ocaml" +;; + type sub_command = | Compile | Link @@ -214,6 +220,7 @@ let js_of_ocaml_flags t ~dir (spec : Js_of_ocaml.Flags.Spec.t) = let js_of_ocaml_rule sctx + ~(submode : Js_of_ocaml.Submode.t) ~sub_command ~dir ~(flags : _ Js_of_ocaml.Flags.t) @@ -221,9 +228,14 @@ let js_of_ocaml_rule ~spec ~target ~sourcemap + ~directory_targets = let open Action_builder.O in - let jsoo = jsoo ~dir sctx in + let jsoo = + match submode with + | JS -> jsoo ~dir sctx + | Wasm -> wasmoo ~dir sctx + in let flags = let* flags = js_of_ocaml_flags sctx ~dir flags in match sub_command with @@ -238,10 +250,12 @@ let js_of_ocaml_rule | Compile -> S [] | Link -> A "link" | Build_runtime -> A "build-runtime") - ; (match (sourcemap : Js_of_ocaml.Sourcemap.t) with - | No -> A "--no-source-map" - | Inline -> A "--source-map-inline" - | File -> + ; (match (sourcemap : Js_of_ocaml.Sourcemap.t), submode with + | No, _ -> A "--no-source-map" + | Inline, _ | File, Wasm -> + (* With wasm_of_ocaml, source maps are always inline *) + A "--source-map-inline" + | File, JS -> S [ A "--source-map" ; Hidden_targets [ Path.Build.set_extension target ~ext:".map" ] @@ -258,11 +272,20 @@ let js_of_ocaml_rule ; Target target ; spec ] + |> Action_builder.With_targets.add_directories ~directory_targets ;; -let jsoo_runtime_files = List.concat_map ~f:(fun t -> Lib_info.jsoo_runtime (Lib.info t)) +let jsoo_runtime_files ~(submode : Js_of_ocaml.Submode.t) libs = + List.concat_map + ~f:(fun t -> + (match submode with + | JS -> Lib_info.jsoo_runtime + | Wasm -> Lib_info.wasmoo_runtime) + (Lib.info t)) + libs +;; -let standalone_runtime_rule cc ~javascript_files ~target ~flags = +let standalone_runtime_rule ~submode cc ~runtime_files ~target ~flags = let dir = Compilation_context.dir cc in let sctx = Compilation_context.super_context cc in let config = @@ -276,22 +299,24 @@ let standalone_runtime_rule cc ~javascript_files ~target ~flags = [ Resolve.Memo.args (let open Resolve.Memo.O in let+ libs = libs in - Command.Args.Deps (jsoo_runtime_files libs)) - ; Deps (List.map ~f:Path.build javascript_files) + Command.Args.Deps (jsoo_runtime_files ~submode libs)) + ; Deps (List.map ~f:Path.build runtime_files) ] in let dir = Compilation_context.dir cc in js_of_ocaml_rule (Compilation_context.super_context cc) + ~submode ~sub_command:Build_runtime ~dir ~flags ~target + ~directory_targets:[] ~spec ~config:(Some config) ;; -let exe_rule cc ~linkall ~javascript_files ~src ~target ~flags = +let exe_rule ~submode cc ~linkall ~runtime_files ~src ~target ~directory_targets ~flags = let dir = Compilation_context.dir cc in let sctx = Compilation_context.super_context cc in let libs = Compilation_context.requires_link cc in @@ -315,44 +340,71 @@ let exe_rule cc ~linkall ~javascript_files ~src ~target ~flags = [ Resolve.Memo.args (let open Resolve.Memo.O in let+ libs = libs in - Command.Args.Deps (jsoo_runtime_files libs)) - ; Deps (List.map ~f:Path.build javascript_files) + Command.Args.Deps (jsoo_runtime_files ~submode libs)) + ; Deps (List.map ~f:Path.build runtime_files) ; Dep (Path.build src) ; Dyn linkall ] in - js_of_ocaml_rule sctx ~sub_command:Compile ~dir ~spec ~target ~flags ~config:None + js_of_ocaml_rule + sctx + ~submode + ~sub_command:Compile + ~dir + ~spec + ~target + ~directory_targets + ~flags + ~config:None ;; -let with_js_ext s = +let with_js_ext ~submode s = match Filename.split_extension s with - | name, ".cma" -> name ^ Js_of_ocaml.Ext.cma - | name, ".cmo" -> name ^ Js_of_ocaml.Ext.cmo + | name, ".cma" -> name ^ Js_of_ocaml.Ext.cma ~submode + | name, ".cmo" -> name ^ Js_of_ocaml.Ext.cmo ~submode | _ -> assert false ;; -let jsoo_archives ctx config lib = +let jsoo_archives ~submode ctx config lib = let info = Lib.info lib in let archives = Lib_info.archives info in match Lib.is_local lib with | true -> let obj_dir = Lib_info.obj_dir info in List.map archives.byte ~f:(fun archive -> - in_obj_dir' ~obj_dir ~config:(Some config) [ with_js_ext (Path.basename archive) ]) + in_obj_dir' + ~obj_dir + ~config:(Some config) + [ with_js_ext ~submode (Path.basename archive) ]) | false -> List.map archives.byte ~f:(fun archive -> Path.build (in_build_dir ctx ~config - [ Lib_name.to_string (Lib.name lib); with_js_ext (Path.basename archive) ])) + [ Lib_name.to_string (Lib.name lib) + ; with_js_ext ~submode (Path.basename archive) + ])) ;; -let link_rule cc ~runtime ~target ~obj_dir cm ~flags ~linkall ~link_time_code_gen = +let link_rule + ~submode + cc + ~runtime + ~target + ~directory_targets + ~obj_dir + cm + ~flags + ~linkall + ~link_time_code_gen + = let sctx = Compilation_context.super_context cc in let dir = Compilation_context.dir cc in let mod_name m = - Module_name.Unique.artifact_filename (Module.obj_name m) ~ext:Js_of_ocaml.Ext.cmo + Module_name.Unique.artifact_filename + (Module.obj_name m) + ~ext:(Js_of_ocaml.Ext.cmo ~submode) in let ctx = Super_context.context sctx |> Context.build_context in let get_all = @@ -373,20 +425,22 @@ let link_rule cc ~runtime ~target ~obj_dir cm ~flags ~linkall ~link_time_code_ge (* Special case for the stdlib because it is not referenced in the META *) let stdlib = - Path.build (in_build_dir ctx ~config [ "stdlib"; "stdlib" ^ Js_of_ocaml.Ext.cma ]) + Path.build + (in_build_dir ctx ~config [ "stdlib"; "stdlib" ^ Js_of_ocaml.Ext.cma ~submode ]) in let special_units = List.concat_map to_link ~f:(function | Lib_flags.Lib_and_module.Lib _lib -> [] | Module (obj_dir, m) -> [ in_obj_dir' ~obj_dir ~config:None [ mod_name m ] ]) in - let all_libs = List.concat_map libs ~f:(jsoo_archives ctx config) in + let all_libs = List.concat_map libs ~f:(jsoo_archives ~submode ctx config) in let all_other_modules = List.map cm ~f:(fun m -> Path.build (in_obj_dir ~obj_dir ~config:None [ mod_name m ])) in let std_exit = - Path.build (in_build_dir ctx ~config [ "stdlib"; "std_exit" ^ Js_of_ocaml.Ext.cmo ]) + Path.build + (in_build_dir ctx ~config [ "stdlib"; "std_exit" ^ Js_of_ocaml.Ext.cmo ~submode ]) in let linkall = force_linkall || linkall in Command.Args.S @@ -403,22 +457,44 @@ let link_rule cc ~runtime ~target ~obj_dir cm ~flags ~linkall ~link_time_code_ge ] in let spec = Command.Args.S [ Dep (Path.build runtime); Dyn get_all ] in - js_of_ocaml_rule sctx ~sub_command:Link ~dir ~spec ~target ~flags ~config:None + js_of_ocaml_rule + sctx + ~submode + ~sub_command:Link + ~dir + ~spec + ~target + ~directory_targets + ~flags + ~config:None ;; -let build_cm' sctx ~dir ~in_context ~src ~target ~config ~sourcemap = +let build_cm' sctx ~dir ~in_context ~submode ~src ~target ~config ~sourcemap = let spec = Command.Args.Dep src in let flags = in_context.Js_of_ocaml.In_context.flags in - js_of_ocaml_rule sctx ~sub_command:Compile ~dir ~flags ~spec ~target ~config ~sourcemap + js_of_ocaml_rule + sctx + ~submode + ~sub_command:Compile + ~dir + ~flags + ~spec + ~target + ~directory_targets:[] + ~config + ~sourcemap ;; -let build_cm sctx ~dir ~in_context ~src ~obj_dir ~config = - let name = with_js_ext (Path.basename src) in +let iter_submodes ~f = Memo.parallel_iter [ Js_of_ocaml.Submode.JS; Wasm ] ~f + +let build_cm sctx ~dir ~in_context ~submode ~src ~obj_dir ~config = + let name = with_js_ext ~submode (Path.basename src) in let target = in_obj_dir ~obj_dir ~config [ name ] in build_cm' sctx ~dir ~in_context + ~submode ~src ~target ~config:(Option.map config ~f:Action_builder.return) @@ -453,32 +529,37 @@ let setup_separate_compilation_rules sctx components = archive "stdlib.cma" :: archive "std_exit.cmo" :: archives | _ -> archives in - Memo.parallel_iter archives ~f:(fun fn -> - let build_context = Context.build_context ctx in - 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 - ; javascript_files = [] - ; wasm_files = [] - ; compilation_mode = None - ; sourcemap = None - } - in - let src = - let src_dir = Lib_info.src_dir info in - Path.relative src_dir name - in - let target = in_build_dir build_context ~config [ lib_name; with_js_ext name ] in - build_cm' - sctx - ~dir - ~in_context - ~src - ~target - ~config:(Some (Action_builder.return config)) - ~sourcemap:Js_of_ocaml.Sourcemap.Inline - |> Super_context.add_rule sctx ~dir)) + iter_submodes ~f:(fun submode -> + Memo.parallel_iter archives ~f:(fun fn -> + let build_context = Context.build_context ctx in + 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 + ; submodes = None + ; javascript_files = [] + ; wasm_files = [] + ; compilation_mode = None + ; sourcemap = None + } + in + let src = + let src_dir = Lib_info.src_dir info in + Path.relative src_dir name + in + let target = + in_build_dir build_context ~config [ lib_name; with_js_ext ~submode name ] + in + build_cm' + sctx + ~dir + ~in_context + ~submode + ~src + ~target + ~config:(Some (Action_builder.return config)) + ~sourcemap:Js_of_ocaml.Sourcemap.Inline + |> Super_context.add_rule sctx ~dir))) ;; let js_of_ocaml_compilation_mode t ~dir = @@ -503,6 +584,19 @@ let js_of_ocaml_sourcemap t ~dir = else No ;; +let jsoo_submodes ~dir ~submodes = + let+ submodes = + match submodes with + | Some _ -> Memo.return submodes + | None -> + let+ js_of_ocaml = jsoo_env ~dir in + js_of_ocaml.submodes + in + match submodes with + | Some m -> Js_of_ocaml.Submode.Set.to_list m + | None -> [ JS ] +;; + let build_exe cc ~loc @@ -517,21 +611,15 @@ let build_exe let sctx = Compilation_context.super_context cc in let dir = Compilation_context.dir cc in let { Js_of_ocaml.In_context.javascript_files - ; wasm_files = _ + ; wasm_files ; flags + ; submodes ; compilation_mode ; sourcemap } = in_context in - let target = Path.Build.set_extension src ~ext:Js_of_ocaml.Ext.exe in - let standalone_runtime = - in_obj_dir - ~obj_dir - ~config:None - [ Path.Build.basename (Path.Build.set_extension src ~ext:Js_of_ocaml.Ext.runtime) ] - in let mode : Rule.Mode.t = match promote with | None -> Standard @@ -546,34 +634,79 @@ let build_exe match sourcemap with | None -> js_of_ocaml_sourcemap sctx ~dir | Some x -> Memo.return x + and* submodes = jsoo_submodes ~dir ~submodes in + let* () = + if not (List.mem ~equal:Poly.equal submodes JS) + then ( + let dst = Path.Build.set_extension src ~ext:(Js_of_ocaml.Ext.exe ~submode:JS) in + let src = + Path.build (Path.Build.set_extension src ~ext:(Js_of_ocaml.Ext.exe ~submode:Wasm)) + in + Super_context.add_rule ~loc ~dir ~mode sctx (Action_builder.copy ~src ~dst)) + else Memo.return () in - match (cmode : Js_of_ocaml.Compilation_mode.t) with - | Separate_compilation -> - let+ () = - standalone_runtime_rule - cc - ~javascript_files - ~target:standalone_runtime - ~flags - ~sourcemap:Js_of_ocaml.Sourcemap.Inline - |> Super_context.add_rule ~loc sctx ~dir - and+ () = - link_rule + Memo.parallel_iter submodes ~f:(fun submode -> + let standalone_runtime = + in_obj_dir + ~obj_dir + ~config:None + [ Path.Build.basename + (Path.Build.set_extension src ~ext:(Js_of_ocaml.Ext.runtime ~submode)) + ] + in + let target = + let ext = Js_of_ocaml.Ext.exe ~submode in + Path.Build.set_extension src ~ext + in + let runtime_files = + match submode with + | JS -> javascript_files + | Wasm -> wasm_files + in + let directory_targets = + match submode with + | JS -> [] + | Wasm -> [ Path.Build.set_extension src ~ext:Js_of_ocaml.Ext.wasm_dir ] + in + match (cmode : Js_of_ocaml.Compilation_mode.t) with + | Separate_compilation -> + let+ () = + standalone_runtime_rule + ~submode + cc + ~runtime_files + ~target:standalone_runtime + ~flags + ~sourcemap:Js_of_ocaml.Sourcemap.Inline + |> Super_context.add_rule ~loc sctx ~dir + and+ () = + link_rule + ~submode + cc + ~runtime:standalone_runtime + ~target + ~directory_targets + ~obj_dir + top_sorted_modules + ~flags + ~linkall + ~link_time_code_gen + ~sourcemap + |> Super_context.add_rule sctx ~loc ~dir ~mode + in + () + | Whole_program -> + exe_rule + ~submode cc - ~runtime:standalone_runtime + ~linkall + ~runtime_files + ~src ~target - ~obj_dir - top_sorted_modules + ~directory_targets ~flags - ~linkall - ~link_time_code_gen ~sourcemap - |> Super_context.add_rule sctx ~loc ~dir ~mode - in - () - | Whole_program -> - exe_rule cc ~linkall ~javascript_files ~src ~target ~flags ~sourcemap - |> Super_context.add_rule sctx ~loc ~dir ~mode + |> Super_context.add_rule sctx ~loc ~dir ~mode) ;; let runner = "node" diff --git a/src/dune_rules/jsoo/jsoo_rules.mli b/src/dune_rules/jsoo/jsoo_rules.mli index 626262eab63..78844da1863 100644 --- a/src/dune_rules/jsoo/jsoo_rules.mli +++ b/src/dune_rules/jsoo/jsoo_rules.mli @@ -19,6 +19,7 @@ val build_cm : Super_context.t -> dir:Path.Build.t -> in_context:Js_of_ocaml.In_context.t + -> submode:Js_of_ocaml.Submode.t -> src:Path.t -> obj_dir:Path.Build.t Obj_dir.t -> config:Config.t option @@ -41,6 +42,13 @@ val runner : string val js_of_ocaml_runtest_alias : dir:Path.Build.t -> Alias.Name.t Memo.t val jsoo_env : dir:Path.Build.t -> string list Action_builder.t Js_of_ocaml.Env.t Memo.t +val jsoo_submodes + : dir:Import.Path.Build.t + -> submodes:Js_of_ocaml.Submode.Set.t option + -> Js_of_ocaml.Submode.t list Memo.t + +val iter_submodes : f:(Js_of_ocaml.Submode.t -> unit Memo.t) -> unit Memo.t + val js_of_ocaml_compilation_mode : Super_context.t -> dir:Import.Path.Build.t diff --git a/src/dune_rules/lib_rules.ml b/src/dune_rules/lib_rules.ml index 5db0c2b7154..404edc4c4da 100644 --- a/src/dune_rules/lib_rules.ml +++ b/src/dune_rules/lib_rules.ml @@ -474,21 +474,23 @@ let setup_build_archives (lib : Library.t) ~top_sorted_modules ~cctx ~expander ~ iter_modes_concurrently modes.ocaml ~f:(fun mode -> build_lib lib ~native_archives ~dir ~sctx ~expander ~flags ~mode ~cm_files) and* () = - (* Build *.cma.js *) + (* Build *.cma.js / *.wasma *) Memo.when_ modes.ocaml.byte (fun () -> let src = Library.archive lib ~dir ~ext:(Mode.compiled_lib_ext Mode.Byte) in - let action_with_targets = - List.map Jsoo_rules.Config.all ~f:(fun config -> - Jsoo_rules.build_cm - sctx - ~dir - ~in_context:js_of_ocaml - ~config:(Some config) - ~src:(Path.build src) - ~obj_dir) - in - Memo.parallel_iter action_with_targets ~f:(fun rule -> - Super_context.add_rule sctx ~dir ~loc:lib.buildable.loc rule)) + Jsoo_rules.iter_submodes ~f:(fun submode -> + let action_with_targets = + List.map Jsoo_rules.Config.all ~f:(fun config -> + Jsoo_rules.build_cm + sctx + ~dir + ~in_context:js_of_ocaml + ~submode + ~config:(Some config) + ~src:(Path.build src) + ~obj_dir) + in + Memo.parallel_iter action_with_targets ~f:(fun rule -> + Super_context.add_rule sctx ~dir ~loc:lib.buildable.loc rule))) in Memo.when_ (Dynlink_supported.By_the_os.get natdynlink_supported && modes.ocaml.native) diff --git a/src/dune_rules/module_compilation.ml b/src/dune_rules/module_compilation.ml index 2679731999f..f0674ecf323 100644 --- a/src/dune_rules/module_compilation.ml +++ b/src/dune_rules/module_compilation.ml @@ -313,19 +313,21 @@ let build_module ?(force_write_cmi = false) ?(precompiled_cmi = false) cctx m = | Some src -> Compilation_context.js_of_ocaml cctx |> Memo.Option.iter ~f:(fun in_context -> - (* Build *.cmo.js *) + (* Build *.cmo.js / *.wasmo *) let sctx = Compilation_context.super_context cctx in let dir = Compilation_context.dir cctx in - let action_with_targets = - Jsoo_rules.build_cm - sctx - ~dir - ~in_context - ~src:(Path.build src) - ~obj_dir - ~config:None - in - Super_context.add_rule sctx ~dir action_with_targets)) + Jsoo_rules.iter_submodes ~f:(fun submode -> + let action_with_targets = + Jsoo_rules.build_cm + sctx + ~dir + ~in_context + ~submode + ~src:(Path.build src) + ~obj_dir + ~config:None + in + Super_context.add_rule sctx ~dir action_with_targets))) in Memo.when_ melange (fun () -> let* () = build_cm ~cm_kind:(Melange Cmj) ~phase:None in diff --git a/src/dune_rules/stanzas/executables.ml b/src/dune_rules/stanzas/executables.ml index 875b8f61cdf..b8f728cf8db 100644 --- a/src/dune_rules/stanzas/executables.ml +++ b/src/dune_rules/stanzas/executables.ml @@ -307,7 +307,7 @@ module Link_mode = struct | Byte, Shared_object -> ".bc" ^ ext_dll | Native, Shared_object -> ext_dll | mode, Plugin -> Mode.plugin_ext mode - | Byte, Js -> Js_of_ocaml.Ext.exe + | Byte, Js -> Js_of_ocaml.Ext.exe ~submode:JS | Native, Js -> User_error.raise ~loc [ Pp.text "Javascript generation only supports bytecode!" ]) ;; diff --git a/src/dune_rules/test_rules.ml b/src/dune_rules/test_rules.ml index a0ceb978d3c..4a4083f2c00 100644 --- a/src/dune_rules/test_rules.ml +++ b/src/dune_rules/test_rules.ml @@ -15,31 +15,30 @@ let rules (t : Tests.t) ~sctx ~dir ~scope ~expander ~dir_contents = else `Regular in let open Memo.O in - let runtest_modes = + let* runtest_modes = if Dune_project.dune_version (Scope.project scope) < (3, 0) - then [ `exe ] + then Memo.return [ `exe, ".exe" ] else Executables.Link_mode.Map.to_list t.exes.modes - |> List.filter_map ~f:(fun ((mode : Executables.Link_mode.t), _) -> + |> Memo.sequential_map ~f:(fun ((mode : Executables.Link_mode.t), _) -> match mode with - | Byte_complete -> Some `exe - | Other { kind = Exe; mode = Native | Best } -> Some `exe - | Other { kind = Exe; mode = Byte } -> Some `bc - | Other { kind = Js; _ } -> Some `js + | Byte_complete | Other { kind = Exe; mode = Native | Best } -> + Memo.return [ `exe, ".exe" ] + | Other { kind = Exe; mode = Byte } -> Memo.return [ `bc, ".bc" ] + | Other { kind = Js; _ } -> + let+ submodes = + Jsoo_rules.jsoo_submodes ~dir ~submodes:t.exes.buildable.js_of_ocaml.submodes + in + List.map submodes ~f:(fun submode -> `js, Js_of_ocaml.Ext.exe ~submode) | Other { kind = C | Object | Shared_object | Plugin; _ } -> (* We don't know how to run tests in these cases *) - None) - |> List.sort_uniq ~compare:Poly.compare + Memo.return []) + >>| List.flatten + >>| List.sort_uniq ~compare:Poly.compare in let* () = Memo.parallel_iter (Nonempty_list.to_list t.exes.names) ~f:(fun (loc, s) -> - Memo.parallel_iter runtest_modes ~f:(fun runtest_mode -> - let ext = - match runtest_mode with - | `js -> Js_of_ocaml.Ext.exe - | `bc -> ".bc" - | `exe -> ".exe" - in + Memo.parallel_iter runtest_modes ~f:(fun (runtest_mode, ext) -> let custom_runner = match runtest_mode with | `js -> Some Jsoo_rules.runner From 2de7794c5c437e7fc15445593b2e1175d78ad462 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Fri, 28 Jun 2024 10:49:30 +0200 Subject: [PATCH 3/7] Update documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Vouillon --- doc/howto/index.rst | 1 + doc/reference/dune/env.rst | 4 +++ doc/reference/dune/executable.rst | 22 +++++++++++---- doc/wasmoo.rst | 46 +++++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 5 deletions(-) create mode 100644 doc/wasmoo.rst diff --git a/doc/howto/index.rst b/doc/howto/index.rst index 91362367a07..ca3fb49843f 100644 --- a/doc/howto/index.rst +++ b/doc/howto/index.rst @@ -15,6 +15,7 @@ These guides will help you use Dune's features in your project. ../sites ../instrumentation ../jsoo + ../wasmoo ../melange ../virtual-libraries ../tests diff --git a/doc/reference/dune/env.rst b/doc/reference/dune/env.rst index cb44d06e17d..485a1bc396b 100644 --- a/doc/reference/dune/env.rst +++ b/doc/reference/dune/env.rst @@ -51,6 +51,10 @@ Fields supported in ```` are: - ``(js_of_ocaml (runtest_alias ))`` specifies the alias under which :ref:`inline_tests` and tests (:ref:`tests-stanza`) run for the `js` mode. +- ``(js_of_ocaml (submodes ))`` controls whether to generate + JavaScript, Wasm code, or both. Each submode is either ``js`` or ``wasm``. + The default is to generate JavaScript code. + - ``(binaries )``, where ```` is a list of entries of the form ``( as )``. ``( as )`` makes the binary ```` available in the command search as just ````. For diff --git a/doc/reference/dune/executable.rst b/doc/reference/dune/executable.rst index c4453f4b155..deb0e3f1ba0 100644 --- a/doc/reference/dune/executable.rst +++ b/doc/reference/dune/executable.rst @@ -14,12 +14,15 @@ executable stanzas is as follows: There can be additional modules in the current directory; you only need to specify the entry point. Given an ``executable`` stanza with ``(name )``, Dune will know how to build ``.exe``. If requested, it will also know how -to build ``.bc`` and ``.bc.js`` (Dune 2.0 and up also need specific -configuration (see the ``modes`` optional field below)). +to build ``.bc``, ``.bc.js`` and ``.bc.wasm.js`` (Dune 2.0 +and up also need specific configuration (see the ``modes`` optional field +below)). ``.exe`` is a native code executable, ``.bc`` is a bytecode -executable which requires ``ocamlrun`` to run, and ``.bc.js`` is a -JavaScript generated using ``js_of_ocaml``. +executable which requires ``ocamlrun`` to run, ``.bc.js`` is a +JavaScript generated using ``js_of_ocaml``, and ``.bc.wasm.js`` is a +Wasm loader generated using ``wasm_of_ocaml`` (the Wasm modules are included in +directory ``.bc.wasm.assets``). Please note: in case native compilation is not available, ``.exe`` will be a custom bytecode executable, in the sense of ``ocamlc -custom``. This means @@ -215,7 +218,8 @@ The extensions for the various linking modes are chosen as follows: .. (byte shared_object) .bc%{ext_dll} .. (native/best shared_object) %{ext_dll} .. c .bc.c -.. js .bc.js +.. js .bc.js (JavaScript) +.. js .bc.wasm.js (Wasm) .. (best plugin) %{ext_plugin} .. (byte plugin) .cma .. (native plugin) .cmxs @@ -233,6 +237,10 @@ linking mode that's the same as ``byte_complete``, but it uses the extension currently tracked by Dune, so they don't run ``.bc`` files during the build. Run the ``.bc.exe`` or ``.exe`` ones instead, as these are self-contained. +When compiling to Wasm but not to JavaScript, a ``.bc.js`` file can +also be produced for compatibility. It is just a copy of the +``bc.wasm.js`` file. + Lastly, note that ``.bc`` executables cannot contain C stubs. If your executable contains C stubs you may want to use ``(modes exe)``. @@ -267,6 +275,10 @@ options using ``(js_of_ocaml ())``. - ``(sourcemap )`` where ``>`` is one of ``no``, ``file`` or ``inline``. This is only available inside ``executable`` stanzas. +- ``(submodes )`` controls whether to generate + JavaScript or Wasm code. Each submode is either ``js`` or ``wasm``. + The default is taken from the environment. + ```` is specified in the :doc:`/reference/ordered-set-language`. The default values for ``flags``, ``compilation_mode`` and ``sourcemap`` depend on the selected build profile. The diff --git a/doc/wasmoo.rst b/doc/wasmoo.rst new file mode 100644 index 00000000000..e5548df05ec --- /dev/null +++ b/doc/wasmoo.rst @@ -0,0 +1,46 @@ +.. _wasmoo: + +*************************************** +Wasm Compilation With Wasm_of_ocaml +*************************************** + +.. TODO(diataxis) + + This is an how-to guide. + +Wasm_of_ocaml_ is a compiler from OCaml to WebAssembly (Wasm for +short). The compiler works by translating OCaml bytecode to Wasm code. + +Compiling to Wasm is very similar to compiling to JavaScript. See +:doc:`jsoo` for more information. + + +Compiling to Wasm +================= + +Dune has full support building Wasm_of_ocaml libraries and executables transparently. +There's no need to customize or enable anything to compile OCaml +libraries/executables to Wasm. + +To build a Wasm executable, just define an executable as you would normally. +Consider this example: + +.. code:: console + + $ echo 'print_endline "hello from wasm"' > foo.ml + +With the following ``dune`` file: + +.. code:: dune + + (executable (name foo) (modes js) (js_of_ocaml (submodes wasm))) + +And then request the ``.wasm.js`` target: + +.. code:: console + + $ dune build ./foo.bc.wasm.js + $ node _build/default/foo.bc.wasm.js + hello from wasm + +.. _wasm_of_ocaml: https://github.com/ocaml-wasm/wasm_of_ocaml From d9989546e93d65cb4280a43d85e8eb3a7e780ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Sat, 6 Jul 2024 14:07:50 +0200 Subject: [PATCH 4/7] Add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Vouillon --- Makefile | 3 + .../gen-opam-install-file/stubs.t/dune | 12 +- .../stubs.t/dune-project | 2 +- .../gen-opam-install-file/stubs.t/foo.wat | 1 + .../gen-opam-install-file/stubs.t/run.t | 1 + .../blackbox-tests/test-cases/meta-gen.t/dune | 7 +- .../test-cases/meta-gen.t/dune-project | 2 +- .../test-cases/meta-gen.t/run.t | 1 + .../test-cases/wasmoo/build-info.t/main.opam | 0 .../test-cases/wasmoo/build-info.t/run.t | 292 ++++++++++++++++++ .../test-cases/wasmoo/build-info.t/src/dune | 13 + .../wasmoo/build-info.t/src/main.ml | 9 + test/blackbox-tests/test-cases/wasmoo/dune | 16 + .../test-cases/wasmoo/github3622.t | 28 ++ .../wasmoo/inline-tests.t/byte/byte.ml | 2 + .../wasmoo/inline-tests.t/byte/dune | 3 + .../test-cases/wasmoo/inline-tests.t/dune | 8 + .../wasmoo/inline-tests.t/native/dune | 3 + .../wasmoo/inline-tests.t/native/native.ml | 2 + .../test-cases/wasmoo/inline-tests.t/run.t | 24 ++ .../wasmoo/inline-tests.t/wasm/dune | 6 + .../wasmoo/inline-tests.t/wasm/wasm.ml | 5 + .../wasmoo/inline-tests.t/wasm/wasm.wat | 4 + .../wasmoo/jsoo-config.t/bin/bin1.ml | 6 + .../wasmoo/jsoo-config.t/bin/bin2.ml | 6 + .../wasmoo/jsoo-config.t/bin/bin3.ml | 6 + .../test-cases/wasmoo/jsoo-config.t/bin/dune | 24 ++ .../test-cases/wasmoo/jsoo-config.t/dune | 7 + .../wasmoo/jsoo-config.t/dune-project | 1 + .../test-cases/wasmoo/jsoo-config.t/lib/dune | 1 + .../wasmoo/jsoo-config.t/lib/library1.ml | 3 + .../test-cases/wasmoo/jsoo-config.t/run.t | 12 + .../wasmoo/no-check-prim.t/bin/dune | 8 + .../wasmoo/no-check-prim.t/bin/runtime.js | 3 + .../wasmoo/no-check-prim.t/bin/technologic.ml | 13 + .../wasmoo/no-check-prim.t/bin/z.ml | 1 + .../wasmoo/no-check-prim.t/dune-project | 1 + .../wasmoo/no-check-prim.t/lib/dune | 7 + .../wasmoo/no-check-prim.t/lib/runtime.js | 6 + .../wasmoo/no-check-prim.t/lib/runtime.wat | 7 + .../wasmoo/no-check-prim.t/lib/x.ml | 5 + .../wasmoo/no-check-prim.t/lib/y.ml | 1 + .../test-cases/wasmoo/no-check-prim.t/run.t | 50 +++ .../test-cases/wasmoo/no-check-prim.t/x.opam | 0 .../test-cases/wasmoo/public-libs.t/a/a.ml | 1 + .../test-cases/wasmoo/public-libs.t/a/dune | 3 + .../test-cases/wasmoo/public-libs.t/b/dune | 5 + .../test-cases/wasmoo/public-libs.t/b/main.ml | 1 + .../wasmoo/public-libs.t/dune-project | 3 + .../test-cases/wasmoo/public-libs.t/run.t | 3 + .../test-cases/wasmoo/simple.t/bin/dune | 8 + .../test-cases/wasmoo/simple.t/bin/runtime.js | 3 + .../wasmoo/simple.t/bin/technologic.ml | 13 + .../test-cases/wasmoo/simple.t/bin/z.ml | 1 + .../test-cases/wasmoo/simple.t/dune-project | 1 + .../test-cases/wasmoo/simple.t/lib/dune | 7 + .../test-cases/wasmoo/simple.t/lib/runtime.js | 6 + .../wasmoo/simple.t/lib/runtime.wat | 7 + .../test-cases/wasmoo/simple.t/lib/stubs.c | 3 + .../test-cases/wasmoo/simple.t/lib/x.ml | 5 + .../test-cases/wasmoo/simple.t/lib/y.ml | 1 + .../test-cases/wasmoo/simple.t/run.t | 32 ++ .../test-cases/wasmoo/simple.t/x.opam | 0 .../test-cases/wasmoo/submodes.t/dune | 8 + .../test-cases/wasmoo/submodes.t/dune-project | 1 + .../test-cases/wasmoo/submodes.t/main.ml | 4 + .../test-cases/wasmoo/submodes.t/run.t | 27 ++ .../test-cases/wasmoo/tests.t/a.ml | 1 + .../test-cases/wasmoo/tests.t/b.expected | 1 + .../test-cases/wasmoo/tests.t/b.ml | 1 + .../test-cases/wasmoo/tests.t/dune | 5 + .../test-cases/wasmoo/tests.t/dune-project | 1 + .../test-cases/wasmoo/tests.t/run.t | 4 + 73 files changed, 757 insertions(+), 11 deletions(-) create mode 100644 test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/foo.wat create mode 100644 test/blackbox-tests/test-cases/wasmoo/build-info.t/main.opam create mode 100644 test/blackbox-tests/test-cases/wasmoo/build-info.t/run.t create mode 100644 test/blackbox-tests/test-cases/wasmoo/build-info.t/src/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/build-info.t/src/main.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/github3622.t create mode 100644 test/blackbox-tests/test-cases/wasmoo/inline-tests.t/byte/byte.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/inline-tests.t/byte/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/inline-tests.t/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/inline-tests.t/native/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/inline-tests.t/native/native.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/inline-tests.t/run.t create mode 100644 test/blackbox-tests/test-cases/wasmoo/inline-tests.t/wasm/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/inline-tests.t/wasm/wasm.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/inline-tests.t/wasm/wasm.wat create mode 100644 test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/bin1.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/bin2.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/bin3.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/dune-project create mode 100644 test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/lib/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/lib/library1.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/run.t create mode 100644 test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/runtime.js create mode 100644 test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/technologic.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/z.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/dune-project create mode 100644 test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/runtime.js create mode 100644 test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/runtime.wat create mode 100644 test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/x.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/y.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/run.t create mode 100644 test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/x.opam create mode 100644 test/blackbox-tests/test-cases/wasmoo/public-libs.t/a/a.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/public-libs.t/a/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/public-libs.t/b/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/public-libs.t/b/main.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/public-libs.t/dune-project create mode 100644 test/blackbox-tests/test-cases/wasmoo/public-libs.t/run.t create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/bin/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/bin/runtime.js create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/bin/technologic.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/bin/z.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/dune-project create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/lib/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/lib/runtime.js create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/lib/runtime.wat create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/lib/stubs.c create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/lib/x.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/lib/y.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/run.t create mode 100644 test/blackbox-tests/test-cases/wasmoo/simple.t/x.opam create mode 100644 test/blackbox-tests/test-cases/wasmoo/submodes.t/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/submodes.t/dune-project create mode 100644 test/blackbox-tests/test-cases/wasmoo/submodes.t/main.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/submodes.t/run.t create mode 100644 test/blackbox-tests/test-cases/wasmoo/tests.t/a.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/tests.t/b.expected create mode 100644 test/blackbox-tests/test-cases/wasmoo/tests.t/b.ml create mode 100644 test/blackbox-tests/test-cases/wasmoo/tests.t/dune create mode 100644 test/blackbox-tests/test-cases/wasmoo/tests.t/dune-project create mode 100644 test/blackbox-tests/test-cases/wasmoo/tests.t/run.t diff --git a/Makefile b/Makefile index cd14e6f68b4..9d76d842da2 100644 --- a/Makefile +++ b/Makefile @@ -89,6 +89,9 @@ test-windows: $(BIN) test-js: $(BIN) $(BIN) build @runtest-js +test-wasm: $(BIN) + DUNE_WASM_TEST=enable $(BIN) build @runtest-wasm + test-coq: $(BIN) DUNE_COQ_TEST=enable $(BIN) build @runtest-coq diff --git a/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/dune b/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/dune index f6f742a6fc9..af74ed3b5df 100644 --- a/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/dune +++ b/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/dune @@ -1,11 +1,11 @@ (library (name foo) (install_c_headers cfoo) - (js_of_ocaml (javascript_files foo.js)) - (c_names c) - (cxx_names cpp) + (js_of_ocaml (javascript_files foo.js) (wasm_files foo.js foo.wat)) + (foreign_stubs (language c) (names c)) + (foreign_stubs (language cxx) (names cpp)) (public_name foo)) -(alias - (name default) - (action (echo "%{read:foo.install}"))) \ No newline at end of file +(rule + (alias default) + (action (echo "%{read:foo.install}"))) diff --git a/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/dune-project b/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/dune-project index de4fc209200..3e2a6150dda 100644 --- a/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/dune-project +++ b/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/dune-project @@ -1 +1 @@ -(lang dune 1.0) +(lang dune 3.17) diff --git a/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/foo.wat b/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/foo.wat new file mode 100644 index 00000000000..3af8f254547 --- /dev/null +++ b/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/foo.wat @@ -0,0 +1 @@ +(module) diff --git a/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/run.t b/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/run.t index 6a8b999201e..25fedb24d65 100644 --- a/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/run.t +++ b/test/blackbox-tests/test-cases/gen-opam-install-file/stubs.t/run.t @@ -13,6 +13,7 @@ stubs and js files installed "_build/install/default/lib/foo/foo.cmxa" "_build/install/default/lib/foo/foo.js" "_build/install/default/lib/foo/foo.ml" + "_build/install/default/lib/foo/foo.wat" "_build/install/default/lib/foo/libfoo_stubs$ext_lib" "_build/install/default/lib/foo/opam" ] diff --git a/test/blackbox-tests/test-cases/meta-gen.t/dune b/test/blackbox-tests/test-cases/meta-gen.t/dune index 91925536c33..8fb1d5c797c 100644 --- a/test/blackbox-tests/test-cases/meta-gen.t/dune +++ b/test/blackbox-tests/test-cases/meta-gen.t/dune @@ -13,7 +13,9 @@ (library (name foobar_runtime_lib2) - (js_of_ocaml (javascript_files foobar_runtime.js foobar_runtime2.js)) + (js_of_ocaml + (javascript_files foobar_runtime.js foobar_runtime2.js) + (wasm_files foobar_runtime.wat foobar_runtime2.wat)) (public_name foobar.runtime-lib2) (synopsis "runtime library for foobar.rewriter2")) @@ -41,6 +43,5 @@ (libraries foobar) (preprocess (pps foobar_rewriter))) -(alias - (name runtest) +(rule (alias runtest) (action (echo "%{read:META.foobar}"))) diff --git a/test/blackbox-tests/test-cases/meta-gen.t/dune-project b/test/blackbox-tests/test-cases/meta-gen.t/dune-project index 6aae99ad17a..3e2a6150dda 100644 --- a/test/blackbox-tests/test-cases/meta-gen.t/dune-project +++ b/test/blackbox-tests/test-cases/meta-gen.t/dune-project @@ -1 +1 @@ -(lang dune 1.9) +(lang dune 3.17) diff --git a/test/blackbox-tests/test-cases/meta-gen.t/run.t b/test/blackbox-tests/test-cases/meta-gen.t/run.t index 8a939042406..7716e35b6fd 100644 --- a/test/blackbox-tests/test-cases/meta-gen.t/run.t +++ b/test/blackbox-tests/test-cases/meta-gen.t/run.t @@ -61,6 +61,7 @@ plugin(byte) = "foobar_runtime_lib2.cma" plugin(native) = "foobar_runtime_lib2.cmxs" jsoo_runtime = "foobar_runtime.js foobar_runtime2.js" + wasmoo_runtime = "foobar_runtime.wat foobar_runtime2.wat" ) package "sub" ( directory = "sub" diff --git a/test/blackbox-tests/test-cases/wasmoo/build-info.t/main.opam b/test/blackbox-tests/test-cases/wasmoo/build-info.t/main.opam new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/blackbox-tests/test-cases/wasmoo/build-info.t/run.t b/test/blackbox-tests/test-cases/wasmoo/build-info.t/run.t new file mode 100644 index 00000000000..04aa5e6195e --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/build-info.t/run.t @@ -0,0 +1,292 @@ +Jsoo and build-info + + $ echo "(lang dune 3.17)" > dune-project + $ dune build + Warning: '--source-map' is enabled but the bytecode program was compiled with no debugging information. + Warning: Consider passing '-g' option to ocamlc. + $ node _build/default/src/main.bc.wasm.js + unknown + $ dune install --prefix _install --display short 2>&1 | sed 's/-[a-f0-9]*[.]wasm/.wasm/' + Installing _install/lib/main/META + Installing _install/lib/main/dune-package + Installing _install/lib/main/opam + Installing _install/bin/main + Installing _install/bin/main.bc.wasm.assets/Build_info.wasm + Installing _install/bin/main.bc.wasm.assets/Build_info.wasm.map + Installing _install/bin/main.bc.wasm.assets/Build_info__Build_info_data.wasm + Installing _install/bin/main.bc.wasm.assets/Build_info__Build_info_data.wasm.map + Installing _install/bin/main.bc.wasm.assets/CamlinternalAtomic.wasm + Installing _install/bin/main.bc.wasm.assets/CamlinternalAtomic.wasm.map + Installing _install/bin/main.bc.wasm.assets/CamlinternalFormat.wasm + Installing _install/bin/main.bc.wasm.assets/CamlinternalFormat.wasm.map + Installing _install/bin/main.bc.wasm.assets/CamlinternalFormatBasics.wasm + Installing _install/bin/main.bc.wasm.assets/CamlinternalFormatBasics.wasm.map + Installing _install/bin/main.bc.wasm.assets/CamlinternalLazy.wasm + Installing _install/bin/main.bc.wasm.assets/CamlinternalLazy.wasm.map + Installing _install/bin/main.bc.wasm.assets/Dune__exe__Main.wasm + Installing _install/bin/main.bc.wasm.assets/Dune__exe__Main.wasm.map + Installing _install/bin/main.bc.wasm.assets/Std_exit.wasm + Installing _install/bin/main.bc.wasm.assets/Std_exit.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Buffer.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Buffer.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Bytes.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Bytes.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Char.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Char.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Int.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Int.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Lazy.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Lazy.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__List.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__List.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Obj.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Obj.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Printf.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Printf.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Seq.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Seq.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__String.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__String.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Sys.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Sys.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Uchar.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Uchar.wasm.map + Installing _install/bin/main.bc.wasm.assets/prelude.wasm + Installing _install/bin/main.bc.wasm.assets/runtime.wasm + Installing _install/bin/main.bc.wasm.assets/start.wasm + Installing _install/bin/main.bc.wasm.assets/start-291802e1.wat + Installing _install/bin/main.bc.wasm.js + $ node _install/bin/main.bc.wasm.js + unknown + $ git init -q + $ touch README + $ git add README + $ git commit -m "initial" -q + $ git tag v1 -am "V1" + $ git commit -m "empty2" --allow-empty -q + $ echo "HELLO" > README + $ dune build + Warning: '--source-map' is enabled but the bytecode program was compiled with no debugging information. + Warning: Consider passing '-g' option to ocamlc. + $ node _build/default/src/main.bc.wasm.js + unknown + $ dune install --prefix _install --display short 2>&1 | sed 's/-[a-f0-9]*[.]wasm/.wasm/' + Deleting _install/lib/main/META + Installing _install/lib/main/META + Deleting _install/lib/main/dune-package + Installing _install/lib/main/dune-package + Deleting _install/lib/main/opam + Installing _install/lib/main/opam + Deleting _install/bin/main + Installing _install/bin/main + Deleting _install/bin/main.bc.wasm.assets/Build_info.wasm + Installing _install/bin/main.bc.wasm.assets/Build_info.wasm + Deleting _install/bin/main.bc.wasm.assets/Build_info.wasm.map + Installing _install/bin/main.bc.wasm.assets/Build_info.wasm.map + Installing _install/bin/main.bc.wasm.assets/Build_info__Build_info_data.wasm + Deleting _install/bin/main.bc.wasm.assets/Build_info__Build_info_data.wasm.map + Installing _install/bin/main.bc.wasm.assets/Build_info__Build_info_data.wasm.map + Deleting _install/bin/main.bc.wasm.assets/CamlinternalAtomic.wasm + Installing _install/bin/main.bc.wasm.assets/CamlinternalAtomic.wasm + Deleting _install/bin/main.bc.wasm.assets/CamlinternalAtomic.wasm.map + Installing _install/bin/main.bc.wasm.assets/CamlinternalAtomic.wasm.map + Deleting _install/bin/main.bc.wasm.assets/CamlinternalFormat.wasm + Installing _install/bin/main.bc.wasm.assets/CamlinternalFormat.wasm + Deleting _install/bin/main.bc.wasm.assets/CamlinternalFormat.wasm.map + Installing _install/bin/main.bc.wasm.assets/CamlinternalFormat.wasm.map + Deleting _install/bin/main.bc.wasm.assets/CamlinternalFormatBasics.wasm + Installing _install/bin/main.bc.wasm.assets/CamlinternalFormatBasics.wasm + Deleting _install/bin/main.bc.wasm.assets/CamlinternalFormatBasics.wasm.map + Installing _install/bin/main.bc.wasm.assets/CamlinternalFormatBasics.wasm.map + Deleting _install/bin/main.bc.wasm.assets/CamlinternalLazy.wasm + Installing _install/bin/main.bc.wasm.assets/CamlinternalLazy.wasm + Deleting _install/bin/main.bc.wasm.assets/CamlinternalLazy.wasm.map + Installing _install/bin/main.bc.wasm.assets/CamlinternalLazy.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Dune__exe__Main.wasm + Installing _install/bin/main.bc.wasm.assets/Dune__exe__Main.wasm + Deleting _install/bin/main.bc.wasm.assets/Dune__exe__Main.wasm.map + Installing _install/bin/main.bc.wasm.assets/Dune__exe__Main.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Std_exit.wasm + Installing _install/bin/main.bc.wasm.assets/Std_exit.wasm + Deleting _install/bin/main.bc.wasm.assets/Std_exit.wasm.map + Installing _install/bin/main.bc.wasm.assets/Std_exit.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Buffer.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Buffer.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Buffer.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Buffer.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Bytes.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Bytes.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Bytes.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Bytes.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Char.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Char.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Char.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Char.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Int.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Int.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Int.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Int.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Lazy.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Lazy.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Lazy.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Lazy.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__List.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__List.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__List.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__List.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Obj.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Obj.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Obj.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Obj.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Printf.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Printf.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Printf.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Printf.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Seq.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Seq.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Seq.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Seq.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__String.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__String.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__String.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__String.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Sys.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Sys.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Sys.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Sys.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Uchar.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Uchar.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Uchar.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Uchar.wasm.map + Deleting _install/bin/main.bc.wasm.assets/prelude.wasm + Installing _install/bin/main.bc.wasm.assets/prelude.wasm + Deleting _install/bin/main.bc.wasm.assets/runtime.wasm + Installing _install/bin/main.bc.wasm.assets/runtime.wasm + Deleting _install/bin/main.bc.wasm.assets/start.wasm + Installing _install/bin/main.bc.wasm.assets/start.wasm + Deleting _install/bin/main.bc.wasm.assets/start-291802e1.wat + Installing _install/bin/main.bc.wasm.assets/start-291802e1.wat + Deleting _install/bin/main.bc.wasm.js + Installing _install/bin/main.bc.wasm.js + Installing _install/doc/main/README + $ node _install/bin/main.bc.wasm.js + v1-1-xxxxx-dirty + $ echo "(name main)" >> dune-project + $ echo "(version 0.2.0)" >> dune-project + $ dune build + Warning: '--source-map' is enabled but the bytecode program was compiled with no debugging information. + Warning: Consider passing '-g' option to ocamlc. + $ node _build/default/src/main.bc.wasm.js + 0.2.0 + $ dune install --prefix _install --display short 2>&1 | sed 's/-[a-f0-9]*[.]wasm/.wasm/' + Deleting _install/lib/main/META + Installing _install/lib/main/META + Deleting _install/lib/main/dune-package + Installing _install/lib/main/dune-package + Deleting _install/lib/main/opam + Installing _install/lib/main/opam + Deleting _install/bin/main + Installing _install/bin/main + Deleting _install/bin/main.bc.wasm.assets/Build_info.wasm + Installing _install/bin/main.bc.wasm.assets/Build_info.wasm + Deleting _install/bin/main.bc.wasm.assets/Build_info.wasm.map + Installing _install/bin/main.bc.wasm.assets/Build_info.wasm.map + Installing _install/bin/main.bc.wasm.assets/Build_info__Build_info_data.wasm + Deleting _install/bin/main.bc.wasm.assets/Build_info__Build_info_data.wasm.map + Installing _install/bin/main.bc.wasm.assets/Build_info__Build_info_data.wasm.map + Deleting _install/bin/main.bc.wasm.assets/CamlinternalAtomic.wasm + Installing _install/bin/main.bc.wasm.assets/CamlinternalAtomic.wasm + Deleting _install/bin/main.bc.wasm.assets/CamlinternalAtomic.wasm.map + Installing _install/bin/main.bc.wasm.assets/CamlinternalAtomic.wasm.map + Deleting _install/bin/main.bc.wasm.assets/CamlinternalFormat.wasm + Installing _install/bin/main.bc.wasm.assets/CamlinternalFormat.wasm + Deleting _install/bin/main.bc.wasm.assets/CamlinternalFormat.wasm.map + Installing _install/bin/main.bc.wasm.assets/CamlinternalFormat.wasm.map + Deleting _install/bin/main.bc.wasm.assets/CamlinternalFormatBasics.wasm + Installing _install/bin/main.bc.wasm.assets/CamlinternalFormatBasics.wasm + Deleting _install/bin/main.bc.wasm.assets/CamlinternalFormatBasics.wasm.map + Installing _install/bin/main.bc.wasm.assets/CamlinternalFormatBasics.wasm.map + Deleting _install/bin/main.bc.wasm.assets/CamlinternalLazy.wasm + Installing _install/bin/main.bc.wasm.assets/CamlinternalLazy.wasm + Deleting _install/bin/main.bc.wasm.assets/CamlinternalLazy.wasm.map + Installing _install/bin/main.bc.wasm.assets/CamlinternalLazy.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Dune__exe__Main.wasm + Installing _install/bin/main.bc.wasm.assets/Dune__exe__Main.wasm + Deleting _install/bin/main.bc.wasm.assets/Dune__exe__Main.wasm.map + Installing _install/bin/main.bc.wasm.assets/Dune__exe__Main.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Std_exit.wasm + Installing _install/bin/main.bc.wasm.assets/Std_exit.wasm + Deleting _install/bin/main.bc.wasm.assets/Std_exit.wasm.map + Installing _install/bin/main.bc.wasm.assets/Std_exit.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Buffer.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Buffer.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Buffer.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Buffer.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Bytes.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Bytes.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Bytes.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Bytes.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Char.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Char.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Char.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Char.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Int.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Int.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Int.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Int.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Lazy.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Lazy.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Lazy.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Lazy.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__List.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__List.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__List.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__List.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Obj.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Obj.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Obj.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Obj.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Printf.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Printf.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Printf.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Printf.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Seq.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Seq.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Seq.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Seq.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__String.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__String.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__String.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__String.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Sys.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Sys.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Sys.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Sys.wasm.map + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Uchar.wasm + Installing _install/bin/main.bc.wasm.assets/Stdlib__Uchar.wasm + Deleting _install/bin/main.bc.wasm.assets/Stdlib__Uchar.wasm.map + Installing _install/bin/main.bc.wasm.assets/Stdlib__Uchar.wasm.map + Deleting _install/bin/main.bc.wasm.assets/prelude.wasm + Installing _install/bin/main.bc.wasm.assets/prelude.wasm + Deleting _install/bin/main.bc.wasm.assets/runtime.wasm + Installing _install/bin/main.bc.wasm.assets/runtime.wasm + Deleting _install/bin/main.bc.wasm.assets/start.wasm + Installing _install/bin/main.bc.wasm.assets/start.wasm + Deleting _install/bin/main.bc.wasm.assets/start-291802e1.wat + Installing _install/bin/main.bc.wasm.assets/start-291802e1.wat + Deleting _install/bin/main.bc.wasm.js + Installing _install/bin/main.bc.wasm.js + Deleting _install/doc/main/README + Installing _install/doc/main/README + $ node _build/default/src/main.bc.wasm.js + 0.2.0 diff --git a/test/blackbox-tests/test-cases/wasmoo/build-info.t/src/dune b/test/blackbox-tests/test-cases/wasmoo/build-info.t/src/dune new file mode 100644 index 00000000000..9f1d7f4c7b4 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/build-info.t/src/dune @@ -0,0 +1,13 @@ +(executable + (name main) + (public_name main) + (modes js byte) + (js_of_ocaml (submodes wasm)) + (modules main) + (package main) + (libraries dune-build-info)) + +(install + (section bin) + (files main.bc.wasm.js) + (dirs main.bc.wasm.assets)) diff --git a/test/blackbox-tests/test-cases/wasmoo/build-info.t/src/main.ml b/test/blackbox-tests/test-cases/wasmoo/build-info.t/src/main.ml new file mode 100644 index 00000000000..c526da6abf4 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/build-info.t/src/main.ml @@ -0,0 +1,9 @@ +let version = + match Build_info.V1.version () with + | None -> "unknown" + | Some v -> Build_info.V1.Version.to_string v + +let () = match String.split_on_char '-' version with + | [tag; plus; _commit; dirty] -> Printf.printf "%s-%s-%s-%s" tag plus "xxxxx" dirty + | [ x ] -> print_endline x + | _ -> print_endline "unexpected" diff --git a/test/blackbox-tests/test-cases/wasmoo/dune b/test/blackbox-tests/test-cases/wasmoo/dune new file mode 100644 index 00000000000..5a26ce4c4bf --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/dune @@ -0,0 +1,16 @@ +(cram + (applies_to :whole_subtree) + (deps %{bin:node} %{bin:js_of_ocaml} %{bin:wasm_of_ocaml}) + (alias runtest-wasm) + (enabled_if + (= %{env:DUNE_WASM_TEST=disable} enable))) + +(cram + (applies_to inline-tests) + (deps + (package ppx_expect))) + +(cram + (applies_to build-info) + (deps + (package dune-build-info))) diff --git a/test/blackbox-tests/test-cases/wasmoo/github3622.t b/test/blackbox-tests/test-cases/wasmoo/github3622.t new file mode 100644 index 00000000000..f4103f2d768 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/github3622.t @@ -0,0 +1,28 @@ +This test demonstrates a bug in dune's separation compilation of jsoo. +std_exit.cmo wasn't being linked in the end, which was causing at_exit hooks not +being ran and channels not being flushed. + +Setup fixtures: + + $ echo "(lang dune 3.17)" > dune-project + $ echo 'let () = print_string "bla"' > main.ml + $ cat >dune < (executable + > (name main) + > (modes js) + > (js_of_ocaml (submodes wasm))) + > EOF + +Test without separate compilation: + + $ dune build --profile=release ./main.bc.wasm.js + $ node _build/default/main.bc.wasm.js + bla + +Test with separate compilation: + + $ dune build --profile=dev ./main.bc.wasm.js + $ node _build/default/main.bc.wasm.js + bla + +The result should be the same diff --git a/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/byte/byte.ml b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/byte/byte.ml new file mode 100644 index 00000000000..23b5d38322a --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/byte/byte.ml @@ -0,0 +1,2 @@ +let _ = assert (Sys.backend_type = Bytecode) +let _ = print_endline "inline tests (Byte)" diff --git a/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/byte/dune b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/byte/dune new file mode 100644 index 00000000000..aaf265b6a85 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/byte/dune @@ -0,0 +1,3 @@ +(library + (name inline_tests_byte) + (inline_tests (modes byte) (backend fake_backend))) diff --git a/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/dune b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/dune new file mode 100644 index 00000000000..418c95e453a --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/dune @@ -0,0 +1,8 @@ +(library + (name fake_backend) + (modules ()) + (inline_tests.backend + (generate_runner + (progn + (echo "[@@@warning \"-40\"]\n") + (cat %{impl-files}))))) diff --git a/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/native/dune b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/native/dune new file mode 100644 index 00000000000..44373b41fb1 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/native/dune @@ -0,0 +1,3 @@ +(library + (name inline_tests_native) + (inline_tests (modes native) (backend fake_backend))) diff --git a/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/native/native.ml b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/native/native.ml new file mode 100644 index 00000000000..f28bab40046 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/native/native.ml @@ -0,0 +1,2 @@ +let _ = assert (Sys.backend_type = Native) +let _ = print_endline "inline tests (Native)" diff --git a/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/run.t b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/run.t new file mode 100644 index 00000000000..f4ccb7dbe36 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/run.t @@ -0,0 +1,24 @@ +Run inline tests using node js + + $ cat >dune-project < (lang dune 3.17) + > EOF + + $ dune runtest + inline tests (Byte) + inline tests (Byte) + inline tests (Native) + inline tests (Native) + inline tests (Wasm) + inline tests (Wasm) + + $ dune runtest --profile release + inline tests (Native) + inline tests (Native) + inline tests (Wasm) + inline tests (Wasm) + + $ dune build wasm/.inline_tests_wasm.inline-tests/inline_test_runner_inline_tests_wasm.bc --display short + Error: Don't know how to build + wasm/.inline_tests_wasm.inline-tests/inline_test_runner_inline_tests_wasm.bc + [1] diff --git a/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/wasm/dune b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/wasm/dune new file mode 100644 index 00000000000..7fa81740628 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/wasm/dune @@ -0,0 +1,6 @@ +(library + (name inline_tests_wasm) + (js_of_ocaml (wasm_files wasm.wat) (submodes wasm)) + (inline_tests + (modes js) + (backend fake_backend))) diff --git a/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/wasm/wasm.ml b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/wasm/wasm.ml new file mode 100644 index 00000000000..2db226905c3 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/wasm/wasm.ml @@ -0,0 +1,5 @@ +external prim : unit -> bool = "wasmoo_stubs" + +let _ = assert (Sys.int_size = 31) +let _ = assert (prim ()) +let _ = print_endline "inline tests (Wasm)" diff --git a/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/wasm/wasm.wat b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/wasm/wasm.wat new file mode 100644 index 00000000000..810e81aa67e --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/wasm/wasm.wat @@ -0,0 +1,4 @@ +(module + (func (export "wasmoo_stubs") (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 1))) +) diff --git a/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/bin1.ml b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/bin1.ml new file mode 100644 index 00000000000..bf7f3d4d481 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/bin1.ml @@ -0,0 +1,6 @@ +let name = "bin1" +let hello name = print_endline ("Hi " ^ name) + +let () = Library1.hello name + +let () = hello Library1.name diff --git a/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/bin2.ml b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/bin2.ml new file mode 100644 index 00000000000..87c52bec613 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/bin2.ml @@ -0,0 +1,6 @@ +let name = "bin2" +let hello name = print_endline ("Hi " ^ name) + +let () = Library1.hello name + +let () = hello Library1.name diff --git a/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/bin3.ml b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/bin3.ml new file mode 100644 index 00000000000..d94b8d12e3a --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/bin3.ml @@ -0,0 +1,6 @@ +let name = "bin3" +let hello name = print_endline ("Hi " ^ name) + +let () = Library1.hello name + +let () = hello Library1.name diff --git a/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/dune b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/dune new file mode 100644 index 00000000000..6dc09bed0e5 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/bin/dune @@ -0,0 +1,24 @@ +(executable + (name bin1) + (modules bin1) + (modes js) + (libraries library1) + (js_of_ocaml + (flags (:standard --enable use-js-string))) +) + +(executable + (name bin2) + (modules bin2) + (modes js) + (libraries library1) + (js_of_ocaml + (flags (:standard --disable use-js-string))) +) + +(executable + (name bin3) + (modules bin3) + (modes js) + (libraries library1) +) diff --git a/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/dune b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/dune new file mode 100644 index 00000000000..7f70cce913f --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/dune @@ -0,0 +1,7 @@ +(env + (_ + (js_of_ocaml + (submodes wasm) + (flags (:standard --quiet)) + (compilation_mode separate) +))) diff --git a/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/dune-project b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/dune-project new file mode 100644 index 00000000000..3e2a6150dda --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/dune-project @@ -0,0 +1 @@ +(lang dune 3.17) diff --git a/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/lib/dune b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/lib/dune new file mode 100644 index 00000000000..22f5ea64365 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/lib/dune @@ -0,0 +1 @@ +(library (name library1)) \ No newline at end of file diff --git a/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/lib/library1.ml b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/lib/library1.ml new file mode 100644 index 00000000000..70ad25d7d71 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/lib/library1.ml @@ -0,0 +1,3 @@ +let name = "library1" + +let hello name = print_endline ("Hello " ^ name) diff --git a/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/run.t b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/run.t new file mode 100644 index 00000000000..656ea0da897 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/jsoo-config.t/run.t @@ -0,0 +1,12 @@ +tests js_of_ocaml configs + + $ dune build bin/bin1.bc.wasm.js bin/bin2.bc.wasm.js bin/bin3.bc.wasm.js + $ node _build/default/bin/bin1.bc.wasm.js + Hello bin1 + Hi library1 + $ node _build/default/bin/bin2.bc.wasm.js + Hello bin2 + Hi library1 + $ node _build/default/bin/bin3.bc.wasm.js + Hello bin3 + Hi library1 diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/dune b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/dune new file mode 100644 index 00000000000..de172d2b9a3 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/dune @@ -0,0 +1,8 @@ +(executables + (names technologic) + (libraries js_of_ocaml x) + (modes js) + (js_of_ocaml + (submodes wasm) + (flags (:standard)) + (wasm_files runtime.js))) diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/runtime.js b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/runtime.js new file mode 100644 index 00000000000..c8210c33522 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/runtime.js @@ -0,0 +1,3 @@ +global.globalPrintFunction = function(x){ + console.log(x); +} diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/technologic.ml b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/technologic.ml new file mode 100644 index 00000000000..06e79a164ec --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/technologic.ml @@ -0,0 +1,13 @@ +module Js = Js_of_ocaml.Js + +let _ = + print_endline X.buy_it; + let obj = Js.Unsafe.obj [|"name", Js.Unsafe.inject (Js.string Z.use_it)|] in + Printf.printf "%s\n%!" (X.print obj); + X.external_print (Js.string "break it"); + (fun x -> + let global = Js.Unsafe.get Js.Unsafe.global "global" in + let globalPrintFunction : Js.js_string Js.t -> unit = + Js.Unsafe.get global "globalPrintFunction" in + Js.Unsafe.fun_call globalPrintFunction [|Js.Unsafe.inject x|] + ) (Js.string "fix it") diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/z.ml b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/z.ml new file mode 100644 index 00000000000..30bb9cee296 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/bin/z.ml @@ -0,0 +1 @@ +let use_it = "use it" diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/dune-project b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/dune-project new file mode 100644 index 00000000000..3e2a6150dda --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/dune-project @@ -0,0 +1 @@ +(lang dune 3.17) diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/dune b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/dune new file mode 100644 index 00000000000..a68edc1c0f7 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/dune @@ -0,0 +1,7 @@ +(library + (name x) + (libraries js_of_ocaml) + (public_name x) + (js_of_ocaml + (flags (--pretty)) (wasm_files runtime.js runtime.wat)) + ) diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/runtime.js b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/runtime.js new file mode 100644 index 00000000000..f2398f02647 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/runtime.js @@ -0,0 +1,6 @@ + + +//Provides: jsPrint +function jsPrint(x){ + joo_global_object.console.log(x); +} diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/runtime.wat b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/runtime.wat new file mode 100644 index 00000000000..d88b8003704 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/runtime.wat @@ -0,0 +1,7 @@ +(module + (import "env" "unwrap" (func $unwrap (param (ref eq)) (result anyref))) + (import "js" "jsPrint" (func $jsPrint (param anyref))) + (func (export "jsPrint") (param $x (ref eq)) (result (ref eq)) + (call $jsPrint (call $unwrap (local.get $x))) + (ref.i31 (i32.const 0))) +) diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/x.ml b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/x.ml new file mode 100644 index 00000000000..37ff0eaa243 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/x.ml @@ -0,0 +1,5 @@ +module Js = Js_of_ocaml.Js + +let buy_it = "buy " ^ Y.it +let print x = Js.to_string (Js.Unsafe.get x "name") +external external_print : Js.js_string Js.t -> unit = "jsPrint" diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/y.ml b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/y.ml new file mode 100644 index 00000000000..d11948ee573 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/lib/y.ml @@ -0,0 +1 @@ +let it = "it" diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/run.t b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/run.t new file mode 100644 index 00000000000..1b42947088d --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/run.t @@ -0,0 +1,50 @@ +Compilation using jsoo + + $ dune build --display short bin/technologic.bc.js @install 2>&1 | \ + > sed s,^\ *$(ocamlc -config-var c_compiler),\ \ C_COMPILER,g + wasm_of_ocaml bin/.technologic.eobjs/jsoo/technologic.bc.runtime.wasma + ocamldep bin/.technologic.eobjs/dune__exe__Technologic.impl.d + ocamldep lib/.x.objs/x.impl.d + ocamlc lib/.x.objs/byte/x__.{cmi,cmo,cmt} + ocamldep lib/.x.objs/x__Y.impl.d + ocamldep bin/.technologic.eobjs/dune__exe__Z.impl.d + ocamlopt lib/.x.objs/native/x__.{cmx,o} + ocamlc lib/.x.objs/byte/x__Y.{cmi,cmo,cmt} + wasm_of_ocaml .js/default/js_of_ocaml-compiler.runtime/jsoo_runtime.wasma + wasm_of_ocaml .js/default/js_of_ocaml/js_of_ocaml.wasma + wasm_of_ocaml .js/default/stdlib/std_exit.wasmo + wasm_of_ocaml .js/default/stdlib/stdlib.wasma + ocamlc bin/.technologic.eobjs/byte/dune__exe.{cmi,cmo,cmt} + ocamldep bin/.technologic.eobjs/dune__exe__Technologic.intf.d + ocamlopt lib/.x.objs/native/x__Y.{cmx,o} + ocamlc lib/.x.objs/byte/x.{cmi,cmo,cmt} + wasm_of_ocaml bin/.technologic.eobjs/jsoo/dune__exe.wasmo + ocamlopt lib/.x.objs/native/x.{cmx,o} + ocamlc bin/.technologic.eobjs/byte/dune__exe__Technologic.{cmi,cmti} + ocamlc lib/x.cma + ocamlc bin/.technologic.eobjs/byte/dune__exe__Z.{cmi,cmo,cmt} + ocamlopt lib/x.{a,cmxa} + wasm_of_ocaml lib/.x.objs/jsoo/default/x.wasma + ocamlc bin/.technologic.eobjs/byte/dune__exe__Technologic.{cmo,cmt} + wasm_of_ocaml bin/.technologic.eobjs/jsoo/dune__exe__Z.wasmo + ocamlopt lib/x.cmxs + wasm_of_ocaml bin/.technologic.eobjs/jsoo/dune__exe__Technologic.wasmo + wasm_of_ocaml bin/technologic.bc.wasm.{js,assets} + $ node ./_build/default/bin/technologic.bc.wasm.js + buy it + use it + break it + fix it + $ dune build bin/technologic.bc.wasm.js @install --profile release + $ node ./_build/default/bin/technologic.bc.wasm.js + buy it + use it + break it + fix it + $ cat >dune-workspace < (lang dune 3.17) + > (context + > (default (disable_dynamically_linked_foreign_archives true))) + > EOF + $ dune build bin/technologic.bc.wasm.js @install --profile dev + $ dune build bin/technologic.bc.wasm.js @install --profile release diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/x.opam b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/x.opam new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/blackbox-tests/test-cases/wasmoo/public-libs.t/a/a.ml b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/a/a.ml new file mode 100644 index 00000000000..df5e542079b --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/a/a.ml @@ -0,0 +1 @@ +let x = 12 diff --git a/test/blackbox-tests/test-cases/wasmoo/public-libs.t/a/dune b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/a/dune new file mode 100644 index 00000000000..9222db1e318 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/a/dune @@ -0,0 +1,3 @@ +(library + (public_name foo.a) + (name a)) diff --git a/test/blackbox-tests/test-cases/wasmoo/public-libs.t/b/dune b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/b/dune new file mode 100644 index 00000000000..18b69c13178 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/b/dune @@ -0,0 +1,5 @@ +(executable + (name main) + (libraries a) + (modes js) + (js_of_ocaml (submodes wasm))) diff --git a/test/blackbox-tests/test-cases/wasmoo/public-libs.t/b/main.ml b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/b/main.ml new file mode 100644 index 00000000000..e9273e98aa0 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/b/main.ml @@ -0,0 +1 @@ +let _ = A.x diff --git a/test/blackbox-tests/test-cases/wasmoo/public-libs.t/dune-project b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/dune-project new file mode 100644 index 00000000000..a8110e485a8 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/dune-project @@ -0,0 +1,3 @@ +(lang dune 3.17) + +(package (name foo)) diff --git a/test/blackbox-tests/test-cases/wasmoo/public-libs.t/run.t b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/run.t new file mode 100644 index 00000000000..68a3c636a8a --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/run.t @@ -0,0 +1,3 @@ +Compilation of libraries with public-names + + $ dune build diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/bin/dune b/test/blackbox-tests/test-cases/wasmoo/simple.t/bin/dune new file mode 100644 index 00000000000..de172d2b9a3 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/bin/dune @@ -0,0 +1,8 @@ +(executables + (names technologic) + (libraries js_of_ocaml x) + (modes js) + (js_of_ocaml + (submodes wasm) + (flags (:standard)) + (wasm_files runtime.js))) diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/bin/runtime.js b/test/blackbox-tests/test-cases/wasmoo/simple.t/bin/runtime.js new file mode 100644 index 00000000000..c8210c33522 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/bin/runtime.js @@ -0,0 +1,3 @@ +global.globalPrintFunction = function(x){ + console.log(x); +} diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/bin/technologic.ml b/test/blackbox-tests/test-cases/wasmoo/simple.t/bin/technologic.ml new file mode 100644 index 00000000000..06e79a164ec --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/bin/technologic.ml @@ -0,0 +1,13 @@ +module Js = Js_of_ocaml.Js + +let _ = + print_endline X.buy_it; + let obj = Js.Unsafe.obj [|"name", Js.Unsafe.inject (Js.string Z.use_it)|] in + Printf.printf "%s\n%!" (X.print obj); + X.external_print (Js.string "break it"); + (fun x -> + let global = Js.Unsafe.get Js.Unsafe.global "global" in + let globalPrintFunction : Js.js_string Js.t -> unit = + Js.Unsafe.get global "globalPrintFunction" in + Js.Unsafe.fun_call globalPrintFunction [|Js.Unsafe.inject x|] + ) (Js.string "fix it") diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/bin/z.ml b/test/blackbox-tests/test-cases/wasmoo/simple.t/bin/z.ml new file mode 100644 index 00000000000..30bb9cee296 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/bin/z.ml @@ -0,0 +1 @@ +let use_it = "use it" diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/dune-project b/test/blackbox-tests/test-cases/wasmoo/simple.t/dune-project new file mode 100644 index 00000000000..3e2a6150dda --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/dune-project @@ -0,0 +1 @@ +(lang dune 3.17) diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/dune b/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/dune new file mode 100644 index 00000000000..d1633abbadb --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/dune @@ -0,0 +1,7 @@ +(library + (name x) + (libraries js_of_ocaml) + (public_name x) + (js_of_ocaml + (flags (--pretty)) (wasm_files runtime.js runtime.wat)) + (foreign_stubs (language c) (names stubs))) diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/runtime.js b/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/runtime.js new file mode 100644 index 00000000000..f2398f02647 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/runtime.js @@ -0,0 +1,6 @@ + + +//Provides: jsPrint +function jsPrint(x){ + joo_global_object.console.log(x); +} diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/runtime.wat b/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/runtime.wat new file mode 100644 index 00000000000..d88b8003704 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/runtime.wat @@ -0,0 +1,7 @@ +(module + (import "env" "unwrap" (func $unwrap (param (ref eq)) (result anyref))) + (import "js" "jsPrint" (func $jsPrint (param anyref))) + (func (export "jsPrint") (param $x (ref eq)) (result (ref eq)) + (call $jsPrint (call $unwrap (local.get $x))) + (ref.i31 (i32.const 0))) +) diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/stubs.c b/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/stubs.c new file mode 100644 index 00000000000..9d98a815a89 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/stubs.c @@ -0,0 +1,3 @@ +#include +#include +void jsPrint () { fprintf(stderr, "Unimplemented Javascript primitive myPrint!\n"); exit(1); } diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/x.ml b/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/x.ml new file mode 100644 index 00000000000..37ff0eaa243 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/x.ml @@ -0,0 +1,5 @@ +module Js = Js_of_ocaml.Js + +let buy_it = "buy " ^ Y.it +let print x = Js.to_string (Js.Unsafe.get x "name") +external external_print : Js.js_string Js.t -> unit = "jsPrint" diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/y.ml b/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/y.ml new file mode 100644 index 00000000000..d11948ee573 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/lib/y.ml @@ -0,0 +1 @@ +let it = "it" diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/run.t b/test/blackbox-tests/test-cases/wasmoo/simple.t/run.t new file mode 100644 index 00000000000..1dad7602308 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/run.t @@ -0,0 +1,32 @@ +Compilation using wasmoo + $ dune build bin/technologic.bc.wasm.js @install --profile dev + $ node ./_build/default/bin/technologic.bc.wasm.js + buy it + use it + break it + fix it + $ dune build @install --profile release + $ node ./_build/default/bin/technologic.bc.wasm.js + buy it + use it + break it + fix it + +Compilation using wasmoo with disable_dynamically_linked_foreign_archives = true + + $ cat >dune-workspace < (lang dune 3.17) + > (context + > (default (disable_dynamically_linked_foreign_archives true))) + > EOF + $ dune clean + $ dune build bin/technologic.bc.wasm.js @install --profile dev + +Js_of_ocaml whole program compilation works with +disable_dynamically_linked_foreign_archives = true: + + $ dune build bin/technologic.bc.wasm.js @install --profile release + +We expect a runtime error when running this bc-for-jsoo file. + + $ ! if dune exe bin/technologic.bc-for-jsoo ; then true ; else false ; fi 2> /dev/null diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/x.opam b/test/blackbox-tests/test-cases/wasmoo/simple.t/x.opam new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/blackbox-tests/test-cases/wasmoo/submodes.t/dune b/test/blackbox-tests/test-cases/wasmoo/submodes.t/dune new file mode 100644 index 00000000000..9ebfc9795b2 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/submodes.t/dune @@ -0,0 +1,8 @@ + +(executable + (name main) + (modes js)) + +(env + (wasm (js_of_ocaml (submodes wasm))) + (both (js_of_ocaml (submodes js wasm)))) diff --git a/test/blackbox-tests/test-cases/wasmoo/submodes.t/dune-project b/test/blackbox-tests/test-cases/wasmoo/submodes.t/dune-project new file mode 100644 index 00000000000..3e2a6150dda --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/submodes.t/dune-project @@ -0,0 +1 @@ +(lang dune 3.17) diff --git a/test/blackbox-tests/test-cases/wasmoo/submodes.t/main.ml b/test/blackbox-tests/test-cases/wasmoo/submodes.t/main.ml new file mode 100644 index 00000000000..caaffbbaa9d --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/submodes.t/main.ml @@ -0,0 +1,4 @@ +let () = + match Sys.backend_type with + Other typ -> print_endline typ + | _ -> assert false diff --git a/test/blackbox-tests/test-cases/wasmoo/submodes.t/run.t b/test/blackbox-tests/test-cases/wasmoo/submodes.t/run.t new file mode 100644 index 00000000000..7183468bb7b --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/submodes.t/run.t @@ -0,0 +1,27 @@ +Building with different combinations of submodes + +The default is to only compile to JavaScript + + $ dune build --profile js + $ node _build/default/main.bc.js + js_of_ocaml + $ dune build --profile js main.bc.wasm.js + Error: Don't know how to build main.bc.wasm.js + [1] + +Compiling to Wasm. One can still use the .bc.js binary but it runs +the Wasm code. + + $ dune build --profile wasm + $ node _build/default/main.bc.js + wasm_of_ocaml + $ node _build/default/main.bc.wasm.js + wasm_of_ocaml + +Compiling to both JS and Wasm. + + $ dune build --profile both + $ node _build/default/main.bc.js + js_of_ocaml + $ node _build/default/main.bc.wasm.js + wasm_of_ocaml diff --git a/test/blackbox-tests/test-cases/wasmoo/tests.t/a.ml b/test/blackbox-tests/test-cases/wasmoo/tests.t/a.ml new file mode 100644 index 00000000000..351293c912d --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/tests.t/a.ml @@ -0,0 +1 @@ +let () = print_endline "a: ok" diff --git a/test/blackbox-tests/test-cases/wasmoo/tests.t/b.expected b/test/blackbox-tests/test-cases/wasmoo/tests.t/b.expected new file mode 100644 index 00000000000..3aca7c21f74 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/tests.t/b.expected @@ -0,0 +1 @@ +b: ok diff --git a/test/blackbox-tests/test-cases/wasmoo/tests.t/b.ml b/test/blackbox-tests/test-cases/wasmoo/tests.t/b.ml new file mode 100644 index 00000000000..9b1f9b5f9f2 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/tests.t/b.ml @@ -0,0 +1 @@ +let () = print_endline "b: ok" diff --git a/test/blackbox-tests/test-cases/wasmoo/tests.t/dune b/test/blackbox-tests/test-cases/wasmoo/tests.t/dune new file mode 100644 index 00000000000..c91a047df42 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/tests.t/dune @@ -0,0 +1,5 @@ +(tests + (names a b) + (modes js)) + +(env (_ (js_of_ocaml (runtest_alias runtest-js) (submodes wasm) (compilation_mode whole_program)))) diff --git a/test/blackbox-tests/test-cases/wasmoo/tests.t/dune-project b/test/blackbox-tests/test-cases/wasmoo/tests.t/dune-project new file mode 100644 index 00000000000..3e2a6150dda --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/tests.t/dune-project @@ -0,0 +1 @@ +(lang dune 3.17) diff --git a/test/blackbox-tests/test-cases/wasmoo/tests.t/run.t b/test/blackbox-tests/test-cases/wasmoo/tests.t/run.t new file mode 100644 index 00000000000..60d459816d0 --- /dev/null +++ b/test/blackbox-tests/test-cases/wasmoo/tests.t/run.t @@ -0,0 +1,4 @@ +tests stanza with wasmoo + + $ dune build @default @runtest-js + a: ok From 5e0eaaf0302f71ca4646b6077617e507b9b51118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Thu, 4 Jul 2024 15:54:03 +0200 Subject: [PATCH 5/7] Changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Vouillon --- doc/changes/10695.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changes/10695.md diff --git a/doc/changes/10695.md b/doc/changes/10695.md new file mode 100644 index 00000000000..86fb2c54760 --- /dev/null +++ b/doc/changes/10695.md @@ -0,0 +1 @@ +- Wasm_of_ocaml support (#10695, @vouillon) From 52523e323ae967d5f7d50d1078e53bc44d6dd1ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Sat, 6 Jul 2024 15:46:44 +0200 Subject: [PATCH 6/7] ci: enable wasm_of_ocaml tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Vouillon --- .github/workflows/workflow.yml | 88 ++++++++++++++++++++++ test/blackbox-tests/test-cases/wasmoo/dune | 5 -- 2 files changed, 88 insertions(+), 5 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 9f24ccc46b5..230c61015ef 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -190,6 +190,94 @@ jobs: # We disable the Dune cache when running the tests DUNE_CACHE: disabled + wasm: + name: Wasm_of_ocaml + runs-on: ubuntu-latest + steps: + - name: Install node + uses: actions/setup-node@v4 + with: + node-version: latest + + - name: Restore cached binaryen + id: cache-binaryen + uses: actions/cache/restore@v4 + with: + path: binaryen + key: ${{ runner.os }}-binaryen-version_119 + + - name: Checkout binaryen + if: steps.cache-binaryen.outputs.cache-hit != 'true' + uses: actions/checkout@v4 + with: + repository: WebAssembly/binaryen + path: binaryen + submodules: true + ref: version_119 + + - name: Install ninja + if: steps.cache-binaryen.outputs.cache-hit != 'true' + run: sudo apt-get install ninja-build + + - name: Build binaryen + if: steps.cache-binaryen.outputs.cache-hit != 'true' + working-directory: ./binaryen + run: | + cmake -G Ninja . + ninja + + - name: Cache binaryen + if: steps.cache-binaryen.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: binaryen + key: ${{ runner.os }}-binaryen-version_119 + + - name: Set binaryen's path + run: | + echo "$GITHUB_WORKSPACE/binaryen/bin" >> $GITHUB_PATH + + - name: Checkout code + uses: actions/checkout@v4 + with: + path: dune + + - name: Use OCaml 4.14.x + uses: ocaml/setup-ocaml@v3 + with: + ocaml-compiler: 4.14.x + opam-pin: false + opam-depext: false + dune-cache: true + + - name: Update dune + working-directory: ./dune + run: opam pin add -n dune . --with-version 3.17.0 + + - name: Checkout wasm_of_ocaml + uses: actions/checkout@v4 + with: + repository: ocaml-wasm/wasm_of_ocaml + ref: target-dir + path: wasm_of_ocaml + + - name: Install wasm_of_ocaml + working-directory: ./wasm_of_ocaml + run: | + opam pin add -n . --with-version `< VERSION` + opam install wasm_of_ocaml-compiler + + - name: Set git user + run: | + git config --global user.name github-actions[bot] + git config --global user.email github-actions[bot]@users.noreply.github.com + - name: Run tests + working-directory: ./dune + run: opam exec -- make test-wasm + env: + # We disable the Dune cache when running the tests + DUNE_CACHE: disabled + monorepo_benchmark_test: name: Build monorepo benchmark docker image runs-on: ubuntu-latest diff --git a/test/blackbox-tests/test-cases/wasmoo/dune b/test/blackbox-tests/test-cases/wasmoo/dune index 5a26ce4c4bf..c5e142618c0 100644 --- a/test/blackbox-tests/test-cases/wasmoo/dune +++ b/test/blackbox-tests/test-cases/wasmoo/dune @@ -5,11 +5,6 @@ (enabled_if (= %{env:DUNE_WASM_TEST=disable} enable))) -(cram - (applies_to inline-tests) - (deps - (package ppx_expect))) - (cram (applies_to build-info) (deps From fb09911f8e171d39db1ac75581c1e3b82ceb6381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Vouillon?= Date: Thu, 26 Sep 2024 15:33:24 +0200 Subject: [PATCH 7/7] Wording changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Vouillon --- .github/workflows/workflow.yml | 26 +++++++++---------- doc/wasmoo.rst | 4 +-- .../test-cases/wasmoo/github3622.t | 6 ++--- .../test-cases/wasmoo/inline-tests.t/run.t | 2 +- .../test-cases/wasmoo/no-check-prim.t/run.t | 2 +- .../test-cases/wasmoo/public-libs.t/run.t | 2 +- .../test-cases/wasmoo/simple.t/run.t | 10 +++---- .../test-cases/wasmoo/submodes.t/run.t | 2 +- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 230c61015ef..527695f6f92 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -194,19 +194,19 @@ jobs: name: Wasm_of_ocaml runs-on: ubuntu-latest steps: - - name: Install node + - name: Install Node uses: actions/setup-node@v4 with: node-version: latest - - name: Restore cached binaryen + - name: Restore Cached Binaryen id: cache-binaryen uses: actions/cache/restore@v4 with: path: binaryen key: ${{ runner.os }}-binaryen-version_119 - - name: Checkout binaryen + - name: Checkout Binaryen if: steps.cache-binaryen.outputs.cache-hit != 'true' uses: actions/checkout@v4 with: @@ -215,29 +215,29 @@ jobs: submodules: true ref: version_119 - - name: Install ninja + - name: Install Ninja if: steps.cache-binaryen.outputs.cache-hit != 'true' run: sudo apt-get install ninja-build - - name: Build binaryen + - name: Build Binaryen if: steps.cache-binaryen.outputs.cache-hit != 'true' working-directory: ./binaryen run: | cmake -G Ninja . ninja - - name: Cache binaryen + - name: Cache Binaryen if: steps.cache-binaryen.outputs.cache-hit != 'true' uses: actions/cache/save@v4 with: path: binaryen key: ${{ runner.os }}-binaryen-version_119 - - name: Set binaryen's path + - name: Set Binaryen's Path run: | echo "$GITHUB_WORKSPACE/binaryen/bin" >> $GITHUB_PATH - - name: Checkout code + - name: Checkout Code uses: actions/checkout@v4 with: path: dune @@ -250,28 +250,28 @@ jobs: opam-depext: false dune-cache: true - - name: Update dune + - name: Update Dune working-directory: ./dune run: opam pin add -n dune . --with-version 3.17.0 - - name: Checkout wasm_of_ocaml + - name: Checkout Wasm_of_ocaml uses: actions/checkout@v4 with: repository: ocaml-wasm/wasm_of_ocaml ref: target-dir path: wasm_of_ocaml - - name: Install wasm_of_ocaml + - name: Install Wasm_of_ocaml working-directory: ./wasm_of_ocaml run: | opam pin add -n . --with-version `< VERSION` opam install wasm_of_ocaml-compiler - - name: Set git user + - name: Set Git User run: | git config --global user.name github-actions[bot] git config --global user.email github-actions[bot]@users.noreply.github.com - - name: Run tests + - name: Run Tests working-directory: ./dune run: opam exec -- make test-wasm env: diff --git a/doc/wasmoo.rst b/doc/wasmoo.rst index e5548df05ec..2a088b6d6db 100644 --- a/doc/wasmoo.rst +++ b/doc/wasmoo.rst @@ -18,8 +18,8 @@ Compiling to Wasm is very similar to compiling to JavaScript. See Compiling to Wasm ================= -Dune has full support building Wasm_of_ocaml libraries and executables transparently. -There's no need to customize or enable anything to compile OCaml +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 libraries/executables to Wasm. To build a Wasm executable, just define an executable as you would normally. diff --git a/test/blackbox-tests/test-cases/wasmoo/github3622.t b/test/blackbox-tests/test-cases/wasmoo/github3622.t index f4103f2d768..5b83eb58c01 100644 --- a/test/blackbox-tests/test-cases/wasmoo/github3622.t +++ b/test/blackbox-tests/test-cases/wasmoo/github3622.t @@ -1,6 +1,6 @@ -This test demonstrates a bug in dune's separation compilation of jsoo. -std_exit.cmo wasn't being linked in the end, which was causing at_exit hooks not -being ran and channels not being flushed. +This test demonstrates a bug in Dune's separation compilation of JSOO. +`std_exit.cmo` wasn't being linked in the end, so the `at_exit` +hooks didn't run and the channels weren't flushed. Setup fixtures: diff --git a/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/run.t b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/run.t index f4ccb7dbe36..ea39b6b928c 100644 --- a/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/run.t +++ b/test/blackbox-tests/test-cases/wasmoo/inline-tests.t/run.t @@ -1,4 +1,4 @@ -Run inline tests using node js +Run inline tests using Node.js $ cat >dune-project < (lang dune 3.17) diff --git a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/run.t b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/run.t index 1b42947088d..fec9ab2e6a9 100644 --- a/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/run.t +++ b/test/blackbox-tests/test-cases/wasmoo/no-check-prim.t/run.t @@ -1,4 +1,4 @@ -Compilation using jsoo +Compilation using WasmOO $ dune build --display short bin/technologic.bc.js @install 2>&1 | \ > sed s,^\ *$(ocamlc -config-var c_compiler),\ \ C_COMPILER,g diff --git a/test/blackbox-tests/test-cases/wasmoo/public-libs.t/run.t b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/run.t index 68a3c636a8a..2a5b7fbfd7b 100644 --- a/test/blackbox-tests/test-cases/wasmoo/public-libs.t/run.t +++ b/test/blackbox-tests/test-cases/wasmoo/public-libs.t/run.t @@ -1,3 +1,3 @@ -Compilation of libraries with public-names +Compilation of libraries with `public-names` $ dune build diff --git a/test/blackbox-tests/test-cases/wasmoo/simple.t/run.t b/test/blackbox-tests/test-cases/wasmoo/simple.t/run.t index 1dad7602308..f8194c95599 100644 --- a/test/blackbox-tests/test-cases/wasmoo/simple.t/run.t +++ b/test/blackbox-tests/test-cases/wasmoo/simple.t/run.t @@ -1,4 +1,4 @@ -Compilation using wasmoo +Compilation using WasmOO $ dune build bin/technologic.bc.wasm.js @install --profile dev $ node ./_build/default/bin/technologic.bc.wasm.js buy it @@ -12,7 +12,7 @@ Compilation using wasmoo break it fix it -Compilation using wasmoo with disable_dynamically_linked_foreign_archives = true +Compilation using WasmOO with `disable_dynamically_linked_foreign_archives = true` $ cat >dune-workspace < (lang dune 3.17) @@ -22,11 +22,11 @@ Compilation using wasmoo with disable_dynamically_linked_foreign_archives = true $ dune clean $ dune build bin/technologic.bc.wasm.js @install --profile dev -Js_of_ocaml whole program compilation works with -disable_dynamically_linked_foreign_archives = true: +Wasm_of_ocaml whole program compilation works with +`disable_dynamically_linked_foreign_archives = true`: $ dune build bin/technologic.bc.wasm.js @install --profile release -We expect a runtime error when running this bc-for-jsoo file. +We expect a runtime error when running this `bc-for-jsoo` file. $ ! if dune exe bin/technologic.bc-for-jsoo ; then true ; else false ; fi 2> /dev/null diff --git a/test/blackbox-tests/test-cases/wasmoo/submodes.t/run.t b/test/blackbox-tests/test-cases/wasmoo/submodes.t/run.t index 7183468bb7b..2995e7e95e0 100644 --- a/test/blackbox-tests/test-cases/wasmoo/submodes.t/run.t +++ b/test/blackbox-tests/test-cases/wasmoo/submodes.t/run.t @@ -9,7 +9,7 @@ The default is to only compile to JavaScript Error: Don't know how to build main.bc.wasm.js [1] -Compiling to Wasm. One can still use the .bc.js binary but it runs +Compiling to Wasm. One can still use the `.bc.js` binary but it runs the Wasm code. $ dune build --profile wasm