diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 11fc1856..9a53de3f 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -8,21 +8,20 @@ jobs:
matrix:
os:
- ubuntu-latest
- - macos-latest
- # - windows-latest
- # Blocked until we no longer require libev; Dream still works on
- # Windows, but testing it is awkward at the moment.
ocaml:
+ - 5.0.x
+ - 4.14.x
+ - 4.13.x
- 4.12.x
+ - 4.11.x
+ - 4.10.x
+ - 4.09.x
+ - 4.08.x
include:
- - os: ubuntu-latest
- ocaml: 4.08.x
- - os: ubuntu-latest
- ocaml: 4.09.x
- - os: ubuntu-latest
- ocaml: 4.10.x
- - os: ubuntu-latest
- ocaml: 4.11.x
+ - os: macos-latest
+ ocaml: 4.12.x
+ - os: windows-latest
+ ocaml: 4.14.x
runs-on: ${{matrix.os}}
steps:
@@ -31,27 +30,66 @@ jobs:
submodules: recursive
- uses: avsm/setup-ocaml@v2
+ if: runner.os != 'Windows'
+ with:
+ ocaml-compiler: ${{matrix.ocaml}}
+
+ - uses: avsm/setup-ocaml@v2
+ if: runner.os == 'Windows'
with:
ocaml-compiler: ${{matrix.ocaml}}
+ opam-repositories: |
+ opam-repository-mingw: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset
+ default: https://github.com/ocaml/opam-repository.git
+ - run: opam depext --yes conf-sqlite3
- run: opam depext --yes conf-postgresql
- run: opam depext --yes conf-libev
- - run: opam install --yes --deps-only --with-test .
- - run: opam exec -- dune runtest
- - run: |
+ if: runner.os != 'Windows'
+
+ # The tests require ppx_expect. The latest versions of it introduced changes
+ # in the formatting of the output, and also require OCaml >= 4.10, which
+ # makes testing on < 4.10 awkward. So, we skip tests on < 4.10.
+ - shell: bash
+ run: |
set -e
set -x
- EXAMPLES=$(find example -maxdepth 1 -type d -not -name "m-mirage*"| grep -v "^example/0" | grep -v "^example$" | sort)
- shopt -s nullglob
+ WITH_TEST=--with-test
+ case ${{matrix.ocaml}} in
+ 4.09.x) WITH_TEST=;;
+ 4.08.x) WITH_TEST=;;
+ esac
+
+ # Tests on Windows are disabled because of a difference in ppx_expect
+ # output. See https://github.com/aantron/dream/pull/282.
+ case ${{runner.os}} in
+ Windows) WITH_TEST=;;
+ esac
+
+ OPAM=$(which opam || true)
+ if [ -z "$OPAM" ]
+ then
+ OPAM=D:\\cygwin\\wrapperbin\\opam.cmd
+ fi
- for EXAMPLE in $EXAMPLES
- do
- FILE=$(ls $EXAMPLE/*.ml $EXAMPLE/*.re $EXAMPLE/server/*.ml $EXAMPLE/server/*.re)
- EXE=$(echo $FILE | sed 's/\..*$/.exe/g')
- echo dune build $EXE
- opam exec -- dune build $EXE
- done
+ $OPAM install --yes --deps-only $WITH_TEST ./dream-pure.opam ./dream-httpaf.opam ./dream.opam
+
+ if [ ! -z "$WITH_TEST" ]
+ then
+ $OPAM exec -- dune runtest
+
+ EXAMPLES=$(find example -maxdepth 1 -type d -not -name "w-mirage*" -not -name "r-tyxml" | grep -v "^example/0" | grep -v "^example$" | sort)
+ shopt -s nullglob
+
+ for EXAMPLE in $EXAMPLES
+ do
+ FILE=$(ls $EXAMPLE/*.ml $EXAMPLE/*.re $EXAMPLE/server/*.ml $EXAMPLE/server/*.re)
+ EXE=$(echo $FILE | sed 's/\..*$/.exe/g')
+ echo dune build $EXE
+ $OPAM exec -- dune build $EXE
+ done
+ fi
quickstart:
strategy:
@@ -77,3 +115,29 @@ jobs:
else
exit 1
fi
+
+ mirage:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ with:
+ submodules: recursive
+ - run: mkdir ../repo-copy
+ - run: cp -r * ../repo-copy/
+ - uses: avsm/setup-ocaml@v2
+ with:
+ ocaml-compiler: 4.14.x
+ - run: opam install --yes --deps-only ./dream-pure.opam ./dream-httpaf.opam ./dream.opam ./dream-mirage.opam
+ - run: opam install --yes mirage mirage-clock-unix
+ - run: cd example/w-mirage && mv config.ml config.ml.backup
+ - run: cd example/w-mirage && sed -e 's/package "dream-mirage"//' < config.ml.backup > config.ml
+ - run: cd example/w-mirage && opam exec -- mirage configure -t unix
+ - run: cd example/w-mirage && opam exec -- make depends
+ - run: cd example/w-mirage && ls duniverse
+ - run: cp -r ../repo-copy example/w-mirage/duniverse/dream
+ - run: cd example/w-mirage/duniverse && rm -rf ocaml-cstruct logs ke fmt lwt bytes seq mirage-flow sexplib0 ptime tls domain-name ocaml-ipaddr mirage-clock ocplib-endian
+ - run: cd example/w-mirage && mv config.ml.backup config.ml
+ - run: cd example/w-mirage && sed -e 's/(libraries/(libraries dream-mirage/' < dune.build > dune.build.2
+ - run: cd example/w-mirage && mv dune.build.2 dune.build
+ - run: cd example/w-mirage && opam exec -- dune build
+ - run: file example/w-mirage/_build/default/main.exe
diff --git a/.gitignore b/.gitignore
index a4114480..08738be9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,10 +15,15 @@ _esy/
esy.lock
# Release script
-dream-*
+dream-*.gz
+dream-*/
# Bisect_ppx
_coverage/
# Humans
scratch/
+
+# Editors
+.vscode/
+*.swp
diff --git a/.gitmodules b/.gitmodules
index f3b0748b..23c0967f 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -12,5 +12,5 @@
url = https://github.com/aantron/ocaml-h2.git
[submodule "src/vendor/paf"]
path = src/vendor/paf
- url = https://github.com/dinosaure/paf-le-chien.git
+ url = https://github.com/aantron/paf-le-chien.git
branch = dream
diff --git a/.ocamlformat b/.ocamlformat
index 9059cdef..7bf428e0 100644
--- a/.ocamlformat
+++ b/.ocamlformat
@@ -1,21 +1,16 @@
-version = 0.19.0
+version = 0.25.1
profile = conventional
leading-nested-match-parens = false
-align-constructors-decl = true
-align-variants-decl = true
space-around-variants = false
space-around-arrays = false
space-around-lists = false
space-around-records = false
-break-before-in = auto
break-infix = fit-or-vertical
break-separators = after
-space-around-records = true
-break-cases = all
+break-cases = fit-or-vertical
cases-exp-indent = 2
exp-grouping = preserve
-nested-match = align
if-then-else = fit-or-vertical
let-and = sparse
type-decl = sparse
diff --git a/LICENSE.md b/LICENSE.md
index 2f5408b0..2440b3ae 100644
--- a/LICENSE.md
+++ b/LICENSE.md
@@ -1,4 +1,4 @@
-Copyright (c) 2021, Anton Bachin
+Copyright (c) 2021-2023, Anton Bachin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/Makefile b/Makefile
index fcd759a3..b95a344f 100644
--- a/Makefile
+++ b/Makefile
@@ -1,31 +1,40 @@
+PACKAGES := dream-pure,dream-httpaf,dream
+
.PHONY : build
build :
- @dune build -p dream --no-print-directory @install
+ @dune build --only-packages $(PACKAGES) --no-print-directory @install
.PHONY : watch
watch :
- @dune build -p dream --no-print-directory -w
+ @dune build --only-packages $(PACKAGES) --no-print-directory @install -w
+
+.PHONY : deps
+deps :
+ opam install --deps-only --with-test ./dream-pure.opam ./dream-httpaf.opam ./dream.opam
+
+TEST ?= test
+ROOT := $(shell [ -f ../dune-workspace ] && echo .. || echo .)
.PHONY : test
test :
- @find . -name '*.coverage' | xargs rm -f
+ @find $(ROOT) -name '*.coverage' | xargs rm -f
@dune build --no-print-directory \
- --instrument-with bisect_ppx --force @test/runtest
+ --instrument-with bisect_ppx --force @$(TEST)/runtest
@bisect-ppx-report html
@bisect-ppx-report summary
@echo See _coverage/index.html
.PHONY : test-watch
test-watch :
- @dune build --no-print-directory -w --root . @test/runtest
+ @dune build --no-print-directory -w @$(TEST)/runtest
.PHONY : coverage-serve
coverage-serve :
- cd _coverage && dune exec -- serve -p 8082
+ cd _coverage && dune exec -- dream-serve -p 8082
.PHONY : promote
promote :
- dune promote --root .
+ dune promote
@make --no-print-directory test
.PHONY : docs
@@ -66,7 +75,7 @@ clean : clean-coverage
dune clean
dune clean --root .
make --no-print-directory -C docs/web clean
- rm -rf src/graphiql/node_modules dream-* _release
+ rm -rf src/graphiql/node_modules
.PHONY : test-ocamlformat
test-ocamlformat :
@@ -92,21 +101,25 @@ todo-all :
VERSION := $(shell git describe --abbrev=0)
RELEASE := dream-$(VERSION)
-FILES := src dream.opam dune-project LICENSE.md README.md
+FILES := \
+ src dream.opam dream-httpaf.opam dream-pure.opam dream-mirage.opam \
+ dune-project LICENSE.md README.md
.PHONY : release
release : clean
rm -rf $(RELEASE) $(RELEASE).tar $(RELEASE).tar.gz _release
- mkdir $(RELEASE)
+ mkdir -p $(RELEASE)
cp -r $(FILES) $(RELEASE)
rm -rf $(RELEASE)/src/vendor/gluten/.github
rm -rf $(RELEASE)/src/vendor/gluten/async
+ rm -rf $(RELEASE)/src/vendor/gluten/eio
rm -rf $(RELEASE)/src/vendor/gluten/mirage
rm -rf $(RELEASE)/src/vendor/gluten/nix
rm -rf $(RELEASE)/src/vendor/httpaf/.github
rm -rf $(RELEASE)/src/vendor/httpaf/async
rm -rf $(RELEASE)/src/vendor/httpaf/benchmarks
rm -rf $(RELEASE)/src/vendor/httpaf/certificates
+ rm -rf $(RELEASE)/src/vendor/httpaf/eio
rm -rf $(RELEASE)/src/vendor/httpaf/examples
rm -rf $(RELEASE)/src/vendor/httpaf/images
rm -rf $(RELEASE)/src/vendor/httpaf/lib_test
@@ -115,6 +128,7 @@ release : clean
rm -rf $(RELEASE)/src/vendor/h2/.github
rm -rf $(RELEASE)/src/vendor/h2/async
rm -rf $(RELEASE)/src/vendor/h2/certificates
+ rm -rf $(RELEASE)/src/vendor/h2/eio
rm -rf $(RELEASE)/src/vendor/h2/examples
rm -rf $(RELEASE)/src/vendor/h2/lib_test
rm -rf $(RELEASE)/src/vendor/h2/mirage
@@ -123,20 +137,30 @@ release : clean
rm -rf $(RELEASE)/src/vendor/h2/vegeta-plot.png
rm -rf $(RELEASE)/src/vendor/websocketaf/.github
rm -rf $(RELEASE)/src/vendor/websocketaf/async
+ rm -rf $(RELEASE)/src/vendor/websocketaf/eio
rm -rf $(RELEASE)/src/vendor/websocketaf/examples
rm -rf $(RELEASE)/src/vendor/websocketaf/lib_test
rm -rf $(RELEASE)/src/vendor/websocketaf/mirage
rm -rf $(RELEASE)/src/vendor/websocketaf/nix
+ rm -rf $(RELEASE)/src/vendor/paf
tar cf $(RELEASE).tar $(RELEASE)
ls -l $(RELEASE).tar
gzip -9 $(RELEASE).tar
mkdir -p _release
cp $(RELEASE).tar.gz _release
(cd _release && tar xf $(RELEASE).tar.gz)
+ opam remove -y dream-pure dream-httpaf dream gluten httpaf h2 websocketaf paf
+ opam pin remove -y dream-pure dream-httpaf dream
+ opam pin add -y --no-action dream-pure _release/$(RELEASE) --kind=path
+ opam pin add -y --no-action dream-httpaf _release/$(RELEASE) --kind=path
opam pin add -y --no-action dream _release/$(RELEASE) --kind=path
opam reinstall -y --verbose dream
+ @echo Run make release-finish to complete after killing the server
cd example/1-hello && dune exec --root . ./hello.exe || true
- opam remove -y dream
- opam pin remove -y dream
+
+.PHONY : release-finish
+release-finish :
+ opam remove -y dream-pure dream-httpaf dream
+ opam pin remove -y dream-pure dream-httpaf dream
md5sum $(RELEASE).tar.gz
ls -l $(RELEASE).tar.gz
diff --git a/README.md b/README.md
index c0d59267..25405410 100644
--- a/README.md
+++ b/README.md
@@ -47,8 +47,8 @@ Dream is **one flat module** in **one package**, documented on
- [**Cryptography**][crypto] helpers, key rotation, and a chosen cipher.
- A neat [**logger**][logging], and attention to configuring the OCaml runtime
nicely.
-- [**Deployment**][deploy] instructions for **Digital Ocean** and **Heroku**,
- with sample CI scripts.
+- [**Deployment**][deploy] instructions for **Digital Ocean**, **Heroku**, and
+ **Fly.io**, with sample CI scripts.
@@ -110,49 +110,37 @@ into.
## Quick start
-
+Visit one of the first tutorials in the [online
+playground][2-middleware-playground], and read its
+[docs](https://github.com/aantron/dream/tree/master/example/2-middleware#files).
+You can get and build it locally with:
bash -c "$(curl -fsSL https://raw.githubusercontent.com/aantron/dream/master/example/quickstart.sh)"-