From 50502e8139fd1b62cb8f55b4a073089ded050543 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Tue, 18 Mar 2025 23:07:10 +0900 Subject: [PATCH 1/9] upgrade dune version to get WASM build --- analysis.opam | 5 +++-- compiler/jsoo/dune | 5 +++-- compiler/jsoo/jsoo_playground_main.ml | 14 ++++++-------- dune-project | 2 +- rescript.opam | 5 +++-- tools.opam | 5 +++-- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/analysis.opam b/analysis.opam index bebaa72055..228193d753 100644 --- a/analysis.opam +++ b/analysis.opam @@ -9,10 +9,11 @@ bug-reports: "https://github.com/rescript-lang/rescript-compiler/issues" depends: [ "ocaml" {>= "4.14"} "cppo" {= "1.8.0"} - "dune" + "dune" {>= "3.17"} + "odoc" {with-doc} ] build: [ - ["dune" "subst"] {pinned} + ["dune" "subst"] {dev} [ "dune" "build" diff --git a/compiler/jsoo/dune b/compiler/jsoo/dune index 5c514e5ef6..46c8b09df7 100644 --- a/compiler/jsoo/dune +++ b/compiler/jsoo/dune @@ -2,9 +2,10 @@ (executables (names jsoo_playground_main) - (modes js) + (modes js wasm) (enabled_if (= %{profile} browser)) (flags (:standard -w +a-4-9-40-42-44-45)) - (libraries core syntax ml js_of_ocaml)) + (libraries core syntax ml js_of_ocaml) + (preprocess (pps js_of_ocaml-ppx))) diff --git a/compiler/jsoo/jsoo_playground_main.ml b/compiler/jsoo/jsoo_playground_main.ml index 370f8177b3..bc04a94e6c 100644 --- a/compiler/jsoo/jsoo_playground_main.ml +++ b/compiler/jsoo/jsoo_playground_main.ml @@ -676,11 +676,9 @@ module Export = struct end let () = - export "rescript_compiler" - Js.Unsafe.( - obj - [| - ("api_version", inject @@ Js.string api_version); - ("version", inject @@ Js.string Bs_version.version); - ("make", inject @@ Export.make); - |]) + Js.export "rescript_compiler" + (object%js + val api_version = api_version + val version = Bs_version.version + method make = Export.make () + end) diff --git a/dune-project b/dune-project index 0b1dd88c9e..562f9bb81c 100644 --- a/dune-project +++ b/dune-project @@ -1,4 +1,4 @@ -(lang dune 2.3) +(lang dune 3.17) (name rescript) diff --git a/rescript.opam b/rescript.opam index 9a259d0737..8d66856c0a 100644 --- a/rescript.opam +++ b/rescript.opam @@ -14,10 +14,11 @@ depends: [ "cppo" {= "1.8.0"} "js_of_ocaml" {= "6.0.1"} "ounit2" {= "2.2.7"} - "dune" + "dune" {>= "3.17"} + "odoc" {with-doc} ] build: [ - ["dune" "subst"] {pinned} + ["dune" "subst"] {dev} [ "dune" "build" diff --git a/tools.opam b/tools.opam index 7858e8d131..48333848f1 100644 --- a/tools.opam +++ b/tools.opam @@ -10,10 +10,11 @@ depends: [ "ocaml" {>= "4.14"} "cppo" {= "1.8.0"} "analysis" - "dune" + "dune" {>= "3.17"} + "odoc" {with-doc} ] build: [ - ["dune" "subst"] {pinned} + ["dune" "subst"] {dev} [ "dune" "build" From ed13393a3eb795bc7ab3bda0c7f8515df29c8eb8 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Tue, 25 Mar 2025 05:26:19 +0900 Subject: [PATCH 2/9] suppress warnings in corrected way --- compiler/syntax/cli/res_cli.ml | 16 ++++++++-------- tests/syntax_benchmarks/Benchmark.ml | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/compiler/syntax/cli/res_cli.ml b/compiler/syntax/cli/res_cli.ml index d045b16753..572ddd95f3 100644 --- a/compiler/syntax/cli/res_cli.ml +++ b/compiler/syntax/cli/res_cli.ml @@ -26,19 +26,19 @@ *) module Color = struct (* use ANSI color codes, see https://en.wikipedia.org/wiki/ANSI_escape_code *) - type color = - | Black [@live] + type[@warning "-37"] color = + | Black | Red - | Green [@live] + | Green | Yellow - | Blue [@live] + | Blue | Magenta | Cyan - | White [@live] + | White - type style = + type[@warning "-37"] style = | FG of color (* foreground *) - | BG of color [@live] (* background *) + | BG of color (* background *) | Bold | Reset | Dim @@ -132,7 +132,7 @@ module Color = struct let term = try Sys.getenv "TERM" with Not_found -> "" in term <> "dumb" && term <> "" && isatty stderr - type setting = Auto [@live] | Always [@live] | Never [@live] + type[@warning "-37"] setting = Auto | Always | Never let setup = let first = ref true in diff --git a/tests/syntax_benchmarks/Benchmark.ml b/tests/syntax_benchmarks/Benchmark.ml index e947612513..e6e48aabaa 100644 --- a/tests/syntax_benchmarks/Benchmark.ml +++ b/tests/syntax_benchmarks/Benchmark.ml @@ -33,16 +33,16 @@ module Time : sig val now : unit -> t - val to_uint64 : t -> int64 [@@live] + val[@warning "-32"] to_uint64 : t -> int64 (* let of_uint64_ns ns = ns *) - val nanosecond : t [@@live] - val microsecond : t [@@live] - val millisecond : t [@@live] - val second : t [@@live] - val minute : t [@@live] - val hour : t [@@live] + val[@warning "-32"] nanosecond : t + val[@warning "-32"] microsecond : t + val[@warning "-32"] millisecond : t + val[@warning "-32"] second : t + val[@warning "-32"] minute : t + val[@warning "-32"] hour : t val zero : t From 0c2d016425f9ccf24ad4c92b6b5023134f5848f4 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Tue, 25 Mar 2025 06:15:02 +0900 Subject: [PATCH 3/9] fix permission issues --- scripts/copyExes.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/copyExes.js b/scripts/copyExes.js index feae5e9b76..b9ebe91cc3 100755 --- a/scripts/copyExes.js +++ b/scripts/copyExes.js @@ -24,10 +24,19 @@ function copyExe(dir, exe) { fs.rmSync(dest); } - fs.copyFileSync(src, dest); - - if (process.platform !== "win32") { - child_process.execSync(`strip ${dest}`); + let mode = 0o755; + if (fs.existsSync(dest)) { + mode = fs.statSync(dest).mode & 0o777; + fs.chmodSync(dest, mode | 0o200); // u+w + } + try { + fs.copyFileSync(src, dest); + if (process.platform !== "win32") { + fs.chmodSync(dest, mode | 0o200); // u+w + child_process.execSync(`strip ${dest}`); + } + } finally { + fs.chmodSync(dest, mode); } } From 2a053514b3f35d8bbebf24625fb06cf479467e3d Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Tue, 25 Mar 2025 06:15:17 +0900 Subject: [PATCH 4/9] format --- compiler/dune | 19 +++++++++++++++++-- compiler/ext/dune | 8 ++++++-- compiler/jsoo/dune | 3 ++- tests/syntax_benchmarks/Benchmark.ml | 14 +++++++------- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/compiler/dune b/compiler/dune index 101b4b8acf..7c5ba77749 100644 --- a/compiler/dune +++ b/compiler/dune @@ -1,5 +1,20 @@ -(dirs bsb bsb_exe bsb_helper bsb_helper_exe bsc cmij common core depends ext - frontend gentype jsoo js_parser ml syntax) +(dirs + bsb + bsb_exe + bsb_helper + bsb_helper_exe + bsc + cmij + common + core + depends + ext + frontend + gentype + jsoo + js_parser + ml + syntax) (env (dev diff --git a/compiler/ext/dune b/compiler/ext/dune index 8c9c936cbc..0896ec2c27 100644 --- a/compiler/ext/dune +++ b/compiler/ext/dune @@ -3,8 +3,12 @@ (wrapped false) (preprocess (action - (run %{bin:cppo} -V OCAML:%{ocaml_version} %{env:CPPO_FLAGS=} - %{input-file}))) + (run + %{bin:cppo} + -V + OCAML:%{ocaml_version} + %{env:CPPO_FLAGS=} + %{input-file}))) (flags (:standard -w +a-4-42-40-9-48-70)) (foreign_stubs diff --git a/compiler/jsoo/dune b/compiler/jsoo/dune index 46c8b09df7..209f9d9f05 100644 --- a/compiler/jsoo/dune +++ b/compiler/jsoo/dune @@ -8,4 +8,5 @@ (flags (:standard -w +a-4-9-40-42-44-45)) (libraries core syntax ml js_of_ocaml) - (preprocess (pps js_of_ocaml-ppx))) + (preprocess + (pps js_of_ocaml-ppx))) diff --git a/tests/syntax_benchmarks/Benchmark.ml b/tests/syntax_benchmarks/Benchmark.ml index e6e48aabaa..dc7093dbe9 100644 --- a/tests/syntax_benchmarks/Benchmark.ml +++ b/tests/syntax_benchmarks/Benchmark.ml @@ -33,16 +33,16 @@ module Time : sig val now : unit -> t - val[@warning "-32"] to_uint64 : t -> int64 + val [@warning "-32"] to_uint64 : t -> int64 (* let of_uint64_ns ns = ns *) - val[@warning "-32"] nanosecond : t - val[@warning "-32"] microsecond : t - val[@warning "-32"] millisecond : t - val[@warning "-32"] second : t - val[@warning "-32"] minute : t - val[@warning "-32"] hour : t + val [@warning "-32"] nanosecond : t + val [@warning "-32"] microsecond : t + val [@warning "-32"] millisecond : t + val [@warning "-32"] second : t + val [@warning "-32"] minute : t + val [@warning "-32"] hour : t val zero : t From b2720505647569a4091b5e89ad425acb6fcd4e25 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Tue, 25 Mar 2025 06:33:33 +0900 Subject: [PATCH 5/9] install js_of_ocaml-ppx --- dune-project | 2 ++ rescript.opam | 1 + 2 files changed, 3 insertions(+) diff --git a/dune-project b/dune-project index 562f9bb81c..6ed23e8da9 100644 --- a/dune-project +++ b/dune-project @@ -36,6 +36,8 @@ (= 1.8.0)) (js_of_ocaml (= 6.0.1)) + (js_of_ocaml-ppx + (= 6.0.1)) (ounit2 (= 2.2.7)) dune)) diff --git a/rescript.opam b/rescript.opam index 8d66856c0a..bf9e3e0539 100644 --- a/rescript.opam +++ b/rescript.opam @@ -13,6 +13,7 @@ depends: [ "ocaml-lsp-server" {with-dev-setup & = "1.22.0"} "cppo" {= "1.8.0"} "js_of_ocaml" {= "6.0.1"} + "js_of_ocaml-ppx" {= "6.0.1"} "ounit2" {= "2.2.7"} "dune" {>= "3.17"} "odoc" {with-doc} From 5d32be76cd9f57af74afa8b7338ead94c76b99d9 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Tue, 25 Mar 2025 12:56:33 +0900 Subject: [PATCH 6/9] fix --- compiler/jsoo/jsoo_playground_main.ml | 2 -- dune-project | 2 ++ rescript.opam | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/compiler/jsoo/jsoo_playground_main.ml b/compiler/jsoo/jsoo_playground_main.ml index bc04a94e6c..d1de5cad1c 100644 --- a/compiler/jsoo/jsoo_playground_main.ml +++ b/compiler/jsoo/jsoo_playground_main.ml @@ -54,8 +54,6 @@ let api_version = "5" module Js = Js_of_ocaml.Js -let export (field : string) v = Js.Unsafe.set Js.Unsafe.global field v - module Lang = struct type t = Res diff --git a/dune-project b/dune-project index 6ed23e8da9..eca2445010 100644 --- a/dune-project +++ b/dune-project @@ -38,6 +38,8 @@ (= 6.0.1)) (js_of_ocaml-ppx (= 6.0.1)) + (wasm_of_ocaml-compiler + (= 6.0.1)) (ounit2 (= 2.2.7)) dune)) diff --git a/rescript.opam b/rescript.opam index bf9e3e0539..ac621eee5e 100644 --- a/rescript.opam +++ b/rescript.opam @@ -14,6 +14,7 @@ depends: [ "cppo" {= "1.8.0"} "js_of_ocaml" {= "6.0.1"} "js_of_ocaml-ppx" {= "6.0.1"} + "wasm_of_ocaml-compiler" {= "6.0.1"} "ounit2" {= "2.2.7"} "dune" {>= "3.17"} "odoc" {with-doc} From e902dda32544ef9c357cf1f981cb2b7fc47100c1 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 02:26:36 +0900 Subject: [PATCH 7/9] fix playground test --- playground/playground_test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/playground/playground_test.js b/playground/playground_test.js index 98807109cf..be5cc1df71 100644 --- a/playground/playground_test.js +++ b/playground/playground_test.js @@ -1,4 +1,7 @@ -require("./compiler.js") +// Playground bundle is UMD module +// It uses `module.exports` in current context, or fallback to `globalThis` +const { rescript_compiler } = require("./compiler.js") + require("./packages/compiler-builtins/cmij.js") require("./packages/@rescript/react/cmij.js") From ebd7b1ed0d23b37b52350a6a9399a83a1bc73340 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 20:30:49 +0900 Subject: [PATCH 8/9] manage dependency list in opam template --- dune-project | 28 +--------------------------- rescript.opam | 27 ++++++++++++++------------- rescript.opam.template | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 40 deletions(-) create mode 100644 rescript.opam.template diff --git a/dune-project b/dune-project index eca2445010..61fbc62cd2 100644 --- a/dune-project +++ b/dune-project @@ -16,33 +16,7 @@ (package (name rescript) - (synopsis "ReScript compiler") - (depends - (ocaml - (>= 4.14)) - (ocamlformat - (and - :with-test - (= 0.27.0))) - (yojson - (and - :with-test - (= 2.2.2))) - (ocaml-lsp-server - (and - :with-dev-setup - (= 1.22.0))) - (cppo - (= 1.8.0)) - (js_of_ocaml - (= 6.0.1)) - (js_of_ocaml-ppx - (= 6.0.1)) - (wasm_of_ocaml-compiler - (= 6.0.1)) - (ounit2 - (= 2.2.7)) - dune)) + (synopsis "ReScript compiler")) (package (name analysis) diff --git a/rescript.opam b/rescript.opam index ac621eee5e..6f5345c73d 100644 --- a/rescript.opam +++ b/rescript.opam @@ -6,19 +6,6 @@ authors: ["Hongbo Zhang "] license: "LGPL-3.0-or-later" homepage: "https://github.com/rescript-lang/rescript-compiler" bug-reports: "https://github.com/rescript-lang/rescript-compiler/issues" -depends: [ - "ocaml" {>= "4.14"} - "ocamlformat" {with-test & = "0.27.0"} - "yojson" {with-test & = "2.2.2"} - "ocaml-lsp-server" {with-dev-setup & = "1.22.0"} - "cppo" {= "1.8.0"} - "js_of_ocaml" {= "6.0.1"} - "js_of_ocaml-ppx" {= "6.0.1"} - "wasm_of_ocaml-compiler" {= "6.0.1"} - "ounit2" {= "2.2.7"} - "dune" {>= "3.17"} - "odoc" {with-doc} -] build: [ ["dune" "subst"] {dev} [ @@ -33,3 +20,17 @@ build: [ "@doc" {with-doc} ] ] +depends: [ + "ocaml" {>= "4.14"} + "ocamlformat" {with-test & = "0.27.0"} + "yojson" {with-test & = "2.2.2"} + "ocaml-lsp-server" {with-dev-setup & = "1.22.0"} + "cppo" {= "1.8.0"} + "ounit2" {= "2.2.7"} + "dune" {>= "3.17"} + "odoc" {with-doc} + # Dependencies that could be broken on Windows runners + "js_of_ocaml" {= "6.0.1" & os != "win32"} + "js_of_ocaml-ppx" {= "6.0.1" & os != "win32"} + "wasm_of_ocaml-compiler" {= "6.0.1" & os != "win32"} +] diff --git a/rescript.opam.template b/rescript.opam.template new file mode 100644 index 0000000000..be3ee9d345 --- /dev/null +++ b/rescript.opam.template @@ -0,0 +1,15 @@ +depends: [ + "ocaml" {>= "4.14"} + "cppo" {= "1.8.0"} + "dune" {>= "3.17"} + "ocamlformat" {with-test & = "0.27.0"} + "yojson" {with-test & = "2.2.2"} + "ounit2" {with-test & = "2.2.7"} + "odoc" {with-doc} + "ocaml-lsp-server" {with-dev-setup & = "1.22.0"} + + # Test dependencies that would be broken on Windows runners + "js_of_ocaml" {os != "win32" & with-test & = "6.0.1"} + "js_of_ocaml-ppx" {os != "win32" & with-test & = "6.0.1"} + "wasm_of_ocaml-compiler" {os != "win32" & with-test & = "6.0.1"} +] From 771811501b0997e0661cbf92d895a6f27fcdf233 Mon Sep 17 00:00:00 2001 From: Hyeseong Kim Date: Wed, 26 Mar 2025 20:54:09 +0900 Subject: [PATCH 9/9] fix opam cache key to use opam --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e416ec37a..98a432c13d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -152,7 +152,7 @@ jobs: # matrix.ocaml_compiler may contain commas - name: Get OPAM cache key shell: bash - run: echo "opam_cache_key=opam-env-v7-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}" | sed 's/,/-/g' >> $GITHUB_ENV + run: echo "opam_cache_key=opam-env-v7-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('*.opam') }}" | sed 's/,/-/g' >> $GITHUB_ENV - name: Restore OPAM environment id: cache-opam-env @@ -249,7 +249,7 @@ jobs: id: compiler-build-state-key shell: bash run: | - echo "value=compiler-build-state-v1-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}" \ + echo "value=compiler-build-state-v1-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('*.opam') }}" \ | sed 's/,/-/g' >> "$GITHUB_OUTPUT" - name: Restore compiler build state