Skip to content

Commit 7a062b7

Browse files
committed
switch the Makefile to dune
1 parent 79ca3c8 commit 7a062b7

File tree

6 files changed

+44
-157
lines changed

6 files changed

+44
-157
lines changed

interpreter/Makefile

Lines changed: 29 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -9,115 +9,39 @@
99

1010
# Configuration
1111

12-
NAME = wasm
13-
UNOPT = $(NAME).debug
14-
OPT = $(NAME)
15-
LIB = $(NAME)
16-
ZIP = $(NAME).zip
17-
JSLIB = wast
18-
19-
DIRS = util syntax binary text valid runtime exec script host main tests
20-
LIBS =
21-
FLAGS = -lexflags -ml -cflags '-w +a-4-27-42-44-45-70 -warn-error +a-3'
22-
OCBA = ocamlbuild $(FLAGS) $(DIRS:%=-I %)
23-
OCB = $(OCBA) $(LIBS:%=-libs %)
24-
JSO = js_of_ocaml -q --opt 3
12+
OPT = wasm.exe
13+
ZIP = wasm.zip
14+
JSLIB = wast.bc.js
15+
16+
BUILDDIR = _build/default
17+
2518
JS = # set to JS shell command to run JS tests, empty to skip
2619

2720

2821
# Main targets
2922

30-
.PHONY: default opt unopt libopt libunopt jslib all zip smallint dunebuild
23+
.PHONY: default opt jslib all zip smallint
3124

32-
default: opt
33-
debug: unopt
34-
opt: $(OPT)
35-
unopt: $(UNOPT)
36-
libopt: _build/$(LIB).cmx _build/$(LIB).cmxa
37-
libunopt: _build/$(LIB).cmo _build/$(LIB).cma
38-
jslib: $(JSLIB).js
39-
all: unopt opt libunopt libopt test
25+
default: $(OPT)
26+
jslib: $(JSLIB)
27+
all: $(OPT) test
4028
zip: $(ZIP)
41-
smallint: smallint.native
42-
ci: all jslib dunebuild
43-
44-
dunebuild:
45-
dune build
46-
29+
smallint: smallint.exe
30+
ci: all jslib
4731

4832
# Building executable
33+
.PHONY: wasm.exe
34+
wasm.exe:
35+
dune build $@
4936

