Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 77 additions & 23 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,84 @@ name: CI
on: [push, pull_request]

jobs:
Ubuntu:
runs-on: ubuntu-latest
Host-Freestanding:
strategy:
matrix:
operating-system: [ubuntu-latest]
ocaml-version: [4.10.2, 4.11.2]
runs-on: ${{ matrix.operating-system }}
steps:
- name: Install packages
run: sudo apt-get install ocaml-nox libgmp-dev
- name: Checkout
uses: actions/checkout@v2
- name: configure tree
run: ./configure
- name: Build
run: make
- name: Run the testsuite
run: make -C tests test

- uses: actions/checkout@v2
- uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-version }}
dune-cache: true
opam-local-packages: |
!zarith.opam
- name: Add mirage-dev repository
run: opam repo add mirage-dev git+https://github.com/mirage/mirage-dev.git#master
- name: Pin ocaml-gmp
run: opam pin -n -y git+https://github.com/TheLortex/ocaml-gmp.git#master
- name: Dune, global GMP
run: opam depext -iyt conf-gmp dune
- name: Compiling example project (host)
run: opam exec -- dune build @install
- name: Running tests (host)
run: opam exec -- dune runtest
- name: External dependencies for bindings
run: opam depext -iyt ocaml-freestanding
- name: Dune and opam-monorepo
run: opam install -t -y dune opam-monorepo
- name: Run opam-monorepo
run: |
opam monorepo lock
opam monorepo pull
- name: Compiling example project (freestanding)
run: opam exec -- dune build @install --workspace dune-workspace.freestanding
- name: Running tests (freestanding)
run: opam exec -- dune runtest --workspace dune-workspace.freestanding
MacOS:
runs-on: macos-latest
steps:
- name: Install packages
run: brew install ocaml ocaml-findlib gmp
- name: Checkout
uses: actions/checkout@v2
- name: configure tree
run: ./configure
- name: Build
run: make
- name: Run the testsuite
run: make -C tests test
- uses: actions/checkout@v2
- uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 4.11.2
dune-cache: true
opam-local-packages: |
!zarith.opam
- name: Dune, global GMP
run: opam depext -iyt conf-gmp dune
- name: Compiling example project (switch)
run: opam exec -- dune build @install
- name: Running tests (switch)
run: opam exec -- dune runtest
- name: Pin ocaml-gmp
run: opam pin -n -y git+https://github.com/TheLortex/ocaml-gmp.git#master
- name: Run opam-monorepo
run: |
opam monorepo lock
opam monorepo pull
- name: Compiling example project (monorepo)
run: opam exec -- dune build @install
- name: Running tests (monorepo)
run: opam exec -- dune runtest

Ubuntu-GMP:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 4.11.2
dune-cache: true
opam-local-packages: |
!zarith.opam
- name: Pin ocaml-gmp
run: opam pin -n -y git+https://github.com/mirage/ocaml-gmp.git#master
- name: Dune, global GMP
run: opam depext -iyt gmp dune
- name: Compiling example project
run: opam exec -- dune build @install
- name: Running tests
run: opam exec -- dune runtest
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@
Makefile
depend
zarith_version.ml
_build
duniverse
zarith.opam.locked
90 changes: 90 additions & 0 deletions dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
(env
(dev
(flags
(:standard -w -6))))

(library
(name zarith)
(public_name zarith)
(modules z q big_int_Z zarith_version)
(wrapped false)
(foreign_stubs
(language c)
(names caml_z)
(flags
:standard
(:include cflags.sxp)))
(c_library_flags
(:include libs.sxp)))

(rule
(target Makefile)
(deps configure config.guess env)
(action
(with-stdout-to
config.log
(bash "env %{read:env} ./configure"))))

(rule
(target env)
(deps env-%{lib-available:gmp})
(action
(copy env-%{lib-available:gmp} env)))

(rule
(target env-false)
(action
(with-stdout-to
%{target}
(bash "echo -n CC=\\\"%{cc}\\\""))))

(rule
(target env-true)
(deps
%{lib:gmp:libgmp.a}
%{lib:gmp:libgmp.so}
%{lib:gmp:gmp.h}
%{workspace_root})
(action
(with-stdout-to
%{target}
(bash
"echo -n CC=\\\"%{cc}\\\" LDFLAGS=\\\"-L$PWD/$(dirname %{lib:gmp:libgmp.a})\\\" CFLAGS=\\\"-I$PWD/$(dirname %{lib:gmp:libgmp.a})\\\" CPPFLAGS=\\\"-I$PWD/$(dirname %{lib:gmp:libgmp.a})\\\""))))

(rule
(target cflags.sxp)
(deps Makefile)
(action
(with-stdout-to
%{target}
(progn
(bash "echo -n '('")
(bash "cat Makefile | sed -n -e 's/CFLAGS=//p'")
(bash "echo -n ')'")))))

