Skip to content

Upgrade dune version to get WASM binary #7349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions analysis.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
19 changes: 17 additions & 2 deletions compiler/dune
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 6 additions & 2 deletions compiler/ext/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions compiler/jsoo/dune
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

(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)))
16 changes: 6 additions & 10 deletions compiler/jsoo/jsoo_playground_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -676,11 +674,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)
16 changes: 8 additions & 8 deletions compiler/syntax/cli/res_cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
26 changes: 2 additions & 24 deletions dune-project
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(lang dune 2.3)
(lang dune 3.17)

(name rescript)

Expand All @@ -16,29 +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))
(ounit2
(= 2.2.7))
dune))
(synopsis "ReScript compiler"))

(package
(name analysis)
Expand Down
5 changes: 4 additions & 1 deletion playground/playground_test.js
Original file line number Diff line number Diff line change
@@ -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")

Expand Down
26 changes: 15 additions & 11 deletions rescript.opam
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,8 @@ authors: ["Hongbo Zhang <[email protected]>"]
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"}
"ounit2" {= "2.2.7"}
"dune"
]
build: [
["dune" "subst"] {pinned}
["dune" "subst"] {dev}
[
"dune"
"build"
Expand All @@ -30,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"}
]
15 changes: 15 additions & 0 deletions rescript.opam.template
Original file line number Diff line number Diff line change
@@ -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"}
]
17 changes: 13 additions & 4 deletions scripts/copyExes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are the permission-related changes required now?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They don't give write permission anymore. binaries are r+x.

The script is to grant required permissions before the task and to revoke them after it is completed.

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);
}
}

Expand Down
14 changes: 7 additions & 7 deletions tests/syntax_benchmarks/Benchmark.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions tools.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading