Skip to content

Commit 71a57e8

Browse files
committed
single dune file, proper opam support, switch parts of the Makefile to
dune, update GitHub actions
1 parent 1e5bd99 commit 71a57e8

File tree

22 files changed

+159
-475
lines changed

22 files changed

+159
-475
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: ocaml/setup-ocaml@v2
1919
with:
2020
ocaml-compiler: 4.12.x
21-
- run: opam install --yes ocamlbuild.0.14.0
21+
- run: opam install --yes dune
2222
- run: cd interpreter && opam exec make all
2323

2424
build-js-api-spec:
@@ -51,7 +51,7 @@ jobs:
5151
submodules: "recursive"
5252
- run: pip install bikeshed && bikeshed update
5353
- run: pip install six
54-
- run: sudo apt-get update -y && sudo apt-get install -y latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended
54+
- run: sudo apt update -y && sudo apt install -y latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended
5555
- run: pip install sphinx==4.0.0
5656
- run: cd document/core && make all
5757
- uses: actions/upload-artifact@v2

interpreter/Makefile

Lines changed: 45 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -2,197 +2,84 @@
22
# package manager to build. However, Opam package management is available
33
# optionally through the check/install/uninstall targets.
44
#
5-
# The $(JSLIB) target requires node.js and BuckleScript.
5+
# The wast.js target requires node.js and BuckleScript.
66
#
77
# See README.me for instructions.
88

99

1010
# Configuration
1111

12-
NAME = wasm
13-
UNOPT = $(NAME).debug
14-
OPT = $(NAME)
15-
LIB = $(NAME)
16-
ZIP = $(NAME).zip
17-
JSLIB = wast.js
18-
WINMAKE = winmake.bat
19-
20-
DIRS = util syntax binary text valid runtime exec script host main tests
21-
LIBS = bigarray
22-
FLAGS = -lexflags -ml -cflags '-w +a-4-27-42-44-45 -warn-error +a-3'
23-
OCBA = ocamlbuild $(FLAGS) $(DIRS:%=-I %)
24-
OCB = $(OCBA) $(LIBS:%=-libs %)
25-
JS = # set to JS shell command to run JS tests
26-
12+
BUILDDIR = _build/default
13+
UNOPT = $(BUILDDIR)/main/main.bc
14+
OPT = $(BUILDDIR)/main/main.exe
15+
JS = # set to JS shell command to run JS tests
16+
TESTDIR = ../test/core
17+
# Skip _output directory, since that's a tmp directory, and list all other wast files.
18+
TESTFILES = $(shell cd $(TESTDIR); ls *.wast; ls [a-z]*/*.wast)
2719

2820
# Main targets
2921

30-
.PHONY: default opt unopt libopt libunopt jslib all land zip smallint
31-
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)
39-
all: unopt opt libunopt libopt test
40-
land: $(WINMAKE) all
41-
zip: $(ZIP)
42-
smallint: smallint.native
43-
44-
45-
# Building executable
46-
47-
empty =
48-
space = $(empty) $(empty)
49-
comma = ,
50-
51-
.INTERMEDIATE: _tags
52-
_tags:
53-
echo >$@ "true: bin_annot"
54-
echo >>$@ "true: debug"
55-
echo >>$@ "<{$(subst $(space),$(comma),$(DIRS))}/*.cmx>: for-pack($(PACK))"
56-
57-
$(UNOPT): main.byte
58-
mv $< $@
59-
60-
$(OPT): main.native
61-
mv $< $@
62-
63-
.PHONY: main.byte main.native
64-
main.byte: _tags
65-
$(OCB) -quiet $@
66-
67-
main.native: _tags
68-
$(OCB) -quiet $@
69-
70-
.PHONY: smallint.byte smallint.native
71-
smallint.byte: _tags
72-
$(OCB) -quiet $@
73-
smallint.native: _tags
74-
$(OCB) -quiet $@
75-
76-
77-
# Building library
78-
79-
FILES = $(shell ls $(DIRS:%=%/*) | grep '[.]ml[^.]*$$')
80-
PACK = $(shell echo `echo $(LIB) | sed 's/^\(.\).*$$/\\1/g' | tr [:lower:] [:upper:]``echo $(LIB) | sed 's/^.\(.*\)$$/\\1/g'`)
22+
.PHONY: default jslib all land zip
8123

82-
.INTERMEDIATE: $(LIB).mlpack
83-
$(LIB).mlpack: $(DIRS)
84-
ls $(FILES) \
85-
| sed 's:\(.*/\)\{0,1\}\(.*\)\.[^\.]*:\2:' \
86-
| grep -v main \
87-
| sort | uniq \
88-
>$@
89-
90-
.INTERMEDIATE: $(LIB).mllib
91-
$(LIB).mllib:
92-
echo Wasm >$@
93-
94-
_build/$(LIB).cmo: $(FILES) $(LIB).mlpack _tags Makefile
95-
$(OCB) -quiet $(LIB).cmo
96-
97-
_build/$(LIB).cmx: $(FILES) $(LIB).mlpack _tags Makefile
98-
$(OCB) -quiet $(LIB).cmx
99-
100-
_build/$(LIB).cma: $(FILES) $(LIB).mllib _tags Makefile
101-
$(OCBA) -quiet $(LIB).cma
102-
103-
_build/$(LIB).cmxa: $(FILES) $(LIB).mllib _tags Makefile
104-
$(OCBA) -quiet $(LIB).cmxa
105-
106-
107-
# Building JavaScript library
108-
109-
.PHONY: $(JSLIB)
110-
$(JSLIB): $(UNOPT)
111-
mkdir -p _build/jslib/src
112-
cp meta/jslib/* _build/jslib
113-
cp $(DIRS:%=_build/%/*.ml*) meta/jslib/*.ml _build/jslib/src
114-
rm _build/jslib/src/*.ml[^i]
115-
(cd _build/jslib; ./build.sh ../../$@)
116-
117-
118-
# Building Windows build file
119-
120-
$(WINMAKE): clean
121-
echo rem Auto-generated from Makefile! >$@
122-
echo set NAME=$(NAME) >>$@
123-
echo if \'%1\' neq \'\' set NAME=%1 >>$@
124-
$(OCB) main.byte \
125-
| grep -v ocamldep \
126-
| grep -v mkdir \
127-
| sed s:`which ocaml`:ocaml:g \
128-
| sed s:main/main.d.byte:%NAME%.exe: \
129-
>>$@
24+
default: $(OPT)
25+
debug: $(UNOPT)
26+
jslib: $(BUILDDIR)/jslib/wasm.bc.js
27+
all: $(UNOPT) $(OPT) test
28+
land: all
29+
zip: wasm.zip
13030

31+
$(BUILDDIR)/%:
32+
dune build $*
13133

13234
# Executing test suite
13335

134-
TESTDIR = ../test/core
135-
# Skip _output directory, since that's a tmp directory, and list all other wast files.
136-
TESTFILES = $(shell cd $(TESTDIR); ls *.wast; ls [a-z]*/*.wast)
137-
TESTS = $(TESTFILES:%.wast=%)
36+
.PHONY: test debugtest partest winmake.bat
13837