(rule
(target libs.sxp)
(deps Makefile)
(action
(with-stdout-to
%{target}
(progn
(bash "echo -n '('")
(bash "cat Makefile | sed -n -e 's/LIBS=//p'")
(bash "echo -n ')'")))))

(rule
(deps META)
(action
(with-stdout-to
zarith_version.ml
(progn
(run echo "let")
(bash "grep \"version\" META | head -1")))))

(library
(name zarith_top)
(optional)
(public_name zarith.top)
(modules zarith_top)
(libraries zarith compiler-libs.toplevel))
2 changes: 2 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(lang dune 2.8)
(name zarith)
9 changes: 9 additions & 0 deletions dune-workspace.freestanding
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(lang dune 1.10)

(context (default))

(context (default
(name freestanding)
(toolchain freestanding)
(host default)
))
108 changes: 108 additions & 0 deletions tests/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
; Run test for host

(executable
(enabled_if
(= %{context_name} default))
(name zq)
(modules zq)
(libraries zarith))

(rule
(enabled_if
(= %{context_name} default))
(action
(with-stdout-to
zq.output
(run ./zq.exe))))

; Run test for Solo5 SPT target

(rule
(copy zq.ml zq_freestanding.ml))

(rule (with-stdout-to startup.c (echo """
#include <solo5.h>
#define CAML_NAME_SPACE
#include <caml/callback.h>

static char *unused_argv[] = { \"mirage\", NULL };

void _nolibc_init(uintptr_t heap_start, size_t heap_size); // defined in solo5-libc/sysdeps_solo5.c

int solo5_app_main(const struct solo5_start_info *si) {
_nolibc_init(si->heap_start, si->heap_size);
caml_startup(unused_argv);
}
""")))

(rule (with-stdout-to manifest.json (echo """
{
\"type\": \"solo5.manifest\",
\"version\": 1,
\"devices\": []
}
""")))

(executable
(enabled_if
(= %{context_name} freestanding))
(name zq_freestanding)
(modules zq_freestanding)
(libraries zarith)
(link_flags :standard -cclib "-z solo5-abi=spt")
(foreign_stubs
(language c)
(names startup manifest)))

(rule
(enabled_if
(= %{context_name} freestanding))
(targets manifest.c)
(deps manifest.json)
(action
(run solo5-elftool gen-manifest manifest.json manifest.c)))

; Run solo5 code

(rule
(enabled_if
(= %{context_name} freestanding))
(deps zq_freestanding.exe)
(action
(with-accepted-exit-codes
1
(with-stdout-to
zq.output.full
(run solo5-spt zq_freestanding.exe)))))

; Remove solo5 intro

(rule
(enabled_if
(= %{context_name} freestanding))
(deps zq.output.full)
(action
(with-stdout-to
zq.output
(bash "head -n -1 zq.output.full | tail -n +12 -"))))

; Check results

(rule
(alias runtest)
(action
(diff zq.expected zq.output)))

(rule
(target zq.expected)
(enabled_if
(= %{arch_sixtyfour} true))
(action
(copy zq.output64 %{target})))

(rule
(target zq.expected)
(enabled_if
(= %{arch_sixtyfour} false))
(action
(copy zq.output32 %{target})))
1 change: 1 addition & 0 deletions tests/zq.ml
Original file line number Diff line number Diff line change
Expand Up @@ -825,3 +825,4 @@ let test_Q () =

let _ = test_Z()
let _ = test_Q()
let _ = flush stdout
20 changes: 3 additions & 17 deletions zarith.opam
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,12 @@ homepage: "https://github.com/ocaml/Zarith"
bug-reports: "https://github.com/ocaml/Zarith/issues"
dev-repo: "git+https://github.com/ocaml/Zarith.git"
build: [
["./configure"] {os != "openbsd" & os != "freebsd" & os != "macos"}
[
"sh"
"-exc"
"LDFLAGS=\"$LDFLAGS -L/usr/local/lib\" CFLAGS=\"$CFLAGS -I/usr/local/include\" ./configure"
] {os = "openbsd" | os = "freebsd"}
[
"sh"
"-exc"
"LDFLAGS=\"$LDFLAGS -L/opt/local/lib -L/usr/local/lib\" CFLAGS=\"$CFLAGS -I/opt/local/include -I/usr/local/include\" ./configure"
] {os = "macos"}
[make]
]
install: [
[make "install"]
["dune" "build" "-p" "zarith" ]
]
depends: [
"ocaml" {>= "4.04.0"}
"ocamlfind"
"conf-gmp"
"dune"
"gmp" | "conf-gmp"
]
synopsis:
"Implements arithmetic and logical operations over arbitrary-precision integers"
Expand Down