Skip to content

Commit ddd176a

Browse files
committed
Add a GitHub action for Esperanto
1 parent 80d6996 commit ddd176a

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

.github/workflows/esperanto.yml

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Esperanto support
2+
on: [ push ]
3+
jobs:
4+
test:
5+
strategy:
6+
matrix:
7+
operating-system: [ ubuntu-latest ]
8+
ocaml-version: [ "4.13.1", "4.14.0" ]
9+
local-packages:
10+
- |
11+
*.opam
12+
!lwt_domain.opam
13+
runs-on: ${{ matrix.operating-system }}
14+
steps:
15+
- uses: actions/checkout@v2
16+
- uses: ocaml/setup-ocaml@v2
17+
with:
18+
ocaml-compiler: ${{ matrix.ocaml-version }}
19+
opam-local-packages: ${{ matrix.local-packages }}
20+
- name: Fix binfmt and Cosmopolitan
21+
run: sudo sh -c "echo ':APE:M::MZqFpD::/bin/sh:' >/proc/sys/fs/binfmt_misc/register"
22+
- name: Pin Esperanto
23+
run: opam pin add git+https://github.com/dinosaure/esperanto
24+
- name: Install Esperanto, Dune & ocamlfind
25+
run: opam install cosmopolitan cosmopolitan-pth esperanto dune ocamlfind
26+
- name: Install opam-monorepo
27+
run: opam install opam-monorepo
28+
- name: Add opam-monorepo overlays
29+
run: opam repo add dune-universe git+https://github.com/dune-universe/opam-overlays.git
30+
- name: Example with LWT & Esperanto
31+
run: |
32+
mkdir esperanto-example
33+
cd esperanto-example
34+
cat >dune-workspace <<EOF
35+
(lang dune 2.0)
36+
(context (default))
37+
(context
38+
(default
39+
(name esperanto)
40+
(toolchain esperanto)
41+
(host default)))
42+
EOF
43+
cat >dune-project <<EOF
44+
(lang dune 2.0)
45+
EOF
46+
cat >cat.ml <<EOF
47+
open Lwt.Infix
48+
49+
let rec fill_write fd buf off len =
50+
Lwt_unix.write fd buf off len >>= fun len' ->
51+
if len - len' > 0
52+
then full_write fd buf (off + len') (len - len')
53+
else Lwt.return_unit
54+
55+
let tmp = Bytes.create 0x1000
56+
57+
let rec cat () =
58+
Lwt.catch begin fun () ->
59+
Lwt_unix.read Lwt_unix.stdin tmp 0 (Bytes.length tmp) >>= fun len ->
60+
match len with
61+
| 0 -> Lwt.return_unit
62+
| len -> full_write Lwt_unix.stdout tmp 0 len >>= cat
63+
end @@ function
64+
| End_of_file -> Lwt.return_unit
65+
| exn -> raise exn
66+
67+
let () = Lwt_main.run (cat ())
68+
EOF
69+
cat >dune <<EOF
70+
(executable
71+
(name cat)
72+
(libraries lwt.unix))
73+
74+
(rule
75+
(target cat.com)
76+
(enabled_if (= %{context_name} esperanto))
77+
(mode promote)
78+
(deps cat.exe)
79+
(action (run objcopy -S -O binary %{deps} %{target})))
80+
EOF
81+
cat >cat.opam <<EOF
82+
opam-version: "2.0"
83+
name: "cat"
84+
maintainer: [ "Romain Calascibetta <[email protected]>" ]
85+
authors: [ "Romain Calascibetta <[email protected]>" ]
86+
homepage: "https://github.com/dinosaure/esperanto"
87+
bug-reports: "https://github.com/dinosaure/esperanto/issues"
88+
dev-repo: "git+https://github.com/dinosaure/esperanto"
89+
doc: "https://dinosaure.github.io/esperanto/"
90+
license: "MIT"
91+
synopsis: "The cat.com tool produced by esperanto"
92+
description: "The cat.com tool produced by esperanto"
93+
94+
build: [
95+
[ "dune" "build" "-p" name "-j" jobs ]
96+
]
97+
install: [
98+
[ "dune" "install" "-p" name ] {with-test}
99+
]
100+
101+
depends: [
102+
"ocaml" {>= "4.12.0"}
103+
"dune" {>= "2.8.0"}
104+
"lwt"
105+
]
106+
EOF
107+
opam monorepo lock
108+
opam monorepo pull
109+
opam exec -- dune build ./cat.com
110+
./cat.com < cat.ml

0 commit comments

Comments
 (0)