139-
.PHONY: test debugtest partest
38+
winmake.bat:
39+
dune clean
40+
dune build main/main.bc
41+
cat _build/log | grep -v "^#" | sed s:`which ocaml`:ocaml:g | sed s:_build/default:_build/:g
14042

141-
test: $(OPT) smallint
142-
$(TESTDIR)/run.py --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',)
143-
./smallint.native
144-
debugtest: $(UNOPT) smallint
145-
$(TESTDIR)/run.py --wasm `pwd`/$(UNOPT) $(if $(JS),--js '$(JS)',)
146-
./smallint.native
43+
test/%: $(OPT)
44+
$(TESTDIR)/run.py --wasm `pwd`/$< $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
45+
debugtest/%: $(UNOPT)
46+
$(TESTDIR)/run.py --wasm `pwd`/$< $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
14747

148-
test/%: $(OPT)
149-
$(TESTDIR)/run.py --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
150-
debugtest/%: $(UNOPT)
151-
$(TESTDIR)/run.py --wasm `pwd`/$(UNOPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
48+
test: $(OPT) smallinttest
49+
$(TESTDIR)/run.py --wasm `pwd`/$< $(if $(JS),--js '$(JS)',)
50+
debugtest: $(UNOPT) smallinttest
51+
$(TESTDIR)/run.py --wasm `pwd`/$< $(if $(JS),--js '$(JS)',)
15252

153-
run/%: $(OPT)
154-
./$(OPT) $(TESTDIR)/$*.wast
155-
debug/%: $(UNOPT)
156-
./$(UNOPT) $(TESTDIR)/$*.wast
53+
run/%:
54+
dune exec -- main/main.exe $(TESTDIR)/$*.wast
55+
debug/%:
56+
dune exec -- main/main.bc $(TESTDIR)/$*.wast
15757

158-
partest: $(TESTS:%=quiettest/%)
58+
partest: $(TESTFILES:%.wast=quiettest/%)
15959
@echo All tests passed.
16060

161-
quiettest/%: $(OPT)
61+
quiettest/%: $(OPT)
16262
@ ( \
163-
$(TESTDIR)/run.py 2>$(@F).out --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast && \
63+
$(TESTDIR)/run.py 2>$(@F).out --wasm `pwd`/$< $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast && \
16464
rm $(@F).out \
16565
) || \
16666
cat $(@F).out || rm $(@F).out || exit 1
16767

168-
smallinttest: smallint
169-
@./smallint.native
68+
smallinttest:
69+
dune runtest
17070

17171
# Miscellaneous targets
17272

173-
.PHONY: clean
174-
175-
$(ZIP): $(WINMAKE)
176-
git archive --format=zip --prefix=$(NAME)/ -o $@ HEAD
73+
wasm.zip:
74+
git archive --format=zip --prefix=wasm/ -o $@ HEAD
17775

17876
clean:
179-
rm -rf _build/jslib $(LIB).mlpack _tags
180-
$(OCB) -clean
181-
77+
dune clean
18278

18379
# Opam support
18480

185-
.PHONY: check install uninstall
186-
187-
check:
188-
# Check that we can find all relevant libraries
189-
# when using ocamlfind
190-
ocamlfind query $(LIBS)
191-
192-
install: _build/$(LIB).cmx _build/$(LIB).cmo
193-
ocamlfind install $(LIB) meta/findlib/META _build/$(LIB).o \
194-
$(wildcard _build/$(LIB).cm*) \
195-
$(wildcard $(DIRS:%=%/*.mli))
81+
install:
82+
dune install
19683

19784
uninstall:
198-
ocamlfind remove $(LIB)
85+
dune uninstall

interpreter/binary/dune

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

interpreter/dune

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
(copy_files#
2+
(files binary/*.ml*))
3+
4+
(copy_files#
5+
(files exec/*.ml*))
6+
7+
(copy_files#
8+
(files host/*.ml*))
9+
10+
(copy_files#
11+
(files main/flags.ml))
12+
13+
(copy_files#
14+
(files runtime/*.ml*))
15+
16+
(copy_files#
17+
(files script/*.ml*))
18+
19+
(copy_files#
20+
(files syntax/*.ml*))
21+
22+
(copy_files#
23+
(files text/*.ml*))
24+
25+
(copy_files#
26+
(files util/*.ml*))
27+
28+
(copy_files#
29+
(files valid/*.ml*))
30+
31+
(library
32+
(public_name wasm)
33+
(wrapped false))
34+
35+
; we don't use the `ocamllex` stanza directly as there's no way to pass the `-ml`
36+
; if we don't pass `-ml` we have a transition table overflow...
37+
38+
(rule
39+
(target lexer.ml)
40+
(deps lexer.mll)
41+
(action
42+
(chdir
43+
%{workspace_root}
44+
(run %{bin:ocamllex} -q -ml -o %{target} %{deps}))))
45+
46+
(ocamlyacc
47+
(modules parser))

interpreter/dune-project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
11
(lang dune 2.8)
22

33
(implicit_transitive_deps false)
4+
5+
(name wasm)
6+
7+
(license Apache-2.0)
8+
9+
(authors "TODO")
10+
11+
(maintainers "TODO")
12+
13+
(source
14+
(github WebAssembly/spec))
15+
16+
(generate_opam_files true)
17+
18+
(package
19+
(name wasm)
20+
(synopsis "WebAssembly library")
21+
(description "A library for writing/reading/running WebAssembly binaries.")
22+
(tags
23+
(wasm webassembly spec interpreter))
24+
(depends
25+
(ocaml
26+
(>= 4.05))))

interpreter/exec/dune

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

interpreter/host/dune

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

interpreter/jslib/dune

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(executable
2+
(name wasm)
3+
(modes js)
4+
(libraries wasm))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ let encode s =
33
match def.Source.it with
44
| Script.Textual m -> Encode.encode m
55
| Script.Encoded (_, bs) -> bs
6+
| _ -> failwith "unimplemented"
67

78
let decode s width =
89
let m = Decode.decode "(decode)" s in

0 commit comments

Comments
 (0)