Skip to content

Commit 3f5feb4

Browse files
author
Lucas Pluvinage
committed
new dunification of zarith
1 parent 53603d5 commit 3f5feb4

File tree

8 files changed

+245
-43
lines changed

8 files changed

+245
-43
lines changed

.github/workflows/CI.yml

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,38 @@ name: CI
33
on: [push, pull_request]
44

55
jobs:
6-
Ubuntu:
7-
runs-on: ubuntu-latest
6+
test:
7+
strategy:
8+
matrix:
9+
operating-system: [ubuntu-latest]
10+
ocaml-version: [4.10.0, 4.11.0]
11+
runs-on: ${{ matrix.operating-system }}
812
steps:
9-
- name: Install packages
10-
run: sudo apt-get install ocaml-nox libgmp-dev
11-
- name: Checkout
12-
uses: actions/checkout@v2
13-
- name: configure tree
14-
run: ./configure
15-
- name: Build
16-
run: make
17-
- name: Run the testsuite
18-
run: make -C tests test
19-
20-
MacOS:
21-
runs-on: macos-latest
22-
steps:
23-
- name: Install packages
24-
run: brew install ocaml ocaml-findlib gmp
25-
- name: Checkout
26-
uses: actions/checkout@v2
27-
- name: configure tree
28-
run: ./configure
29-
- name: Build
30-
run: make
31-
- name: Run the testsuite
32-
run: make -C tests test
13+
- uses: actions/checkout@v2
14+
- uses: actions-ml/setup-ocaml@master
15+
with:
16+
ocaml-version: ${{ matrix.ocaml-version }}
17+
- name: Pin solo5
18+
run: opam pin -n -y git+https://github.com/mato/solo5#new-toolchain
19+
- name: Pin ocaml-freestanding
20+
run: opam pin -n -y git+https://github.com/TheLortex/ocaml-freestanding#mirage-4-staging
21+
- name: Pin ocaml-gmp
22+
run: opam pin -n -y git+https://github.com/mirage/ocaml-gmp.git#master
23+
- name: Dune, global GMP
24+
run: opam depext -iyt conf-gmp dune
25+
- name: Compiling example project (host)
26+
run: opam exec -- dune build @install
27+
- name: Running tests (host)
28+
run: opam exec -- dune runtest
29+
- name: External dependencies for bindings
30+
run: opam depext -iyt ocaml-freestanding
31+
- name: Dune and opam-monorepo
32+
run: opam install -t -y dune opam-monorepo
33+
- name: Run opam-monorepo
34+
run: |
35+
opam monorepo lock
36+
opam monorepo pull
37+
- name: Compiling example project (freestanding)
38+
run: opam exec -- dune build @install --workspace dune-workspace.freestanding
39+
- name: Running tests (freestanding)
40+
run: opam exec -- dune runtest --workspace dune-workspace.freestanding

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
Makefile
1111
depend
1212
zarith_version.ml
13+
_build
14+
duniverse
15+
zarith.opam.locked

dune

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
(env
2+
(dev
3+
(flags
4+
(:standard -w -6))))
5+
6+
(library
7+
(name zarith)
8+
(public_name zarith)
9+
(modules z q big_int_Z zarith_version)
10+
(wrapped false)
11+
(foreign_stubs
12+
(language c)
13+
(names caml_z)
14+
(flags
15+
:standard
16+
(:include cflags.sxp)))
17+
(c_library_flags
18+
(:include libs.sxp)))
19+
20+
(rule
21+
(target Makefile)
22+
(deps configure config.guess env)
23+
(action
24+
(bash "env %{read:env} ./configure")))
25+
26+
(rule
27+
(target env)
28+
(deps env-%{lib-available:gmp})
29+
(action
30+
(copy env-%{lib-available:gmp} env)))
31+
32+
(rule
33+
(target env-false)
34+
(action
35+
(with-stdout-to
36+
%{target}
37+
(bash "echo -n CC=\\\"%{cc}\\\""))))
38+
39+
(rule
40+
(target env-true)
41+
(deps
42+
(package gmp))
43+
(action
44+
(with-stdout-to
45+
%{target}
46+
(bash
47+
"echo -n CC=\\\"%{cc}\\\" LDFLAGS=\\\"-L$(realpath $(dirname %{lib:gmp:libgmp.a}))\\\" CFLAGS=\\\"-I$(realpath $(dirname %{lib:gmp:libgmp.a}))\\\" CPPFLAGS=\\\"-I$(realpath $(dirname %{lib:gmp:libgmp.a}))\\\""))))
48+
49+
(rule
50+
(target cflags.sxp)
51+
(deps Makefile)
52+
(action
53+
(with-stdout-to
54+
%{target}
55+
(progn
56+
(bash "echo -n '('")
57+
(bash "cat Makefile | sed -n -e 's/CFLAGS=//p'")
58+
(bash "echo -n ')'")))))
59+
60+
(rule
61+
(target libs.sxp)
62+
(deps Makefile)
63+
(action
64+
(with-stdout-to
65+
%{target}
66+
(progn
67+
(bash "echo -n '('")
68+
(bash "cat Makefile | sed -n -e 's/LIBS=//p'")
69+
(bash "echo -n ')'")))))
70+
71+
(rule
72+
(deps META)
73+
(action
74+
(with-stdout-to
75+
zarith_version.ml
76+
(progn
77+
(run echo "let")
78+
(bash "grep \"version\" META | head -1")))))
79+
80+
(library
81+
(name zarith_top)
82+
(optional)
83+
(public_name zarith.top)
84+
(modules zarith_top)
85+
(libraries zarith compiler-libs.toplevel))

