This commit is contained in:
parent
aa2ff7b2f0
commit
2f3113f55d
11742 changed files with 1223940 additions and 0 deletions
|
|
@ -0,0 +1,125 @@
|
|||
Jsoo and build-info
|
||||
|
||||
$ echo "(lang dune 3.17)" > dune-project
|
||||
$ dune build
|
||||
Warning [missing-debug-event]: '--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/dune__exe__Main.wasm
|
||||
Installing _install/bin/main.bc.wasm.assets/dune__exe__Main.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/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.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 [missing-debug-event]: '--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
|
||||
Installing _install/bin/main.bc.wasm.assets/build_info__Build_info_data.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/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/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.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 [missing-debug-event]: '--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
|
||||
Installing _install/bin/main.bc.wasm.assets/build_info__Build_info_data.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/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/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.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
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
(executable
|
||||
(name main)
|
||||
(public_name main)
|
||||
(modes wasm byte)
|
||||
(modules main)
|
||||
(package main)
|
||||
(libraries dune-build-info))
|
||||
|
||||
(install
|
||||
(section bin)
|
||||
(files main.bc.wasm.js)
|
||||
(dirs main.bc.wasm.assets))
|
||||
|
|
@ -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"
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
(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 build-info)
|
||||
(deps
|
||||
(package dune-build-info)))
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
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:
|
||||
|
||||
$ echo "(lang dune 3.17)" > dune-project
|
||||
$ echo 'let () = print_string "bla"' > main.ml
|
||||
$ cat >dune <<EOF
|
||||
> (executable
|
||||
> (name main)
|
||||
> (modes 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
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
let _ = assert (Sys.backend_type = Bytecode)
|
||||
let _ = print_endline "inline tests (Byte)"
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(library
|
||||
(name inline_tests_byte)
|
||||
(inline_tests (modes byte) (backend fake_backend)))
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
(library
|
||||
(name fake_backend)
|
||||
(modules ())
|
||||
(inline_tests.backend
|
||||
(generate_runner
|
||||
(progn
|
||||
(echo "[@@@warning \"-40\"]\n")
|
||||
(cat %{impl-files})))))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(library
|
||||
(name inline_tests_native)
|
||||
(inline_tests (modes native) (backend fake_backend)))
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
let _ = assert (Sys.backend_type = Native)
|
||||
let _ = print_endline "inline tests (Native)"
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
Run inline tests using Node.js
|
||||
|
||||
$ cat >dune-project <<EOF
|
||||
> (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]
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(library
|
||||
(name inline_tests_wasm)
|
||||
(wasm_of_ocaml (wasm_files wasm.wat))
|
||||
(inline_tests
|
||||
(modes wasm)
|
||||
(backend fake_backend)))
|
||||
|
|
@ -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)"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(module
|
||||
(func (export "wasmoo_stubs") (param (ref eq)) (result (ref eq))
|
||||
(ref.i31 (i32.const 1)))
|
||||
)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
let name = "bin1"
|
||||
let hello name = print_endline ("Hi " ^ name)
|
||||
|
||||
let () = Library1.hello name
|
||||
|
||||
let () = hello Library1.name
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
let name = "bin2"
|
||||
let hello name = print_endline ("Hi " ^ name)
|
||||
|
||||
let () = Library1.hello name
|
||||
|
||||
let () = hello Library1.name
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
let name = "bin3"
|
||||
let hello name = print_endline ("Hi " ^ name)
|
||||
|
||||
let () = Library1.hello name
|
||||
|
||||
let () = hello Library1.name
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
(executable
|
||||
(name bin1)
|
||||
(modules bin1)
|
||||
(modes wasm)
|
||||
(libraries library1)
|
||||
)
|
||||
|
||||
(executable
|
||||
(name bin2)
|
||||
(modules bin2)
|
||||
(modes wasm)
|
||||
(libraries library1)
|
||||
)
|
||||
|
||||
(executable
|
||||
(name bin3)
|
||||
(modules bin3)
|
||||
(modes wasm)
|
||||
(libraries library1)
|
||||
)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(env
|
||||
(_
|
||||
(wasm_of_ocaml
|
||||
(flags (:standard --quiet))
|
||||
(compilation_mode separate)
|
||||
)))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 3.17)
|
||||
|
|
@ -0,0 +1 @@
|
|||
(library (name library1))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
let name = "library1"
|
||||
|
||||
let hello name = print_endline ("Hello " ^ name)
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(executables
|
||||
(names technologic)
|
||||
(libraries js_of_ocaml x)
|
||||
(modes wasm)
|
||||
(wasm_of_ocaml
|
||||
(javascript_files runtime.js)))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
global.globalPrintFunction = function(x){
|
||||
console.log(x);
|
||||
}
|
||||
|
|
@ -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")
|
||||
|
|
@ -0,0 +1 @@
|
|||
let use_it = "use it"
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 3.17)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
(library
|
||||
(name x)
|
||||
(libraries js_of_ocaml)
|
||||
(public_name x)
|
||||
(wasm_of_ocaml
|
||||
(flags (--pretty)) (javascript_files runtime.js) (wasm_files runtime.wat))
|
||||
)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
|
||||
//Provides: jsPrint
|
||||
function jsPrint(x){
|
||||
globalThis.console.log(x);
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
(module
|
||||
(import "env" "unwrap" (func $unwrap (param (ref eq)) (result anyref)))
|
||||
(import "js" "jsPrint" (func $print (param anyref)))
|
||||
(func (export "jsPrint") (param $x (ref eq)) (result (ref eq))
|
||||
(call $print (call $unwrap (local.get $x)))
|
||||
(ref.i31 (i32.const 0)))
|
||||
)
|
||||
|
|
@ -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"
|
||||
|
|
@ -0,0 +1 @@
|
|||
let it = "it"
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
Compilation using WasmOO
|
||||
|
||||
$ dune build --display short bin/technologic.bc.wasm.js @install 2>&1 | \
|
||||
> sed s,^\ *$(ocamlc -config-var c_compiler),\ \ C_COMPILER,g
|
||||
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
|
||||
wasm_of_ocaml bin/.technologic.eobjs/jsoo/technologic.bc.runtime.wasma
|
||||
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/stdlib/stdlib.wasma
|
||||
wasm_of_ocaml .js/default/stdlib/std_exit.wasmo
|
||||
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 .js/default/js_of_ocaml-compiler.runtime/jsoo_runtime.wasma
|
||||
ocamlopt lib/.x.objs/native/x.{cmx,o}
|
||||
ocamlc bin/.technologic.eobjs/byte/dune__exe__Z.{cmi,cmo,cmt}
|
||||
ocamlc lib/x.cma
|
||||
ocamlc bin/.technologic.eobjs/byte/dune__exe__Technologic.{cmi,cmti}
|
||||
wasm_of_ocaml .js/default/js_of_ocaml/js_of_ocaml.wasma
|
||||
ocamlopt lib/x.{a,cmxa}
|
||||
ocamlc bin/.technologic.eobjs/byte/dune__exe__Technologic.{cmo,cmt}
|
||||
wasm_of_ocaml lib/.x.objs/jsoo/default/x.wasma
|
||||
ocamlopt lib/x.cmxs
|
||||
wasm_of_ocaml bin/.technologic.eobjs/jsoo/dune__exe.wasmo
|
||||
wasm_of_ocaml bin/.technologic.eobjs/jsoo/dune__exe__Z.wasmo
|
||||
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 <<EOF
|
||||
> (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
|
||||
|
|
@ -0,0 +1 @@
|
|||
let x = 12
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(library
|
||||
(public_name foo.a)
|
||||
(name a))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(executable
|
||||
(name main)
|
||||
(libraries a)
|
||||
(modes wasm))
|
||||
|
|
@ -0,0 +1 @@
|
|||
let _ = A.x
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(lang dune 3.17)
|
||||
|
||||
(package (name foo))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Compilation of libraries with `public-names`
|
||||
|
||||
$ dune build
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 3.17)
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
(library
|
||||
(name inline_test)
|
||||
(modules inline_test)
|
||||
(inline_tests
|
||||
(modes wasm)
|
||||
(backend inline_test_backend)))
|
||||
|
||||
(library
|
||||
(name inline_test_backend)
|
||||
(modules inline_test_backend)
|
||||
(inline_tests.backend (generate_runner (echo ""))))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Run tests and inline tests within a sandbox in copy mode
|
||||
|
||||
$ dune runtest --sandbox=copy
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
(test
|
||||
(modes wasm)
|
||||
(name test))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
(executables
|
||||
(names technologic)
|
||||
(libraries js_of_ocaml x)
|
||||
(modes wasm)
|
||||
(wasm_of_ocaml
|
||||
(javascript_files runtime.js)))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
global.globalPrintFunction = function(x){
|
||||
console.log(x);
|
||||
}
|
||||
|
|
@ -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")
|
||||
|
|
@ -0,0 +1 @@
|
|||
let use_it = "use it"
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 3.17)
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
(library
|
||||
(name x)
|
||||
(libraries js_of_ocaml)
|
||||
(public_name x)
|
||||
(wasm_of_ocaml
|
||||
(flags (--pretty)) (wasm_files runtime.js runtime.wat))
|
||||
(foreign_stubs (language c) (names stubs)))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
|
||||
//Provides: jsPrint
|
||||
function jsPrint(x){
|
||||
globalThis.console.log(x);
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
(module
|
||||
(import "env" "unwrap" (func $unwrap (param (ref eq)) (result anyref)))
|
||||
(import "js" "jsPrint" (func $print (param anyref)))
|
||||
(func (export "jsPrint") (param $x (ref eq)) (result (ref eq))
|
||||
(call $print (call $unwrap (local.get $x)))
|
||||
(ref.i31 (i32.const 0)))
|
||||
)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
void jsPrint () { fprintf(stderr, "Unimplemented Javascript primitive myPrint!\n"); exit(1); }
|
||||
|
|
@ -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"
|
||||
|
|
@ -0,0 +1 @@
|
|||
let it = "it"
|
||||
|
|
@ -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 <<EOF
|
||||
> (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
|
||||
|
||||
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.
|
||||
|
||||
$ ! if dune exe bin/technologic.bc-for-jsoo ; then true ; else false ; fi 2> /dev/null
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
(executable
|
||||
(name main)
|
||||
(modes js wasm))
|
||||
|
||||
(env
|
||||
(js (wasm_of_ocaml (enabled_if false)))
|
||||
(wasm (js_of_ocaml (enabled_if false))))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 3.17)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
let () =
|
||||
match Sys.backend_type with
|
||||
Other typ -> print_endline typ
|
||||
| _ -> assert false
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
Building with different combinations of submodes
|
||||
|
||||
Compiling 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.
|
||||
|
||||
$ dune build --profile wasm
|
||||
$ node _build/default/main.bc.wasm.js
|
||||
wasm_of_ocaml
|
||||
$ dune build --profile wasm main.bc.js
|
||||
Error: Don't know how to build main.bc.js
|
||||
[1]
|
||||
|
||||
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
|
||||
|
|
@ -0,0 +1 @@
|
|||
let () = print_endline "a: ok"
|
||||
|
|
@ -0,0 +1 @@
|
|||
b: ok
|
||||
|
|
@ -0,0 +1 @@
|
|||
let () = print_endline "b: ok"
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
(tests
|
||||
(names a b)
|
||||
(modes wasm))
|
||||
|
||||
(env
|
||||
(_
|
||||
(wasm_of_ocaml
|
||||
(runtest_alias runtest-js)
|
||||
(compilation_mode whole_program))))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 3.17)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
tests stanza with wasmoo
|
||||
|
||||
$ dune build @default @runtest-js
|
||||
a: ok
|
||||
|
|
@ -0,0 +1 @@
|
|||
let () = print_endline "a: ok"
|
||||
|
|
@ -0,0 +1 @@
|
|||
b: ok
|
||||
|
|
@ -0,0 +1 @@
|
|||
let () = print_endline "b: ok"
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(tests
|
||||
(names a b)
|
||||
(wasm_of_ocaml (compilation_mode whole_program))
|
||||
(modes wasm))
|
||||
|
|
@ -0,0 +1 @@
|
|||
(lang dune 3.17)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
tests stanza with wasmoo
|
||||
|
||||
$ dune build @runtest
|
||||
a: ok
|
||||
Loading…
Add table
Add a link
Reference in a new issue