Skip to content

Commit

Permalink
single dune file, proper opam support, switch parts of the Makefile to
Browse files Browse the repository at this point in the history
dune, update GitHub actions
  • Loading branch information
zapashcanon committed Jan 22, 2022
1 parent 1e5bd99 commit 71a57e8
Show file tree
Hide file tree
Showing 22 changed files with 159 additions and 475 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 4.12.x
- run: opam install --yes ocamlbuild.0.14.0
- run: opam install --yes dune
- run: cd interpreter && opam exec make all

build-js-api-spec:
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
submodules: "recursive"
- run: pip install bikeshed && bikeshed update
- run: pip install six
- run: sudo apt-get update -y && sudo apt-get install -y latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended
- run: sudo apt update -y && sudo apt install -y latexmk texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended
- run: pip install sphinx==4.0.0
- run: cd document/core && make all
- uses: actions/upload-artifact@v2
Expand Down
203 changes: 45 additions & 158 deletions interpreter/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,197 +2,84 @@
# package manager to build. However, Opam package management is available
# optionally through the check/install/uninstall targets.
#
# The $(JSLIB) target requires node.js and BuckleScript.
# The wast.js target requires node.js and BuckleScript.
#
# See README.me for instructions.


# Configuration

NAME = wasm
UNOPT = $(NAME).debug
OPT = $(NAME)
LIB = $(NAME)
ZIP = $(NAME).zip
JSLIB = wast.js
WINMAKE = winmake.bat

DIRS = util syntax binary text valid runtime exec script host main tests
LIBS = bigarray
FLAGS = -lexflags -ml -cflags '-w +a-4-27-42-44-45 -warn-error +a-3'
OCBA = ocamlbuild $(FLAGS) $(DIRS:%=-I %)
OCB = $(OCBA) $(LIBS:%=-libs %)
JS = # set to JS shell command to run JS tests

