Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 975a8ef

Browse files
cknittcristianoc
authored andcommitted
Build executables with dune
1 parent b42a8ed commit 975a8ef

File tree

18 files changed

+120
-226
lines changed

18 files changed

+120
-226
lines changed

.depend

Lines changed: 0 additions & 77 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,40 @@ on:
66
pull_request:
77
branches: [ master ]
88

9+
env:
10+
OCAML_VERSION: 4.06.1
11+
912
jobs:
1013
test:
11-
runs-on: macos-latest
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
os: [macos-latest, ubuntu-latest, windows-latest]
1218

19+
runs-on: ${{matrix.os}}
20+
1321
steps:
14-
- uses: actions/checkout@v2.3.4
22+
- uses: actions/checkout@v3
1523

1624
- name: Cache OCaml's opam
1725
uses: actions/cache@v2.1.5
1826
with:
1927
path: ~/.opam
20-
key: macos-latest-ocaml-4.06.1
28+
key: ${{matrix.os}}-ocaml-${{env.OCAML_VERSION}}
2129

22-
- name: Use OCaml
23-
uses: ocaml/setup-ocaml@v2
30+
- name: Use OCaml ${{env.OCAML_VERSION}}
31+
uses: ocaml/setup-ocaml@v2.0.3
2432
with:
25-
ocaml-compiler: 4.06.1
33+
ocaml-compiler: ${{env.OCAML_VERSION}}
34+
opam-pin: false
35+
opam-depext: false
2636

27-
- name: Use Node.js
28-
uses: actions/setup-node@v2.1.5
29-
with:
30-
node-version: 16
37+
- name: Install dependencies
38+
run: opam install dune reanalyze
3139

32-
- run: npm ci
40+
- name: Build executables
41+
run: opam exec -- dune build
3342

34-
- run: eval $(opam env) && make roundtrip-test
43+
- name: Run roundtrip tests
44+
if: runner.os == 'macOS'
45+
run: opam exec -- make roundtrip-test

