Skip to content

Commit 3f06468

Browse files
authored
Upgrade dune version to get WASM binary (#7349)
* upgrade dune version to get WASM build * suppress warnings in corrected way * fix permission issues * format * install js_of_ocaml-ppx * fix * fix playground test * manage dependency list in opam template * fix opam cache key to use opam
1 parent 20d644e commit 3f06468

File tree

14 files changed

+105
-77
lines changed

14 files changed

+105
-77
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ jobs:
152152
# matrix.ocaml_compiler may contain commas
153153
- name: Get OPAM cache key
154154
shell: bash
155-
run: echo "opam_cache_key=opam-env-v7-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}" | sed 's/,/-/g' >> $GITHUB_ENV
155+
run: echo "opam_cache_key=opam-env-v7-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('*.opam') }}" | sed 's/,/-/g' >> $GITHUB_ENV
156156

157157
- name: Restore OPAM environment
158158
id: cache-opam-env
@@ -249,7 +249,7 @@ jobs:
249249
id: compiler-build-state-key
250250
shell: bash
251251
run: |
252-
echo "value=compiler-build-state-v1-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('dune-project') }}" \
252+
echo "value=compiler-build-state-v1-${{ matrix.os }}-${{ matrix.ocaml_compiler }}-${{ hashFiles('*.opam') }}" \
253253
| sed 's/,/-/g' >> "$GITHUB_OUTPUT"
254254
255255
- name: Restore compiler build state

analysis.opam

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ bug-reports: "https://github.com/rescript-lang/rescript-compiler/issues"
99
depends: [
1010
"ocaml" {>= "4.14"}
1111
"cppo" {= "1.8.0"}
12-
"dune"
12+
"dune" {>= "3.17"}
13+
"odoc" {with-doc}
1314
]
1415
build: [
15-
["dune" "subst"] {pinned}
16+
["dune" "subst"] {dev}
1617
[
1718
"dune"
1819
"build"

compiler/dune

+17-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1-
(dirs bsb bsb_exe bsb_helper bsb_helper_exe bsc cmij common core depends ext
2-
frontend gentype jsoo js_parser ml syntax)
1+
(dirs
2+
bsb
3+
bsb_exe
4+
bsb_helper
5+
bsb_helper_exe
6+
bsc
7+
cmij
8+
common
9+
core
10+
depends
11+
ext
12+
frontend
13+
gentype
14+
jsoo
15+
js_parser
16+
ml
17+
syntax)
318

419
(env
520
(dev

compiler/ext/dune

+6-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
(wrapped false)
44
(preprocess
55
(action
6-
(run %{bin:cppo} -V OCAML:%{ocaml_version} %{env:CPPO_FLAGS=}
7-
%{input-file})))
6+
(run
7+
%{bin:cppo}
8+
-V
9+
OCAML:%{ocaml_version}
10+
%{env:CPPO_FLAGS=}
11+
%{input-file})))
812
(flags
913
(:standard -w +a-4-42-40-9-48-70))
1014
(foreign_stubs

compiler/jsoo/dune

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
(executables
44
(names jsoo_playground_main)
5-
(modes js)
5+
(modes js wasm)
66
(enabled_if
77
(= %{profile} browser))
88
(flags
99
(:standard -w +a-4-9-40-42-44-45))
10-
(libraries core syntax ml js_of_ocaml))
10+
(libraries core syntax ml js_of_ocaml)
11+
(preprocess
12+
(pps js_of_ocaml-ppx)))

compiler/jsoo/jsoo_playground_main.ml

+6-10
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,6 @@ let api_version = "5"
5454

5555
module Js = Js_of_ocaml.Js
5656

57-
let export (field : string) v = Js.Unsafe.set Js.Unsafe.global field v
58-
5957
module Lang = struct
6058
type t = Res
6159

@@ -676,11 +674,9 @@ module Export = struct
676674
end
677675

678676
let () =
679-
export "rescript_compiler"
680-
Js.Unsafe.(
681-
obj
682-
[|
683-
("api_version", inject @@ Js.string api_version);
684-
("version", inject @@ Js.string Bs_version.version);
685-
("make", inject @@ Export.make);
686-
|])
677+
Js.export "rescript_compiler"
678+
(object%js
679+
val api_version = api_version
680+
val version = Bs_version.version
681+
method make = Export.make ()
682+
end)

compiler/syntax/cli/res_cli.ml

+8-8
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@
2626
*)
2727
module Color = struct
2828
(* use ANSI color codes, see https://en.wikipedia.org/wiki/ANSI_escape_code *)
29-
type color =
30-
| Black [@live]
29+
type[@warning "-37"] color =
30+
| Black
3131
| Red
32-
| Green [@live]
32+
| Green
3333
| Yellow
34-
| Blue [@live]
34+
| Blue
3535
| Magenta
3636
| Cyan
37-
| White [@live]
37+
| White
3838

39-
type style =
39+
type[@warning "-37"] style =
4040
| FG of color (* foreground *)
41-
| BG of color [@live] (* background *)
41+
| BG of color (* background *)
4242
| Bold
4343
| Reset
4444
| Dim
@@ -132,7 +132,7 @@ module Color = struct
132132
let term = try Sys.getenv "TERM" with Not_found -> "" in
133133
term <> "dumb" && term <> "" && isatty stderr
134134

135-
type setting = Auto [@live] | Always [@live] | Never [@live]
135+
type[@warning "-37"] setting = Auto | Always | Never
136136

137137
let setup =
138138
let first = ref true in

dune-project

+2-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(lang dune 2.3)
1+
(lang dune 3.17)
22

33
(name rescript)
44

@@ -16,29 +16,7 @@
1616

1717
(package
1818
(name rescript)
19-
(synopsis "ReScript compiler")
20-
(depends
21-
(ocaml
22-
(>= 4.14))
23-
(ocamlformat
24-
(and
25-
:with-test
26-
(= 0.27.0)))
27-
(yojson
28-
(and
29-
:with-test
30-
(= 2.2.2)))
31-
(ocaml-lsp-server
32-
(and
33-
:with-dev-setup
34-
(= 1.22.0)))
35-
(cppo
36-
(= 1.8.0))
37-
(js_of_ocaml
38-
(= 6.0.1))
39-
(ounit2
40-
(= 2.2.7))
41-
dune))
19+
(synopsis "ReScript compiler"))
4220

4321
(package
4422
(name analysis)

playground/playground_test.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
require("./compiler.js")
1+
// Playground bundle is UMD module
2+
// It uses `module.exports` in current context, or fallback to `globalThis`
3+
const { rescript_compiler } = require("./compiler.js")
4+
25
require("./packages/compiler-builtins/cmij.js")
36
require("./packages/@rescript/react/cmij.js")
47

rescript.opam

+15-11
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,8 @@ authors: ["Hongbo Zhang <[email protected]>"]
66
license: "LGPL-3.0-or-later"
77
homepage: "https://github.com/rescript-lang/rescript-compiler"
88
bug-reports: "https://github.com/rescript-lang/rescript-compiler/issues"
9-
depends: [
10-
"ocaml" {>= "4.14"}
11-
"ocamlformat" {with-test & = "0.27.0"}
12-
"yojson" {with-test & = "2.2.2"}
13-
"ocaml-lsp-server" {with-dev-setup & = "1.22.0"}
14-
"cppo" {= "1.8.0"}
15-
"js_of_ocaml" {= "6.0.1"}
16-
"ounit2" {= "2.2.7"}
17-
"dune"
18-
]
199
build: [
20-
["dune" "subst"] {pinned}
10+
["dune" "subst"] {dev}
2111
[
2212
"dune"
2313
"build"
@@ -30,3 +20,17 @@ build: [
3020
"@doc" {with-doc}
3121
]
3222
]
23+
depends: [
24+
"ocaml" {>= "4.14"}
25+
"ocamlformat" {with-test & = "0.27.0"}
26+
"yojson" {with-test & = "2.2.2"}
27+
"ocaml-lsp-server" {with-dev-setup & = "1.22.0"}
28+
"cppo" {= "1.8.0"}
29+
"ounit2" {= "2.2.7"}
30+
"dune" {>= "3.17"}
31+
"odoc" {with-doc}
32+
# Dependencies that could be broken on Windows runners
33+
"js_of_ocaml" {= "6.0.1" & os != "win32"}
34+
"js_of_ocaml-ppx" {= "6.0.1" & os != "win32"}
35+
"wasm_of_ocaml-compiler" {= "6.0.1" & os != "win32"}
36+
]

rescript.opam.template

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
depends: [
2+
"ocaml" {>= "4.14"}
3+
"cppo" {= "1.8.0"}
4+
"dune" {>= "3.17"}
5+
"ocamlformat" {with-test & = "0.27.0"}
6+
"yojson" {with-test & = "2.2.2"}
7+
"ounit2" {with-test & = "2.2.7"}
8+
"odoc" {with-doc}
9+
"ocaml-lsp-server" {with-dev-setup & = "1.22.0"}
10+
11+
# Test dependencies that would be broken on Windows runners
12+
"js_of_ocaml" {os != "win32" & with-test & = "6.0.1"}
13+
"js_of_ocaml-ppx" {os != "win32" & with-test & = "6.0.1"}
14+
"wasm_of_ocaml-compiler" {os != "win32" & with-test & = "6.0.1"}
15+
]

scripts/copyExes.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,19 @@ function copyExe(dir, exe) {
2424
fs.rmSync(dest);
2525
}
2626

27-
fs.copyFileSync(src, dest);
28-
29-
if (process.platform !== "win32") {
30-
child_process.execSync(`strip ${dest}`);
27+
let mode = 0o755;
28+
if (fs.existsSync(dest)) {
29+
mode = fs.statSync(dest).mode & 0o777;
30+
fs.chmodSync(dest, mode | 0o200); // u+w
31+
}
32+
try {
33+
fs.copyFileSync(src, dest);
34+
if (process.platform !== "win32") {
35+
fs.chmodSync(dest, mode | 0o200); // u+w
36+
child_process.execSync(`strip ${dest}`);
37+
}
38+
} finally {
39+
fs.chmodSync(dest, mode);
3140
}
3241
}
3342

tests/syntax_benchmarks/Benchmark.ml

+7-7
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ module Time : sig
3333

3434
val now : unit -> t
3535

36-
val to_uint64 : t -> int64 [@@live]
36+
val [@warning "-32"] to_uint64 : t -> int64
3737

3838
(* let of_uint64_ns ns = ns *)
3939

40-
val nanosecond : t [@@live]
41-
val microsecond : t [@@live]
42-
val millisecond : t [@@live]
43-
val second : t [@@live]
44-
val minute : t [@@live]
45-
val hour : t [@@live]
40+
val [@warning "-32"] nanosecond : t
41+
val [@warning "-32"] microsecond : t
42+
val [@warning "-32"] millisecond : t
43+
val [@warning "-32"] second : t
44+
val [@warning "-32"] minute : t
45+
val [@warning "-32"] hour : t
4646

4747
val zero : t
4848

tools.opam

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ depends: [
1010
"ocaml" {>= "4.14"}
1111
"cppo" {= "1.8.0"}
1212
"analysis"
13-
"dune"
13+
"dune" {>= "3.17"}
14+
"odoc" {with-doc}
1415
]
1516
build: [
16-
["dune" "subst"] {pinned}
17+
["dune" "subst"] {dev}
1718
[
1819
"dune"
1920
"build"

0 commit comments

Comments
 (0)