dune-project

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
(lang dune 2.8)
2+
(name zarith)

dune-workspace.freestanding

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(lang dune 1.10)
2+
3+
(context (default))
4+
5+
(context (default
6+
(name freestanding)
7+
(toolchain freestanding)
8+
(host default)
9+
))

tests/dune

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
; Run test for host
2+
3+
(executable
4+
(enabled_if
5+
(= %{context_name} default))
6+
(name zq)
7+
(modules zq)
8+
(libraries zarith))
9+
10+
(rule
11+
(enabled_if
12+
(= %{context_name} default))
13+
(action
14+
(with-stdout-to
15+
zq.output
16+
(run ./zq.exe))))
17+
18+
; Run test for Solo5 SPT target
19+
20+
(rule
21+
(copy zq.ml zq_freestanding.ml))
22+
23+
(rule (with-stdout-to startup.c (echo """
24+
#include <solo5.h>
25+
#define CAML_NAME_SPACE
26+
#include <caml/callback.h>
27+
28+
static char *unused_argv[] = { \"mirage\", NULL };
29+
30+
void _nolibc_init(uintptr_t heap_start, size_t heap_size); // defined in solo5-libc/sysdeps_solo5.c
31+
32+
int solo5_app_main(const struct solo5_start_info *si) {
33+
_nolibc_init(si->heap_start, si->heap_size);
34+
caml_startup(unused_argv);
35+
}
36+
""")))
37+
38+
(rule (with-stdout-to manifest.json (echo """
39+
{
40+
\"type\": \"solo5.manifest\",
41+
\"version\": 1,
42+
\"devices\": []
43+
}
44+
""")))
45+
46+
(executable
47+
(enabled_if
48+
(= %{context_name} freestanding))
49+
(name zq_freestanding)
50+
(modules zq_freestanding)
51+
(libraries zarith)
52+
(link_flags :standard -cclib "-z solo5-abi=spt")
53+
(foreign_stubs
54+
(language c)
55+
(names startup manifest)))
56+
57+
(rule
58+
(enabled_if
59+
(= %{context_name} freestanding))
60+
(targets manifest.c)
61+
(deps manifest.json)
62+
(action
63+
(run solo5-elftool gen-manifest manifest.json manifest.c)))
64+
65+
; Run solo5 code
66+
67+
(rule
68+
(enabled_if
69+
(= %{context_name} freestanding))
70+
(deps zq_freestanding.exe)
71+
(action
72+
(with-accepted-exit-codes
73+
1
74+
(with-stdout-to
75+
zq.output.full
76+
(run solo5-spt zq_freestanding.exe)))))
77+
78+
; Remove solo5 intro
79+
80+
(rule
81+
(enabled_if
82+
(= %{context_name} freestanding))
83+
(deps zq.output.full)
84+
(action
85+
(with-stdout-to
86+
zq.output
87+
(bash "head -n -1 zq.output.full | tail -n +12 -"))))
88+
89+
; Check results
90+
91+
(rule
92+
(alias runtest)
93+
(action
94+
(diff zq.expected zq.output)))
95+
96+
(rule
97+
(target zq.expected)
98+
(enabled_if
99+
(= %{arch_sixtyfour} true))
100+
(action
101+
(copy zq.output64 %{target})))
102+
103+
(rule
104+
(target zq.expected)
105+
(enabled_if
106+
(= %{arch_sixtyfour} false))
107+
(action
108+
(copy zq.output32 %{target})))

tests/zq.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,3 +825,4 @@ let test_Q () =
825825

826826
let _ = test_Z()
827827
let _ = test_Q()
828+
let _ = flush stdout

zarith.opam

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,12 @@ homepage: "https://github.com/ocaml/Zarith"
1010
bug-reports: "https://github.com/ocaml/Zarith/issues"
1111
dev-repo: "git+https://github.com/ocaml/Zarith.git"
1212
build: [
13-
["./configure"] {os != "openbsd" & os != "freebsd" & os != "macos"}
14-
[
15-
"sh"
16-
"-exc"
17-
"LDFLAGS=\"$LDFLAGS -L/usr/local/lib\" CFLAGS=\"$CFLAGS -I/usr/local/include\" ./configure"
18-
] {os = "openbsd" | os = "freebsd"}
19-
[
20-
"sh"
21-
"-exc"
22-
"LDFLAGS=\"$LDFLAGS -L/opt/local/lib -L/usr/local/lib\" CFLAGS=\"$CFLAGS -I/opt/local/include -I/usr/local/include\" ./configure"
23-
] {os = "macos"}
24-
[make]
25-
]
26-
install: [
27-
[make "install"]
13+
["dune" "build" "-p" "zarith" ]
2814
]
2915
depends: [
3016
"ocaml" {>= "4.04.0"}
31-
"ocamlfind"
32-
"conf-gmp"
17+
"dune"
18+
"gmp" | "conf-gmp"
3319
]
3420
synopsis:
3521
"Implements arithmetic and logical operations over arbitrary-precision integers"

0 commit comments

Comments
 (0)