.gitignore

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
.DS_STORE
2-
node_modules
32
*.cm*
43
*.o
54
*.s
65
lib/*
76
!lib/README.md
87
.vscode/settings.json
9-
# each person has its own preferences
10-
_build
8+
9+
# Dune
10+
_build

Makefile

Lines changed: 16 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,24 @@
1-
OCAMLOPT=ocamlopt.opt
2-
OCAMLFLAGS=-g -w +a-4-42-40-9-48 -warn-error +a -bin-annot -I +compiler-libs -I src -I tests -absname
3-
OCAMLDEP=ocamldep.opt
4-
%.cmi : %.mli
5-
$(OCAMLOPT) $(OCAMLFLAGS) -c $<
6-
%.cmx : %.ml
7-
$(OCAMLOPT) $(OCAMLFLAGS) -c $<
8-
include .depend
9-
.PHONY: depend
10-
depend:
11-
@$(OCAMLDEP) -native -I tests -I src src/*.ml src/*.mli tests/*.ml tests/*.mli > .depend
1+
build:
2+
dune build
123

13-
API_FILES = \
14-
src/reactjs_jsx_ppx_v3.cmx\
15-
src/res_io.cmx\
16-
src/res_minibuffer.cmx\
17-
src/res_doc.cmx\
18-
src/res_comment.cmx\
19-
src/res_token.cmx\
20-
src/res_grammar.cmx\
21-
src/res_reporting.cmx\
22-
src/res_diagnostics_printing_utils.cmx \
23-
src/res_diagnostics.cmx\
24-
src/res_parsetree_viewer.cmx\
25-
src/res_parens.cmx\
26-
src/res_comments_table.cmx\
27-
src/res_utf8.cmx\
28-
src/res_printer.cmx\
29-
src/res_scanner.cmx\
30-
src/res_js_ffi.cmx\
31-
src/res_parser.cmx\
32-
src/res_core.cmx\
33-
src/res_driver.cmx \
34-
src/res_ast_conversion.cmx \
35-
src/res_driver_ml_parser.cmx \
36-
src/res_driver_reason_binary.cmx \
37-
src/res_driver_binary.cmx \
38-
src/res_ast_debugger.cmx \
39-
src/res_outcome_printer.cmx \
40-
src/res_multi_printer.cmx
4+
bootstrap: build
5+
dune exec -- ./scripts/bootstrap.sh
416

42-
CLI_FILES = $(API_FILES) src/res_cli.cmx
7+
bench: build
8+
dune exec -- bench
439

44-
TEST_FILES = $(API_FILES) tests/res_utf8_test.cmx tests/res_test.cmx
10+
test: reanalyze
11+
dune exec -- tests
12+
dune exec -- ./test.sh
4513

46-
.DEFAULT_GOAL := build-native
14+
roundtrip-test: reanalyze
15+
dune exec -- tests
16+
ROUNDTRIP_TEST=1 dune exec -- ./test.sh
4717

48-
lib/rescript.exe: $(CLI_FILES)
49-
$(OCAMLOPT) $(OCAMLFLAGS) -O2 -o ./lib/rescript.exe -I +compiler-libs ocamlcommon.cmxa -I src $(CLI_FILES)
50-
51-
build-native: lib/rescript.exe depend
52-
53-
bootstrap: build-native
54-
# pack and parse the whole codebase using the compiler itself. Kind of a test
55-
ocaml unix.cma ./scripts/bspack.ml -bs-main Res_cli -I src -o ./lib/rescript.ml
56-
./lib/rescript.exe ./lib/rescript.ml > ./lib/rescript.res
57-
$(OCAMLOPT) -w a -pp "./lib/rescript.exe -print binary" -O2 -o ./lib/rescript.exe -I +compiler-libs ocamlcommon.cmxa -I lib -impl ./lib/rescript.res
58-
59-
bench: lib/bench.exe
60-
./lib/bench.exe
61-
62-
lib/bench.exe: benchmarks/Benchmark.ml $(API_FILES)
63-
$(OCAMLOPT) $(OCAMLFLAGS) -O2 -o ./lib/bench.exe -bin-annot -I +compiler-libs ocamlcommon.cmxa benchmarks/mac_osx_time.c -I benchmarks -I src $(API_FILES) benchmarks/Benchmark.ml
64-
65-
lib/test.exe: $(TEST_FILES)
66-
$(OCAMLOPT) $(OCAMLFLAGS) -O2 -o ./lib/test.exe -bin-annot -I +compiler-libs ocamlcommon.cmxa -I src -I tests $(TEST_FILES)
67-
68-
test: reanalyze build-native lib/test.exe
69-
./lib/test.exe
70-
./test.sh
71-
72-
roundtrip-test: reanalyze lib/test.exe
73-
./lib/test.exe
74-
ROUNDTRIP_TEST=1 ./test.sh
75-
76-
reanalyze: build-native lib/test.exe
77-
npx reanalyze -all-cmt . -suppress tests
18+
reanalyze: build
19+
reanalyze.exe -all-cmt _build/default -suppress tests
7820

7921
clean:
80-
git clean -dfx src benchmarks lib tests
22+
dune clean
8123

82-
.PHONY: clean test roundtrip-test reanalyze bootstrap build-native
24+
.PHONY: bench clean test roundtrip-test reanalyze bootstrap build-native

benchmarks/dune

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(executable
2+
(name benchmark)
3+
(public_name bench)
4+
(enabled_if
5+
(= %{system} macosx))
6+
(flags
7+
(-open Syntax))
8+
(foreign_stubs
9+
(language c)
10+
(names mac_osx_time))
11+
(libraries syntax compiler-libs.common))

cli/dune

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(executable
2+
(name res_cli)
3+
(public_name rescript)
4+
(flags
5+
(-open Syntax))
6+
(libraries syntax compiler-libs.common))
File renamed without changes.
File renamed without changes.
File renamed without changes.

dune

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(dirs src cli benchmarks tests scripts)
2+
3+
(env
4+
(dev
5+
(flags
6+
(:standard -w +a-4-42-40-9-48)))
7+
(release
8+
(flags
9+
(:standard -w +a-4-42-40-9-48))))

dune-project

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(lang dune 2.3)
2+
3+
(name rescript-syntax)
4+
5+
(generate_opam_files true)
6+
7+
(package
8+
(name rescript-syntax)
9+
(synopsis "ReScript parser/printer"))

package-lock.json

Lines changed: 0 additions & 32 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

rescript-syntax.opam

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# This file is generated by dune, edit dune-project instead
2+
opam-version: "2.0"
3+
synopsis: "ReScript parser/printer"
4+
depends: [
5+
"dune" {>= "2.3"}
6+
]
7+
build: [
8+
["dune" "subst"] {pinned}
9+
[
10+
"dune"
11+
"build"
12+
"-p"
13+
name
14+
"-j"
15+
jobs
16+
"@install"
17+
"@runtest" {with-test}
18+
"@doc" {with-doc}
19+
]
20+
]

scripts/bootstrap.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/zsh
2+
3+
# pack and parse the whole codebase using the compiler itself. Kind of a test
4+
ocaml unix.cma ./scripts/bspack.ml -bs-main Res_cli -I cli -I src -o ./lib/rescript.ml
5+
rescript ./lib/rescript.ml > ./lib/rescript.res
6+
ocamlopt.opt -w a -pp "rescript -print binary" -O2 -o rescript -I +compiler-libs ocamlcommon.cmxa -I lib -impl ./lib/rescript.res

src/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(library
2+
(name syntax)
3+
(libraries compiler-libs.common))

0 commit comments

Comments
 (0)