BUILDDIR = _build/default
UNOPT = $(BUILDDIR)/main/main.bc
OPT = $(BUILDDIR)/main/main.exe
JS = # set to JS shell command to run JS tests
TESTDIR = ../test/core
# Skip _output directory, since that's a tmp directory, and list all other wast files.
TESTFILES = $(shell cd $(TESTDIR); ls *.wast; ls [a-z]*/*.wast)

# Main targets

.PHONY: default opt unopt libopt libunopt jslib all land zip smallint

default: opt
debug: unopt
opt: $(OPT)
unopt: $(UNOPT)
libopt: _build/$(LIB).cmx _build/$(LIB).cmxa
libunopt: _build/$(LIB).cmo _build/$(LIB).cma
jslib: $(JSLIB)
all: unopt opt libunopt libopt test
land: $(WINMAKE) all
zip: $(ZIP)
smallint: smallint.native


# Building executable

empty =
space = $(empty) $(empty)
comma = ,

.INTERMEDIATE: _tags
_tags:
echo >$@ "true: bin_annot"
echo >>$@ "true: debug"
echo >>$@ "<{$(subst $(space),$(comma),$(DIRS))}/*.cmx>: for-pack($(PACK))"

$(UNOPT): main.byte
mv $< $@

$(OPT): main.native
mv $< $@

.PHONY: main.byte main.native
main.byte: _tags
$(OCB) -quiet $@

main.native: _tags
$(OCB) -quiet $@

.PHONY: smallint.byte smallint.native
smallint.byte: _tags
$(OCB) -quiet $@
smallint.native: _tags
$(OCB) -quiet $@


# Building library

FILES = $(shell ls $(DIRS:%=%/*) | grep '[.]ml[^.]*$$')
PACK = $(shell echo `echo $(LIB) | sed 's/^\(.\).*$$/\\1/g' | tr [:lower:] [:upper:]``echo $(LIB) | sed 's/^.\(.*\)$$/\\1/g'`)
.PHONY: default jslib all land zip

.INTERMEDIATE: $(LIB).mlpack
$(LIB).mlpack: $(DIRS)
ls $(FILES) \
| sed 's:\(.*/\)\{0,1\}\(.*\)\.[^\.]*:\2:' \
| grep -v main \
| sort | uniq \
>$@
.INTERMEDIATE: $(LIB).mllib
$(LIB).mllib:
echo Wasm >$@
_build/$(LIB).cmo: $(FILES) $(LIB).mlpack _tags Makefile
$(OCB) -quiet $(LIB).cmo
_build/$(LIB).cmx: $(FILES) $(LIB).mlpack _tags Makefile
$(OCB) -quiet $(LIB).cmx
_build/$(LIB).cma: $(FILES) $(LIB).mllib _tags Makefile
$(OCBA) -quiet $(LIB).cma
_build/$(LIB).cmxa: $(FILES) $(LIB).mllib _tags Makefile
$(OCBA) -quiet $(LIB).cmxa
# Building JavaScript library
.PHONY: $(JSLIB)
$(JSLIB): $(UNOPT)
mkdir -p _build/jslib/src
cp meta/jslib/* _build/jslib
cp $(DIRS:%=_build/%/*.ml*) meta/jslib/*.ml _build/jslib/src
rm _build/jslib/src/*.ml[^i]
(cd _build/jslib; ./build.sh ../../$@)
# Building Windows build file
$(WINMAKE): clean
echo rem Auto-generated from Makefile! >$@
echo set NAME=$(NAME) >>$@
echo if \'%1\' neq \'\' set NAME=%1 >>$@
$(OCB) main.byte \
| grep -v ocamldep \
| grep -v mkdir \
| sed s:`which ocaml`:ocaml:g \
| sed s:main/main.d.byte:%NAME%.exe: \
>>$@
default: $(OPT)
debug: $(UNOPT)
jslib: $(BUILDDIR)/jslib/wasm.bc.js
all: $(UNOPT) $(OPT) test
land: all
zip: wasm.zip

$(BUILDDIR)/%:
dune build $*

# Executing test suite

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

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

test: $(OPT) smallint
$(TESTDIR)/run.py --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',)
./smallint.native
debugtest: $(UNOPT) smallint
$(TESTDIR)/run.py --wasm `pwd`/$(UNOPT) $(if $(JS),--js '$(JS)',)
./smallint.native
test/%: $(OPT)
$(TESTDIR)/run.py --wasm `pwd`/$< $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
debugtest/%: $(UNOPT)
$(TESTDIR)/run.py --wasm `pwd`/$< $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast

test/%: $(OPT)
$(TESTDIR)/run.py --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
debugtest/%: $(UNOPT)
$(TESTDIR)/run.py --wasm `pwd`/$(UNOPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
test: $(OPT) smallinttest
$(TESTDIR)/run.py --wasm `pwd`/$< $(if $(JS),--js '$(JS)',)
debugtest: $(UNOPT) smallinttest
$(TESTDIR)/run.py --wasm `pwd`/$< $(if $(JS),--js '$(JS)',)

run/%: $(OPT)
./$(OPT) $(TESTDIR)/$*.wast
debug/%: $(UNOPT)
./$(UNOPT) $(TESTDIR)/$*.wast
run/%:
dune exec -- main/main.exe $(TESTDIR)/$*.wast
debug/%:
dune exec -- main/main.bc $(TESTDIR)/$*.wast

partest: $(TESTS:%=quiettest/%)
partest: $(TESTFILES:%.wast=quiettest/%)
@echo All tests passed.

quiettest/%: $(OPT)
quiettest/%: $(OPT)
@ ( \
$(TESTDIR)/run.py 2>$(@F).out --wasm `pwd`/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast && \
$(TESTDIR)/run.py 2>$(@F).out --wasm `pwd`/$< $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast && \
rm $(@F).out \
) || \
cat $(@F).out || rm $(@F).out || exit 1

smallinttest: smallint
@./smallint.native
smallinttest:
dune runtest

# Miscellaneous targets

.PHONY: clean
$(ZIP): $(WINMAKE)
git archive --format=zip --prefix=$(NAME)/ -o $@ HEAD
wasm.zip:
git archive --format=zip --prefix=wasm/ -o $@ HEAD

clean:
rm -rf _build/jslib $(LIB).mlpack _tags
$(OCB) -clean
dune clean

# Opam support

.PHONY: check install uninstall
check:
# Check that we can find all relevant libraries
# when using ocamlfind
ocamlfind query $(LIBS)
install: _build/$(LIB).cmx _build/$(LIB).cmo
ocamlfind install $(LIB) meta/findlib/META _build/$(LIB).o \
$(wildcard _build/$(LIB).cm*) \
$(wildcard $(DIRS:%=%/*.mli))
install:
dune install

uninstall:
ocamlfind remove $(LIB)
dune uninstall
4 changes: 0 additions & 4 deletions interpreter/binary/dune

This file was deleted.

47 changes: 47 additions & 0 deletions interpreter/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
(copy_files#
(files binary/*.ml*))

(copy_files#
(files exec/*.ml*))

(copy_files#
(files host/*.ml*))

(copy_files#
(files main/flags.ml))

(copy_files#
(files runtime/*.ml*))

(copy_files#
(files script/*.ml*))

(copy_files#
(files syntax/*.ml*))

(copy_files#
(files text/*.ml*))

(copy_files#
(files util/*.ml*))

(copy_files#
(files valid/*.ml*))

(library
(public_name wasm)
(wrapped false))

; we don't use the `ocamllex` stanza directly as there's no way to pass the `-ml`
; if we don't pass `-ml` we have a transition table overflow...

(rule
(target lexer.ml)
(deps lexer.mll)
(action
(chdir
%{workspace_root}
(run %{bin:ocamllex} -q -ml -o %{target} %{deps}))))

(ocamlyacc
(modules parser))
23 changes: 23 additions & 0 deletions interpreter/dune-project
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
(lang dune 2.8)

(implicit_transitive_deps false)

(name wasm)

(license Apache-2.0)

(authors "TODO")

(maintainers "TODO")

(source
(github WebAssembly/spec))

(generate_opam_files true)

(package
(name wasm)
(synopsis "WebAssembly library")
(description "A library for writing/reading/running WebAssembly binaries.")
(tags
(wasm webassembly spec interpreter))
(depends
(ocaml
(>= 4.05))))
25 changes: 0 additions & 25 deletions interpreter/exec/dune

This file was deleted.

12 changes: 0 additions & 12 deletions interpreter/host/dune

This file was deleted.

4 changes: 4 additions & 0 deletions interpreter/jslib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executable
(name wasm)
(modes js)
(libraries wasm))
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let encode s =
match def.Source.it with
| Script.Textual m -> Encode.encode m
| Script.Encoded (_, bs) -> bs
| _ -> failwith "unimplemented"

let decode s width =
let m = Decode.decode "(decode)" s in
Expand Down
Loading

0 comments on commit 71a57e8

Please sign in to comment.