Skip to content

Commit 653938a

Browse files
authored
[interpreter] Use dune instead of ocamlbuild (#1665)
1 parent cfc9343 commit 653938a

File tree

10 files changed

+137
-294
lines changed

10 files changed

+137
-294
lines changed

interpreter/.gitignore

+4-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
*.cmo
2-
*.cmx
3-
*.native
4-
*.byte
5-
*.opt
6-
*.unopt
7-
*.js
8-
*.zip
9-
*.mlpack
101
_build
112
wasm
12-
wasm.debug
13-
3+
*.install
4+
*.js
5+
*.zip
6+
opam

interpreter/Makefile

+54-158
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# This Makefile uses ocamlbuild but does not rely on ocamlfind or the Opam
1+
# This Makefile uses dune but does not rely on ocamlfind or the Opam
22
# package manager to build. However, Opam package management is available
33
# optionally through the check/install/uninstall targets.
44
#
@@ -9,131 +9,45 @@
99

1010
# Configuration
1111

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

17+
BUILDDIR = _build/default
2818

29-
# Main targets
19+
JS = # set to JS shell command to run JS tests, empty to skip
3020

31-
.PHONY: default opt unopt libopt libunopt jslib all land zip smallint dunebuild
3221

33-
default: opt
34-
debug: unopt
35-
opt: $(OPT)
36-
unopt: $(UNOPT)
37-
libopt: _build/$(LIB).cmx _build/$(LIB).cmxa
38-
libunopt: _build/$(LIB).cmo _build/$(LIB).cma
39-
jslib: $(JSLIB).js
40-
all: unopt opt libunopt libopt test
41-
land: $(WINMAKE) all
42-
zip: $(ZIP)
43-
smallint: smallint.native
44-
ci: land jslib dunebuild
22+
# Main targets
4523

46-
dunebuild:
47-
dune build
24+
.PHONY: default opt jslib all zip smallint
4825

26+
default: $(OPT)
27+
jslib: $(JSLIB)
28+
all: $(OPT) test
29+
zip: $(ZIP)
30+
smallint: smallint.exe
31+
ci: all jslib
4932

5033
# Building executable
34+
.PHONY: $(NAME).exe
35+
$(NAME).exe:
36+
rm -f $(NAME)
37+
dune build $@
38+
cp $(BUILDDIR)/$(OPT) $(NAME)
5139

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

11244
# Building JavaScript library
11345

114-
JSLIB_DIR = meta/jslib
115-
JSLIB_FLAGS = -I $(JSLIB_DIR) -use-ocamlfind -pkg js_of_ocaml -pkg js_of_ocaml-ppx
116-
117-
.INTERMEDIATE: $(JSLIB).byte
118-
$(JSLIB).byte: $(JSLIB_DIR)/$(JSLIB).ml
119-
$(OCBA) $(JSLIB_FLAGS) $@
120-
121-
$(JSLIB).js: $(JSLIB).byte
122-
$(JSO) $<
123-
124-
# Building Windows build file
125-
126-
$(WINMAKE): clean
127-
echo rem Auto-generated from Makefile! >$@
128-
echo set NAME=$(NAME) >>$@
129-
echo if \'%1\' neq \'\' set NAME=%1 >>$@
130-
$(OCB) main.byte \
131-
| grep -v ocamldep \
132-
| grep -v mkdir \
133-
| sed s:`which ocaml`:ocaml:g \
134-
| sed s:main/main.d.byte:%NAME%.exe: \
135-
>>$@
46+
$(JSLIB): $(BUILDDIR)/$(JSLIB)
47+
cp $< $@
13648

49+
$(BUILDDIR)/$(JSLIB):
50+
dune build $(JSLIB)
13751

13852
# Executing test suite
13953

@@ -142,78 +56,60 @@ TESTDIR = ../test/core
14256
TESTFILES = $(shell cd $(TESTDIR); ls *.wast; ls [a-z]*/*.wast)
14357
TESTS = $(TESTFILES:%.wast=%)
14458

145-
.PHONY: test debugtest partest dune-test
59+
.PHONY: test partest dune-test
14660

14761
test: $(OPT) smallint
148-
$(TESTDIR)/run.py --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',)
149-
./smallint.native
150-
debugtest: $(UNOPT) smallint
151-
$(TESTDIR)/run.py --wasm `pwd`/$(UNOPT) $(if $(JS),--js '$(JS)',)
152-
./smallint.native
62+
$(TESTDIR)/run.py --wasm `pwd`/$(BUILDDIR)/$(OPT) $(if $(JS),--js '$(JS)',)
63+
dune exec ./smallint.exe
15364

15465
test/%: $(OPT)
155-
$(TESTDIR)/run.py --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
156-
debugtest/%: $(UNOPT)
157-
$(TESTDIR)/run.py --wasm `pwd`/$(UNOPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
66+
$(TESTDIR)/run.py --wasm `pwd`/$(BUILDDIR)/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
15867

15968
run/%: $(OPT)
16069
./$(OPT) $(TESTDIR)/$*.wast
161-
debug/%: $(UNOPT)
162-
./$(UNOPT) $(TESTDIR)/$*.wast
16370

164-
partest: $(TESTS:%=quiettest/%)
71+
partest: $(TESTS:%=quiettest/%)
16572
@echo All tests passed.
16673

16774
quiettest/%: $(OPT)
16875
@ ( \
169-
$(TESTDIR)/run.py 2>$(@F).out --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast && \
76+
$(TESTDIR)/run.py 2>$(@F).out --wasm `pwd`/$(BUILDDIR)/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast && \
17077
rm $(@F).out \
17178
) || \
17279
cat $(@F).out || rm $(@F).out || exit 1
17380

17481
smallinttest: smallint
175-
@./smallint.native
82+
dune exec ./smallint.exe
17683

17784
dunetest:
17885
dune test
17986

87+
install:
88+
dune build -p $(NAME) @install
89+
dune install
90+
91+
opam-release/%:
92+
git tag opam-$*
93+
git push --tags
94+
rm -f opam-$*.zip
95+
wget https://github.com/WebAssembly/spec/archive/opam-$*.zip
96+
cp wasm.opam opam
97+
echo "url {" >> opam
98+
echo " src: \"https://github.com/WebAssembly/spec/archive/opam-$*.zip\"" >> opam
99+
echo " checksum: \"md5=`md5 -q opam-$*.zip`\"" >> opam
100+
echo "}" >> opam
101+
rm opam-$*.zip
102+
@echo Created file ./opam, submit to github opam-repository/packages/wasm/wasm.$*/opam
180103

181104
# Miscellaneous targets
182105

183106
.PHONY: clean
184107

185-
$(ZIP): $(WINMAKE)
186-
git archive --format=zip --prefix=$(NAME)/ -o $@ HEAD
108+
$(ZIP):
109+
git archive --format=zip --prefix=$(NAME)/ -o $@ HEAD
187110

188111
clean:
189-
rm -rf _build/jslib $(LIB).mlpack _tags $(JSLIB).js
190-
$(OCB) -clean
191-
192-
193-
# Opam support
194-
195-
.PHONY: check install uninstall
112+
dune clean
196113

197-
check:
198-
# Check that we can find all relevant libraries
199-
# when using ocamlfind
200-
ocamlfind query $(LIBS)
201-
202-
install: _build/$(LIB).cmx _build/$(LIB).cmo
203-
ocamlfind install $(LIB) meta/findlib/META _build/$(LIB).o \
204-
$(wildcard _build/$(LIB).cm*) \
205-
$(wildcard $(DIRS:%=%/*.mli))
206-
207-
uninstall:
208-
ocamlfind remove $(LIB)
209-
210-
opam-release/%:
211-
git tag opam-$*
212-
git push --tags
213-
rm -f opam-$*.zip
214-
wget https://github.com/WebAssembly/spec/archive/opam-$*.zip
215-
cp meta/opam/opam .
216-
sed -i ".tmp" s/@VERSION/$*/g opam
217-
sed -i ".tmp" s/@MD5/`md5 -q opam-$*.zip`/g opam
218-
rm opam.tmp opam-$*.zip
219-
@echo Created file ./opam, submit to github opam-repository/packages/wasm/wasm.$*/opam
114+
distclean: clean
115+
rm -f $(NAME) $(JSLIB)

interpreter/README.md

+3-16
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@ The text format defines modules in S-expression syntax. Moreover, it is generali
1717

1818
You'll need OCaml 4.12 or higher. Instructions for installing a recent version of OCaml on multiple platforms are available [here](https://ocaml.org/docs/install.html). On most platforms, the recommended way is through [OPAM](https://ocaml.org/docs/install.html#OPAM).
1919

20+
You'll also need to install the dune build system. See the [installation instructions](https://github.com/ocaml/dune#installation-1).
21+
2022
Once you have OCaml, simply do
2123

2224
```
2325
make
2426
```
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-
```
27+
You'll get an executable named `./wasm`.
2928
To run the test suite,
3029
```
3130
make test
@@ -34,12 +33,6 @@ To do everything:
3433
```
3534
make all
3635
```
37-
Before committing changes, you should do
38-
```
39-
make land
40-
```
41-
That builds `all`, plus updates `winmake.bat`.
42-
4336

4437
#### Building on Windows
4538

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

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

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-
5845
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`.
5946

6047

interpreter/dune

+24-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
(include_subdirs unqualified)
22

33
(library
4-
(name wasm)
5-
; The 'main' module shall not be part of the library, as it would start the
4+
(public_name wasm)
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 \ main wasm smallint wast))
1010

1111
(executable
12-
(name main)
13-
(modules main)
12+
(public_name wasm)
13+
(modules wasm)
1414
(libraries wasm)
1515
(flags
1616
(-open Wasm)))
@@ -22,6 +22,23 @@
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+
32+
(rule
33+
(targets wasm.ml)
34+
(deps main/main.ml)
35+
(action (copy main/main.ml wasm.ml)))
36+
37+
(rule
38+
(targets wast.js)
39+
(deps wast.bc.js)
40+
(action (copy wast.bc.js wast.js)))
41+
2542
(subdir
2643
text
2744
(rule
@@ -42,10 +59,10 @@
4259
(rule
4360
(alias runtest)
4461
(deps
45-
./main.exe
62+
./wasm.exe
4663
./smallint.exe
4764
(source_tree ../test))
4865
(action
4966
(progn
50-
(run ../test/core/run.py --wasm ./main.exe)
67+
(run ../test/core/run.py --wasm ./wasm.exe)
5168
(run ./smallint.exe))))

0 commit comments

Comments
 (0)