diff --git a/.github/workflows/build-wasm_of_ocaml.yml b/.github/workflows/build-wasm_of_ocaml.yml index 2f1d394e01..fc6e57342b 100644 --- a/.github/workflows/build-wasm_of_ocaml.yml +++ b/.github/workflows/build-wasm_of_ocaml.yml @@ -33,6 +33,11 @@ jobs: separate_compilation: true jane_street_tests: false all_jane_street_tests: false + - os: windows-latest + ocaml-compiler: "5.2" + separate_compilation: true + jane_street_tests: true + all_jane_street_tests: false - os: ubuntu-latest ocaml-compiler: "5.2" separate_compilation: true @@ -48,7 +53,7 @@ jobs: steps: - name: Set git to use LF - if: ${{ matrix.os == 'windows-latest' && matrix.ocaml-compiler < 5.2 }} + if: ${{ matrix.os == 'windows-latest' }} run: | git config --global core.autocrlf false git config --global core.eol lf @@ -57,7 +62,7 @@ jobs: - name: Checkout tree uses: actions/checkout@v4 with: - path: wasm_of_ocaml + path: w - name: Checkout Jane Street opam repository if: matrix.jane_street_tests @@ -65,7 +70,7 @@ jobs: with: repository: janestreet/opam-repository ref: 41c89c7824533f6b63cc5b6d75e6ddb1441d1520 - path: janestreet/opam-repository + path: j/opam-repository - name: Set-up Node.js uses: actions/setup-node@v4 @@ -86,16 +91,25 @@ jobs: # It's faster to use a cached version run: opam install --fake binaryen-bin + # Work-around a race between reinstalling mingw-w64-shims + # (because of conf-pkg-config optional dep) and installing other + # packages that implicitly depend on mingw-w64-shims. + - run: opam install conf-pkg-config conf-mingw-w64-gcc-i686 + if: runner.os == 'Windows' + + - name: Pin dune + run: opam pin add -n dune https://github.com/vouillon/dune.git#inline-tests-wasm + - name: Pin wasm_of_ocaml - working-directory: ./wasm_of_ocaml - run: opam pin -n --with-version `< VERSION` . + working-directory: ./w + run: opam pin . -n --with-version dev - name: Checkout Jane Street packages if: matrix.jane_street_tests run: | - opam repo add js janestreet/opam-repository + opam repo add js j/opam-repository opam install opam-format ocamlfind dune graphics cmdliner - opam exec -- ocaml wasm_of_ocaml/tools/ci_setup.ml + opam exec -- dune exec --root w tools/ci_setup.exe j - name: Pin Jane Street packages if: ${{ ! matrix.jane_street_tests }} @@ -106,86 +120,88 @@ jobs: opam pin add -n ppx_expect.v0.16.1 https://github.com/ocaml-wasm/ppx_expect.git#wasm - name: Install wasm_of_ocaml and its test dependencies - working-directory: ./wasm_of_ocaml + working-directory: ./w run: | - opam install `basename -s .opam *.opam` num cohttp-lwt-unix ppx_expect cstruct + opam install . + opam install num cohttp-lwt-unix ppx_expect cstruct uucp - name: Run tests if: ${{ matrix.separate_compilation }} - working-directory: ./wasm_of_ocaml + working-directory: ./w run: opam exec -- dune build @runtest-wasm - name: Run tests with CPS effects if: ${{ matrix.ocaml-compiler >= '5.' && matrix.separate_compilation }} - working-directory: ./wasm_of_ocaml + working-directory: ./w run: opam exec -- dune build @runtest-wasm --profile with-effects - name: Run Base tests - if: matrix.all_jane_street_tests - working-directory: ./janestreet/lib/base + if: ${{ matrix.all_jane_street_tests || matrix.os == 'windows-latest' }} + working-directory: ./j/lib/base run: opam exec -- dune runtest - name: Run Base bigstring tests if: matrix.all_jane_street_tests - working-directory: ./janestreet/lib/base_bigstring + working-directory: ./j/lib/base_bigstring run: opam exec -- dune runtest - name: Run Core tests if: matrix.all_jane_street_tests - working-directory: ./janestreet/lib/core + working-directory: ./j/lib/core run: opam exec -- dune runtest - name: Run Bignum tests - if: matrix.all_jane_street_tests - working-directory: ./janestreet/lib/bignum + if: ${{ matrix.all_jane_street_tests || matrix.os == 'windows-latest' }} + working-directory: ./j/lib/bignum run: opam exec -- dune runtest - name: Run Bin_prot tests + # tests fails on windows if: matrix.all_jane_street_tests - working-directory: ./janestreet/lib/bin_prot + working-directory: ./j/lib/bin_prot run: opam exec -- dune runtest - name: Run String_dict tests if: matrix.all_jane_street_tests - working-directory: ./janestreet/lib/string_dict + working-directory: ./j/lib/string_dict run: opam exec -- dune runtest - name: Run Zarith tests if: matrix.all_jane_street_tests - working-directory: ./janestreet/lib/zarith_stubs_js + working-directory: ./j/lib/zarith_stubs_js run: opam exec -- dune runtest - name: Run Virtual_dom tests if: matrix.all_jane_street_tests - working-directory: ./janestreet/lib/virtual_dom + working-directory: ./j/lib/virtual_dom run: opam exec -- dune runtest - name: Run Bonsai tests if: matrix.all_jane_street_tests - working-directory: ./janestreet/lib/bonsai_test + working-directory: ./j/lib/bonsai_test run: opam exec -- dune runtest - name: Run Bonsai web tests if: matrix.all_jane_street_tests - working-directory: ./janestreet/lib/bonsai_web_test + working-directory: ./j/lib/bonsai_web_test run: opam exec -- dune runtest - name: Run Bonsai web components' tests if: matrix.all_jane_street_tests - working-directory: ./janestreet/lib/bonsai_web_components + working-directory: ./j/lib/bonsai_web_components run: opam exec -- dune runtest - name: Run Bonsai tests (release profile) if: ${{ ! matrix.separate_compilation }} - working-directory: ./janestreet/lib/bonsai_test + working-directory: ./j/lib/bonsai_test run: opam exec -- dune runtest --profile release - name: Run Bonsai web tests (release profile) if: ${{ ! matrix.separate_compilation }} - working-directory: ./janestreet/lib/bonsai_web_test + working-directory: ./j/lib/bonsai_web_test run: opam exec -- dune runtest --profile release - name: Run Bonsai web components' tests (release profile) if: ${{ ! matrix.separate_compilation }} - working-directory: ./janestreet/lib/bonsai_web_components + working-directory: ./j/lib/bonsai_web_components run: opam exec -- dune runtest --profile release diff --git a/CHANGES.md b/CHANGES.md index 6544e2495e..4908bfeaf2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -12,6 +12,7 @@ * Compiler/Runtime: Make resuming a continuation more efficient in js (#1765) * Lib: Add other textMetrics property (#1784) * Misc: move tests to OCaml 5.3 +* Test: run wasm tests on windows ## Bug fixes * Fix small bug in global data flow analysis (#1768) diff --git a/compiler/lib-wasm/link.ml b/compiler/lib-wasm/link.ml index d043d0833e..b5822d31ea 100644 --- a/compiler/lib-wasm/link.ml +++ b/compiler/lib-wasm/link.ml @@ -688,12 +688,7 @@ let remove_directory path = with Sys_error _ -> () let gen_dir dir f = - let d_tmp = - Filename.temp_file_name - ~temp_dir:(Filename.dirname dir) - (Filename.basename dir) - ".tmp" - in + let d_tmp = Filename.temp_file_name ~temp_dir:(Filename.dirname dir) "assets" ".tmp" in try let res = f d_tmp in remove_directory dir; diff --git a/compiler/tests-jsoo/dune b/compiler/tests-jsoo/dune index 26f79c9284..ebc441b217 100644 --- a/compiler/tests-jsoo/dune +++ b/compiler/tests-jsoo/dune @@ -1,5 +1,5 @@ (library - (name jsoo_testsuite_latest) + (name j__latest) (modules test_io test_floats) (libraries unix compiler-libs.common js_of_ocaml-compiler) (enabled_if @@ -10,7 +10,7 @@ (pps ppx_expect))) (library - (name jsoo_testsuite_compression) + (name j__comp) (modules test_marshal_compressed) (libraries unix compiler-libs.common js_of_ocaml-compiler) (enabled_if @@ -21,7 +21,7 @@ (pps ppx_expect))) (library - (name jsoo_testsuite_parsing) + (name j__parsing) (modules test_parsing calc_parser calc_lexer) (libraries unix compiler-libs.common js_of_ocaml-compiler) (enabled_if @@ -32,7 +32,7 @@ (pps ppx_expect))) (library - (name jsoo_testsuite) + (name j__common) (modules (:standard \ diff --git a/compiler/tests-jsoo/lib-effects/dune b/compiler/tests-jsoo/lib-effects/dune index 66df040883..d2d8f835cd 100644 --- a/compiler/tests-jsoo/lib-effects/dune +++ b/compiler/tests-jsoo/lib-effects/dune @@ -5,7 +5,7 @@ (:standard --enable effects))))) (library - (name jsoo_testsuite_effect) + (name j__effect) (enabled_if (>= %{ocaml_version} 5)) (inline_tests diff --git a/dune-project b/dune-project index 1cb47d81d2..9a9aa2c405 100644 --- a/dune-project +++ b/dune-project @@ -146,6 +146,7 @@ (ppxlib (>= 0.15.0)) (re :with-test) (cmdliner (>= 1.1.0)) + (opam-format :with-test) (sedlex (>= 2.3)) menhir menhirLib diff --git a/lib/deriving_json/tests/dune b/lib/deriving_json/tests/dune index c1e0147b3d..db333a5553 100644 --- a/lib/deriving_json/tests/dune +++ b/lib/deriving_json/tests/dune @@ -1,5 +1,5 @@ (library - (name deriving_expect_tests) + (name j__deriving) (libraries unix js_of_ocaml js_of_ocaml.deriving) (inline_tests (modes js wasm)) diff --git a/lib/tests/test_css_angle.ml b/lib/tests/css_a.ml similarity index 100% rename from lib/tests/test_css_angle.ml rename to lib/tests/css_a.ml diff --git a/lib/tests/test_css_color.ml b/lib/tests/css_c.ml similarity index 100% rename from lib/tests/test_css_color.ml rename to lib/tests/css_c.ml diff --git a/lib/tests/test_css_length.ml b/lib/tests/css_l.ml similarity index 100% rename from lib/tests/test_css_length.ml rename to lib/tests/css_l.ml diff --git a/lib/tests/dune.inc b/lib/tests/dune.inc index 85b9beb929..3b7b71c3e9 100644 --- a/lib/tests/dune.inc +++ b/lib/tests/dune.inc @@ -1,139 +1,139 @@ (library - ;; lib/tests/test_css_angle.ml - (name test_css_angle_75) + ;; lib/tests/css_a.ml + (name css_a_75) (enabled_if true) - (modules test_css_angle) + (modules css_a) (libraries js_of_ocaml unix) (inline_tests (modes js wasm)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_css_color.ml - (name test_css_color_75) + ;; lib/tests/css_c.ml + (name css_c_75) (enabled_if true) - (modules test_css_color) + (modules css_c) (libraries js_of_ocaml unix) (inline_tests (modes js wasm)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_css_length.ml - (name test_css_length_75) + ;; lib/tests/css_l.ml + (name css_l_75) (enabled_if true) - (modules test_css_length) + (modules css_l) (libraries js_of_ocaml unix) (inline_tests (modes js wasm)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_fun_call.ml - (name test_fun_call_75) + ;; lib/tests/fcall.ml + (name fcall_75) (enabled_if (<> %{profile} with-effects)) - (modules test_fun_call) + (modules fcall) (libraries js_of_ocaml unix) (inline_tests (modes js)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_fun_call_2.ml - (name test_fun_call_2_75) + ;; lib/tests/fcall2.ml + (name fcall2_75) (enabled_if true) - (modules test_fun_call_2) + (modules fcall2) (libraries js_of_ocaml unix) (inline_tests (modes js wasm)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_json.ml - (name test_json_75) + ;; lib/tests/fserr.ml + (name fserr_75) (enabled_if true) - (modules test_json) + (modules fserr) (libraries js_of_ocaml unix) - (inline_tests (modes js)) + (inline_tests (modes js wasm)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_nodejs_filesystem_errors.ml - (name test_nodejs_filesystem_errors_75) + ;; lib/tests/json.ml + (name json_75) (enabled_if true) - (modules test_nodejs_filesystem_errors) + (modules json) (libraries js_of_ocaml unix) - (inline_tests (modes js wasm)) + (inline_tests (modes js)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_poly_compare.ml - (name test_poly_compare_75) + ;; lib/tests/poly_comp.ml + (name poly_comp_75) (enabled_if true) - (modules test_poly_compare) + (modules poly_comp) (libraries js_of_ocaml unix) (inline_tests (modes js)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_poly_equal.ml - (name test_poly_equal_75) + ;; lib/tests/poly_eq.ml + (name poly_eq_75) (enabled_if true) - (modules test_poly_equal) + (modules poly_eq) (libraries js_of_ocaml unix) (inline_tests (modes js wasm)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_regexp.ml - (name test_regexp_75) + ;; lib/tests/regexp.ml + (name regexp_75) (enabled_if true) - (modules test_regexp) + (modules regexp) (libraries js_of_ocaml unix) (inline_tests (modes js wasm)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_sys.ml - (name test_sys_75) + ;; lib/tests/sys.ml + (name sys_75) (enabled_if (>= %{ocaml_version} 5)) - (modules test_sys) + (modules sys) (libraries js_of_ocaml unix) (inline_tests (modes js)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_typed_array.ml - (name test_typed_array_75) + ;; lib/tests/typedarray.ml + (name typedarray_75) (enabled_if true) - (modules test_typed_array) + (modules typedarray) (libraries js_of_ocaml unix) (inline_tests (modes js wasm)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_unsafe_set_get.ml - (name test_unsafe_set_get_75) + ;; lib/tests/uget_uset.ml + (name uget_uset_75) (enabled_if true) - (modules test_unsafe_set_get) + (modules uget_uset) (libraries js_of_ocaml unix) (inline_tests (modes js wasm)) (preprocess (pps ppx_js_internal ppx_expect))) (library - ;; lib/tests/test_url.ml - (name test_url_75) + ;; lib/tests/url.ml + (name url_75) (enabled_if true) - (modules test_url) + (modules url) (libraries js_of_ocaml unix) (inline_tests (modes js wasm)) (preprocess diff --git a/lib/tests/test_fun_call.ml b/lib/tests/fcall.ml similarity index 100% rename from lib/tests/test_fun_call.ml rename to lib/tests/fcall.ml diff --git a/lib/tests/test_fun_call_2.ml b/lib/tests/fcall2.ml similarity index 100% rename from lib/tests/test_fun_call_2.ml rename to lib/tests/fcall2.ml diff --git a/lib/tests/test_nodejs_filesystem_errors.ml b/lib/tests/fserr.ml similarity index 100% rename from lib/tests/test_nodejs_filesystem_errors.ml rename to lib/tests/fserr.ml diff --git a/lib/tests/gen-rules/gen.ml b/lib/tests/gen-rules/gen.ml index 980e2f0cc8..d4b2f39578 100644 --- a/lib/tests/gen-rules/gen.ml +++ b/lib/tests/gen-rules/gen.ml @@ -53,9 +53,9 @@ type enabled_if = | Any let enabled_if = function - | "test_sys" -> GE5 - | "test_fun_call" -> No_effects_not_wasm - | "test_json" | "test_poly_compare" -> Not_wasm + | "sys" -> GE5 + | "fcall" -> No_effects_not_wasm + | "json" | "poly_comp" -> Not_wasm | _ -> Any let () = diff --git a/lib/tests/test_json.ml b/lib/tests/json.ml similarity index 100% rename from lib/tests/test_json.ml rename to lib/tests/json.ml diff --git a/lib/tests/test_poly_compare.ml b/lib/tests/poly_comp.ml similarity index 100% rename from lib/tests/test_poly_compare.ml rename to lib/tests/poly_comp.ml diff --git a/lib/tests/test_poly_equal.ml b/lib/tests/poly_eq.ml similarity index 96% rename from lib/tests/test_poly_equal.ml rename to lib/tests/poly_eq.ml index 0f6cf095ea..f96aee814b 100644 --- a/lib/tests/test_poly_equal.ml +++ b/lib/tests/poly_eq.ml @@ -24,7 +24,7 @@ let%expect_test "poly equal" = assert (obj1 = obj2); assert (not (obj1 = obj2)); () -[@@expect.uncaught_exn {| "Assert_failure lib/tests/test_poly_equal.ml:24:2" |}] +[@@expect.uncaught_exn {| "Assert_failure lib/tests/poly_eq.ml:24:2" |}] let%expect_test "poly equal neg" = let obj1 = Js.Unsafe.obj [||] in diff --git a/lib/tests/test_regexp.ml b/lib/tests/regexp.ml similarity index 100% rename from lib/tests/test_regexp.ml rename to lib/tests/regexp.ml diff --git a/lib/tests/test_sys.ml b/lib/tests/sys.ml similarity index 100% rename from lib/tests/test_sys.ml rename to lib/tests/sys.ml diff --git a/lib/tests/test_typed_array.ml b/lib/tests/typedarray.ml similarity index 100% rename from lib/tests/test_typed_array.ml rename to lib/tests/typedarray.ml diff --git a/lib/tests/test_unsafe_set_get.ml b/lib/tests/uget_uset.ml similarity index 100% rename from lib/tests/test_unsafe_set_get.ml rename to lib/tests/uget_uset.ml diff --git a/lib/tests/test_url.ml b/lib/tests/url.ml similarity index 100% rename from lib/tests/test_url.ml rename to lib/tests/url.ml diff --git a/runtime/wasm/dune b/runtime/wasm/dune index 90422c0f9d..3bbc0a5fc6 100644 --- a/runtime/wasm/dune +++ b/runtime/wasm/dune @@ -54,24 +54,19 @@ args (glob_files *.wat)) (action - (progn - (bash - "which wasm-merge > /dev/null || (echo 'Error: Binaryen tools not found in the PATH'; false)") - (bash - "wasm-merge --version | grep -q 'version \\(11[89]\\|1[2-9][0-9]\\)' || (echo 'Error: Binaryen version 118 or greater is currently required'; false)") - (run - wasm-merge - -g - --enable-gc - --enable-exception-handling - --enable-reference-types - --enable-tail-call - --enable-strings - --enable-multivalue - --enable-bulk-memory - %{read-lines:args} - -o - %{target})))) + (run + wasm-merge + -g + --enable-gc + --enable-exception-handling + --enable-reference-types + --enable-tail-call + --enable-strings + --enable-multivalue + --enable-bulk-memory + %{read-lines:args} + -o + %{target}))) (rule (target args) diff --git a/runtime/wasm/runtime.js b/runtime/wasm/runtime.js index 00adc8f4a6..f41982a08e 100644 --- a/runtime/wasm/runtime.js +++ b/runtime/wasm/runtime.js @@ -397,6 +397,7 @@ channel_list, exit: (n) => isNode && process.exit(n), argv: () => (isNode ? process.argv.slice(1) : ["a.out"]), + on_windows: () => isNode && process.platform === "win32", getenv: (n) => (isNode ? process.env[n] : null), system: (c) => { var res = require("node:child_process").spawnSync(c, { diff --git a/runtime/wasm/sys.wat b/runtime/wasm/sys.wat index b397c89a82..dcb7c0b813 100644 --- a/runtime/wasm/sys.wat +++ b/runtime/wasm/sys.wat @@ -36,6 +36,7 @@ (func $caml_raise_sys_error (param (ref eq)))) (import "fail" "caml_raise_not_found" (func $caml_raise_not_found)) (import "bindings" "argv" (func $argv (result (ref extern)))) + (import "bindings" "on_windows" (func $on_windows (result i32))) (import "bindings" "system" (func $system (param anyref) (result (ref eq)))) (import "bindings" "getenv" (func $getenv (param anyref) (result anyref))) (import "bindings" "time" (func $time (result f64))) @@ -135,27 +136,27 @@ (func (export "caml_sys_const_ostype_unix") (param (ref eq)) (result (ref eq)) - ;; ZZZ - (ref.i31 (i32.const 1))) + (ref.i31 (i32.eqz (call $on_windows)))) (func (export "caml_sys_const_ostype_win32") (param (ref eq)) (result (ref eq)) - ;; ZZZ - (ref.i31 (i32.const 0))) + (ref.i31 (call $on_windows))) (func (export "caml_sys_const_ostype_cygwin") (param (ref eq)) (result (ref eq)) - ;; ZZZ (ref.i31 (i32.const 0))) (data $Unix "Unix") + (data $Win32 "Win32") (func (export "caml_sys_get_config") (param (ref eq)) (result (ref eq)) - ;; ZZZ - ;; (call $log_js (string.const "caml_sys_get_config")) (array.new_fixed $block 4 (ref.i31 (i32.const 0)) - (array.new_data $string $Unix (i32.const 0) (i32.const 4)) + (if (result (ref eq)) (call $on_windows) + (then + (array.new_data $string $Win32 (i32.const 0) (i32.const 5))) + (else + (array.new_data $string $Unix (i32.const 0) (i32.const 4)))) (ref.i31 (i32.const 32)) (ref.i31 (i32.const 0)))) diff --git a/runtime/wasm/unix.wat b/runtime/wasm/unix.wat index 797a3b3f3f..4740b129ee 100644 --- a/runtime/wasm/unix.wat +++ b/runtime/wasm/unix.wat @@ -99,4 +99,11 @@ (func $unix_inet_addr_of_string (export "unix_inet_addr_of_string") (param (ref eq)) (result (ref eq)) (ref.i31 (i32.const 0))) + (export "caml_unix_filedescr_of_fd" (func $unix_filedescr_of_fd)) + (func $unix_filedescr_of_fd (export "unix_filedescr_of_fd") + (param (ref eq)) (result (ref eq)) + (local.get 0)) + (func $unix_cleanup (export "caml_unix_cleanup") + (param (ref eq)) (result (ref eq)) + (ref.i31 (i32.const 0))) ) diff --git a/tools/ci_setup.ml b/tools/ci_setup.ml index e35336f6ad..c8396a4d74 100644 --- a/tools/ci_setup.ml +++ b/tools/ci_setup.ml @@ -1,20 +1,19 @@ -#use "topfind" - -#require "opam-format" - -#require "unix" - -#require "str" - module StringSet = Set.Make (String) (****) -let repo = "janestreet/opam-repository/packages" +let root = + match Sys.argv with + | [| _; root |] -> root + | _ -> "janestreet" + +let repo = Filename.concat root "opam-repository/packages" let roots = [ "bonsai_web_components"; "string_dict"; "ppx_html" ] -let omitted_others = StringSet.of_list [ "cohttp-async"; "cohttp"; "uri"; "uri-sexp" ] +let omitted_others = + StringSet.of_list + [ "cohttp-async"; "cohttp"; "uri"; "uri-sexp"; "cstruct"; "uucp"; "odoc-parser" ] let omitted_js = StringSet.of_list [ "sexplib0" ] @@ -137,7 +136,7 @@ let read_opam_file filename = ~pos:{ filename; start = 0, 0; stop = 0, 0 } (OpamParser.FullPos.file (Filename.concat (Filename.concat repo filename) "opam")) -let dependencies (_, { OpamFile.OPAM.depends }) = +let dependencies (_, { OpamFile.OPAM.depends; _ }) = let open OpamFormula in depends |> map (fun (nm, _) -> Atom (nm, None)) @@ -165,21 +164,18 @@ let rec traverse visited p = let is_forked p = StringSet.mem p forked_packages -let exec_async ~delay cmd = - let p = - Unix.open_process_out (Printf.sprintf "sleep %f; %s" (float delay /. 10.) cmd) - in +let exec_async cmd = + let p = Unix.open_process_out cmd in fun () -> ignore (Unix.close_process_out p) let ( let* ) (f : unit -> 'a) (g : 'a -> unit -> 'b) : unit -> 'b = fun () -> g (f ()) () let sync_exec f l = - let l = List.mapi f l in + let l = List.map f l in List.iter (fun f -> f ()) l -let pin delay nm = +let pin nm = exec_async - ~delay (Printf.sprintf "opam pin add -n %s https://github.com/ocaml-wasm/%s.git#wasm-v0.18" nm @@ -191,43 +187,37 @@ let install_others others = let others = StringSet.elements (StringSet.diff others omitted_others) in ignore (Sys.command ("opam install -y " ^ String.concat " " others)) -let clone delay ?branch ?(depth = 1) nm src = +let clone ?branch ?(depth = 1) nm src = exec_async - ~delay (Printf.sprintf - "git clone -q --depth %d %s%s janestreet/lib/%s" + "git clone -q --depth %d %s%s %s/lib/%s" depth (match branch with | None -> "" | Some b -> Printf.sprintf "-b %s " b) src + root nm) -let clone' delay ?branch ?commit nm src = +let clone' ?branch ?commit nm src = match commit with - | None -> clone delay ?branch nm src + | None -> clone ?branch nm src | Some commit -> - let* () = clone delay ?branch ~depth:100 nm src in - exec_async - ~delay:0 - (Printf.sprintf "cd janestreet/lib/%s && git checkout -b wasm %s" nm commit) + let* () = clone ?branch ~depth:100 nm src in + exec_async (Printf.sprintf "cd %s/lib/%s && git checkout -b wasm %s" root nm commit) let () = let write f contents = Out_channel.( - with_open_bin (Filename.concat "janestreet" f) - @@ fun ch -> output_string ch contents) + with_open_bin (Filename.concat root f) @@ fun ch -> output_string ch contents) in let copy f f' = - let contents = - In_channel.(with_open_bin (Filename.concat "wasm_of_ocaml" f) @@ input_all) - in + let contents = In_channel.(with_open_bin (Filename.concat "w" f) @@ input_all) in Out_channel.( - with_open_bin (Filename.concat "janestreet" f') - @@ fun ch -> output_string ch contents) + with_open_bin (Filename.concat root f') @@ fun ch -> output_string ch contents) in write "dune-workspace" dune_workspace; - Unix.mkdir "janestreet/node_wrapper" 0o755; + Unix.mkdir (Filename.concat root "node_wrapper") 0o755; List.iter (fun (f, contents) -> write f contents) node_wrapper; copy "tools/node_wrapper.ml" "node_wrapper/node_wrapper.ml" @@ -238,9 +228,9 @@ let () = in pin_packages (); install_others others; - sync_exec (fun i () -> clone i "ocaml-uri" "https://github.com/mirage/ocaml-uri") [ () ]; + sync_exec (fun () -> clone "ocaml-uri" "https://github.com/mirage/ocaml-uri") [ () ]; sync_exec - (fun i nm -> + (fun nm -> let branch = if is_forked nm then Some "wasm-v0.18" else None in let commit = if is_forked nm @@ -253,7 +243,6 @@ let () = String.sub tar_file 0 (String.index tar_file '.')) in clone' - i ?branch ?commit nm @@ -267,7 +256,7 @@ let () = List.iter (fun (dir, patch) -> let ch = - Unix.open_process_out (Printf.sprintf "cd janestreet/lib/%s && patch -p 1" dir) + Unix.open_process_out (Printf.sprintf "cd %s/lib/%s && patch -p 1" root dir) in output_string ch patch; ignore (Unix.close_process_out ch)) diff --git a/tools/dune b/tools/dune index 7532203a08..f5589b29cc 100644 --- a/tools/dune +++ b/tools/dune @@ -1,3 +1,9 @@ (executable (name node_wrapper) + (modules node_wrapper) (libraries unix)) + +(executable + (name ci_setup) + (modules ci_setup) + (libraries opam-format unix)) diff --git a/wasm_of_ocaml-compiler.opam b/wasm_of_ocaml-compiler.opam index b145d310e0..bcb3f21403 100644 --- a/wasm_of_ocaml-compiler.opam +++ b/wasm_of_ocaml-compiler.opam @@ -20,6 +20,7 @@ depends: [ "ppxlib" {>= "0.15.0"} "re" {with-test} "cmdliner" {>= "1.1.0"} + "opam-format" {with-test} "sedlex" {>= "2.3"} "menhir" "menhirLib"