50-
empty =
51-
space = $(empty) $(empty)
52-
comma = ,
53-
54-
.INTERMEDIATE: _tags
55-
_tags:
56-
echo >$@ "true: bin_annot"
57-
echo >>$@ "true: debug"
58-
echo >>$@ "<{$(subst $(space),$(comma),$(DIRS))}/*.cmx>: for-pack($(PACK))"
59-
60-
$(UNOPT): main.byte
61-
mv $< $@
62-
63-
$(OPT): main.native
64-
mv $< $@
65-
66-
.PHONY: main.byte main.native
67-
main.byte: _tags
68-
$(OCB) -quiet $@
69-
70-
main.native: _tags
71-
$(OCB) -quiet $@
72-
73-
.PHONY: smallint.byte smallint.native
74-
smallint.byte: _tags
75-
$(OCB) -quiet $@
76-
smallint.native: _tags
77-
$(OCB) -quiet $@
78-
79-
80-
# Building library
81-
82-
FILES = $(shell ls $(DIRS:%=%/*) | grep '[.]ml[^.]*$$')
83-
PACK = $(shell echo `echo $(LIB) | sed 's/^\(.\).*$$/\\1/g' | tr [:lower:] [:upper:]``echo $(LIB) | sed 's/^.\(.*\)$$/\\1/g'`)
84-
85-
.INTERMEDIATE: $(LIB).mlpack
86-
$(LIB).mlpack: $(DIRS)
87-
ls $(FILES) \
88-
| sed 's:\(.*/\)\{0,1\}\(.*\)\.[^\.]*:\2:' \
89-
| grep -v main \
90-
| sort | uniq \
91-
>$@
92-
93-
.INTERMEDIATE: $(LIB).mllib
94-
$(LIB).mllib:
95-
echo Wasm >$@
96-
97-
_build/$(LIB).cmo: $(FILES) $(LIB).mlpack _tags Makefile
98-
$(OCB) -quiet $(LIB).cmo
99-
100-
_build/$(LIB).cmx: $(FILES) $(LIB).mlpack _tags Makefile
101-
$(OCB) -quiet $(LIB).cmx
102-
103-
_build/$(LIB).cma: $(FILES) $(LIB).mllib _tags Makefile
104-
$(OCBA) -quiet $(LIB).cma
105-
106-
_build/$(LIB).cmxa: $(FILES) $(LIB).mllib _tags Makefile
107-
$(OCBA) -quiet $(LIB).cmxa
108-
37+
.PHONY: smallint.exe
38+
smallint.exe:
39+
dune build $@
10940

11041
# Building JavaScript library
11142

112-
JSLIB_DIR = meta/jslib
113-
JSLIB_FLAGS = -I $(JSLIB_DIR) -use-ocamlfind -pkg js_of_ocaml -pkg js_of_ocaml-ppx
114-
115-
.INTERMEDIATE: $(JSLIB).byte
116-
$(JSLIB).byte: $(JSLIB_DIR)/$(JSLIB).ml
117-
$(OCBA) $(JSLIB_FLAGS) $@
118-
119-
$(JSLIB).js: $(JSLIB).byte
120-
$(JSO) $<
43+
wast.bc.js:
44+
dune build $@
12145

12246
# Executing test suite
12347

@@ -126,37 +50,30 @@ TESTDIR = ../test/core
12650
TESTFILES = $(shell cd $(TESTDIR); ls *.wast; ls [a-z]*/*.wast)
12751
TESTS = $(TESTFILES:%.wast=%)
12852

129-
.PHONY: test debugtest partest dune-test
53+
.PHONY: test partest dune-test
13054

13155
test: $(OPT) smallint
132-
$(TESTDIR)/run.py --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',)
133-
./smallint.native
134-
debugtest: $(UNOPT) smallint
135-
$(TESTDIR)/run.py --wasm `pwd`/$(UNOPT) $(if $(JS),--js '$(JS)',)
136-
./smallint.native
56+
$(TESTDIR)/run.py --wasm `pwd`/$(BUILDDIR)/$(OPT) $(if $(JS),--js '$(JS)',)
57+
dune exec ./smallint.exe
13758

13859
test/%: $(OPT)
139-
$(TESTDIR)/run.py --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
140-
debugtest/%: $(UNOPT)
141-
$(TESTDIR)/run.py --wasm `pwd`/$(UNOPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
60+
$(TESTDIR)/run.py --wasm `pwd`/$(BUILDDIR)/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
14261

14362
run/%: $(OPT)
14463
./$(OPT) $(TESTDIR)/$*.wast
145-
debug/%: $(UNOPT)
146-
./$(UNOPT) $(TESTDIR)/$*.wast
14764

148-
partest: $(TESTS:%=quiettest/%)
65+
partest: $(TESTS:%=quiettest/%)
14966
@echo All tests passed.
15067

15168
quiettest/%: $(OPT)
15269
@ ( \
153-
$(TESTDIR)/run.py 2>$(@F).out --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast && \
70+
$(TESTDIR)/run.py 2>$(@F).out --wasm `pwd`/$(BUILDDIR)/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast && \
15471
rm $(@F).out \
15572
) || \
15673
cat $(@F).out || rm $(@F).out || exit 1
15774

15875
smallinttest: smallint
159-
@./smallint.native
76+
dune exec ./smallint.exe
16077

16178
dunetest:
16279
dune test
@@ -167,26 +84,7 @@ dunetest:
16784
.PHONY: clean
16885

16986
$(ZIP):
170-
git archive --format=zip --prefix=$(NAME)/ -o $@ HEAD
87+
git archive --format=zip --prefix=wasm/ -o $@ HEAD
17188

17289
clean:
173-
rm -rf _build/jslib $(LIB).mlpack _tags $(JSLIB).js
174-
$(OCB) -clean
175-
176-
177-
# Opam support
178-
179-
.PHONY: check install uninstall
180-
181-
check:
182-
# Check that we can find all relevant libraries
183-
# when using ocamlfind
184-
ocamlfind query $(LIBS)
185-
186-
install: _build/$(LIB).cmx _build/$(LIB).cmo
187-
ocamlfind install $(LIB) meta/findlib/META _build/$(LIB).o \
188-
$(wildcard _build/$(LIB).cm*) \
189-
$(wildcard $(DIRS:%=%/*.mli))
190-
191-
uninstall:
192-
ocamlfind remove $(LIB)
90+
dune clean

interpreter/README.md

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,7 @@ Once you have OCaml, simply do
2222
```
2323
make
2424
```
25-
You'll get an executable named `./wasm`. This is a byte code executable. If you want a (faster) native code executable, do
26-
```
27-
make opt
28-
```
25+
You'll get an executable named `_build/default/wasm.exe`.
2926
To run the test suite,
3027
```
3128
make test
@@ -34,12 +31,6 @@ To do everything:
3431
```
3532
make all
3633
```
37-
Before committing changes, you should do
38-
```
39-
make land
40-
```
41-
That builds `all`, plus updates `winmake.bat`.
42-
4334

4435
#### Building on Windows
4536

@@ -49,12 +40,6 @@ The instructions depend on how you [installed OCaml on Windows](https://ocaml.or
4940

5041
2. *Windows Subsystem for Linux* (WSL): You can build the interpreter using `make`, as described above.
5142

52-
3. *From source*: If you just want to build the interpreter and don't care about modifying it, you don't need to install the Cygwin core that comes with the installer. Just install OCaml itself and run
53-
```
54-
winmake.bat
55-
```
56-
in a Windows shell, which creates a program named `wasm`. Note that this will be a byte code executable only, i.e., somewhat slower.
57-
5843
In any way, in order to run the test suite you'll need to have Python installed. If you used Option 3, you can invoke the test runner `runtests.py` directly instead of doing it through `make`.
5944

6045

interpreter/dune

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
(library
44
(name wasm)
5-
; The 'main' module shall not be part of the library, as it would start the
5+
; The 'wasm' module shall not be part of the library, as it would start the
66
; Wasm REPL every time in all the dependencies.
77
; We exclude the 'wast' module as it is only used for the JS build.
88
; 'smallint' is a separate test module.
9-
(modules :standard \ main smallint wast))
9+
(modules :standard \ wasm smallint wast))
1010

1111
(executable
12-
(name main)
13-
(modules main)
12+
(name wasm)
13+
(modules wasm)
1414
(libraries wasm)
1515
(flags
1616
(-open Wasm)))
@@ -22,6 +22,13 @@
2222
(flags
2323
(-open Wasm)))
2424

25+
(executable
26+
(name wast)
27+
(modules wast)
28+
(modes js)
29+
(libraries js_of_ocaml wasm)
30+
(preprocess (pps js_of_ocaml-ppx)))
31+
2532
(subdir
2633
text
2734
(rule
@@ -42,10 +49,10 @@
4249
(rule
4350
(alias runtest)
4451
(deps
45-
./main.exe
52+
./wasm.exe
4653
./smallint.exe
4754
(source_tree ../test))
4855
(action
4956
(progn
50-
(run ../test/core/run.py --wasm ./main.exe)
57+
(run ../test/core/run.py --wasm ./wasm.exe)
5158
(run ./smallint.exe))))

interpreter/meta/jslib/wast.ml renamed to interpreter/jslib/wast.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(* Implements a wrapper library that allows the use of the reference
22
* interpreter's encode/decode functionality in JavaScript.
33
*)
4+
open Wasm
45
open Js_of_ocaml
56

67
let _ =
File renamed without changes.

interpreter/meta/findlib/META

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

0 commit comments

Comments
 (0)