Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] [wip] Support for the dune build system v2 #143

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 14 additions & 10 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install packages
run: sudo apt-get install ocaml-nox libgmp-dev
run: sudo apt-get install ocaml-nox libgmp-dev opam
- name: Checkout
uses: actions/checkout@v2
- name: configure tree
run: ./configure
- name: init opam
run: opam init
- name: install deps
run: opam install . --deps-only --with-test --yes
- name: Build
run: make
run: opam exec -- dune build
- name: Run the testsuite
run: make -C tests test
run: opam exec -- dune runtest

MacOS:
runs-on: macos-latest
steps:
- name: Install packages
run: brew install ocaml ocaml-findlib gmp
run: brew install ocaml ocaml-findlib gmp opam
- name: Checkout
uses: actions/checkout@v2
- name: configure tree
run: ./configure
- name: init opam
run: opam init
- name: install deps
run: opam install . --deps-only --with-test --yes
- name: Build
run: make
run: opam exec -- dune build
- name: Run the testsuite
run: make -C tests test
run: opam exec -- dune runtest
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ jobs:
opam-depext: true
opam-depext-flags: --with-test

- name: configure tree
run: opam exec -- ./configure
- name: install deps
run: opam install . --deps-only --with-test --yes

- name: Build
run: opam exec -- make
run: opam exec -- dune build

- name: Run the testsuite
run: opam exec -- make -C tests test
run: opam exec -- dune runtest

- run: opam install . --with-test

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@
Makefile
depend
zarith_version.ml
_build
.merlin
c-flags.sexp
library-flags.sexp
4 changes: 4 additions & 0 deletions DUNE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- why use -linkall for zarith.cmxs ?
- do we need -failsafe when calling OCAMLMKLIB
- do we need -O3 -Wall -Wextra
- we not longer test bytecode
18 changes: 0 additions & 18 deletions META

This file was deleted.

51 changes: 17 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,20 @@ Additional features include:
* OCaml, version 4.04.0 or later.
* Either the GMP library or the MPIR library, including development files.
* GCC or Clang or a gcc-compatible C compiler and assembler (other compilers may work).
* The Findlib package manager (optional, recommended).
* dune, version 2.7 or later


## INSTALLATION

1) First, run the "configure" script by typing:
1) First, build with
```
./configure
dune build
```
The `configure` script has a few options. Use the `-help` option to get a
list and short description of each option.

2) It creates a Makefile, which can be invoked by:
```
make
```
This builds native and bytecode versions of the library.

3) The libraries are installed by typing:
```
make install
```
or, if you install to a system location but are not an administrator
```
sudo make install
dune install
```
If Findlib is detected, it is used to install files.
Otherwise, the files are copied to a `zarith/` subdirectory of the directory
given by `ocamlc -where`.

The libraries are named `zarith.cmxa` and `zarith.cma`, and the Findlib module
is named `zarith`.
Expand All @@ -70,13 +55,13 @@ option to `ocamlc` / `ocamlopt`, or the `-package zarith` option to `ocamlfind`.

4) (optional, recommended) Test programs are built and run by the additional command
```
make tests
dune runtest
```
(but these are not installed).

5) (optional) HTML API documentation is built (using `ocamldoc`) by the additional command
5) (optional) HTML API documentation is built (using `odoc`) by the additional command
```
make doc
dune build @doc
```

## ONLINE DOCUMENTATION
Expand Down Expand Up @@ -112,15 +97,13 @@ INRIA Rocquencourt (Institut national de recherche en informatique, France).

## CONTENTS

Source files | Description
--------------------|-----------------------------------------
configure | configuration script
z.ml[i] | Z module and implementation for small integers
caml_z.c | C implementation
big_int_z.ml[i] | wrapper to provide a Big_int compatible API to Z
q.ml[i] | rational library, pure OCaml on top of Z
zarith_top.ml | toplevel module to provide pretty-printing
projet.mak | builds Z, Q and the tests
zarith.opam | package description for opam
z_mlgmpidl.ml[i] | conversion between Zarith and MLGMPIDL
tests/ | simple regression tests and benchmarks
Source files | Description
----- ------------------|-----------------------------------------
src/z.ml[i] | Z module and implementation for small integers
src/caml_z.c | C implementation
src/big_int_z.ml[i] | wrapper to provide a Big_int compatible API to Z
src/q.ml[i] | rational library, pure OCaml on top of Z
src/top/zarith_top.ml | toplevel module to provide pretty-printing
zarith.opam | package description for opam
z_mlgmpidl/* | conversion between Zarith and MLGMPIDL
tests/ | simple regression tests and benchmarks
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.13
88 changes: 88 additions & 0 deletions config/discover.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
module C = Configurator.V1

module Version = struct
type t = { major : int; minor : int }

let num = function '0' .. '9' -> true | _ -> false

let of_string_exn s : t =
try Scanf.sscanf s "%d.%d" (fun major minor -> { major; minor })
with _ -> failwith (Printf.sprintf "unable to parse ocaml version %S" s)

let compare a b =
match compare a.major b.major with 0 -> compare a.minor b.minor | n -> n
end

type libmode = [ `Auto | `Gmp | `Mpir ]

let lib : libmode ref = ref `Auto
let perf = ref false

let lookup_with_pkg_config c ~lib =
match C.Pkg_config.get c with
| None -> None
| Some pc -> (
match C.Pkg_config.query pc ~package:lib with
| Some deps -> Some deps
| None -> None)

let lookup_manually c ~lib ~include_h =
let libflag = Printf.sprintf "-l%s" lib in
let c_code =
Printf.sprintf {|
#include <%s>"
int main() { return 1; }
|} include_h
in
if C.c_test c ~link_flags:[ libflag ] c_code then
Some { C.Pkg_config.libs = [ libflag ]; cflags = [] }
else None

let () =
C.main
~args:
[
( "-gmp",
Unit (fun () -> lib := `Gmp),
"use GMP library (default if found)" );
( "-mpir",
Unit (fun () -> lib := `Mpir),
"use MPIR library instead of GMP" );
("-perf", Set perf, "enable performance statistics");
]
~name:"zarith"
(fun c ->
let version =
Version.of_string_exn (C.ocaml_config_var_exn c "version")
in
let use_legacy =
Version.compare version { Version.major = 4; minor = 8 } < 0
in
let find_one ~lib ~include_h =
match lookup_with_pkg_config c ~lib with
| Some x -> x
| None -> match lookup_manually c ~lib ~include_h with
| Some x -> x
| None -> failwith (Printf.sprintf "Unable to find the %s c library" lib)
in

let backend, conf =
let rec find = function
| `Auto -> (
try find `Gmp with e -> ( try find `Mpir with _ -> raise e))
| `Gmp -> (`Gmp, find_one ~lib:"gmp" ~include_h:"gmp.h")
| `Mpir -> (`Mpir, find_one ~lib:"mpir" ~include_h:"mpir.h")
in
find !lib
in
let defs =
match backend with `Gmp -> [ "-DHAS_GMP" ] | `Mpir -> [ "-DHAS_MPIR" ]
in
let defs = if !perf then "-DZ_PERF_COUNTER" :: defs else defs in
let defs =
if use_legacy then "DZ_OCAML_LEGACY_CUSTOM_OPERATIONS" :: defs else defs
in

C.Flags.write_sexp "c-flags.sexp"
(conf.cflags @ defs (* @ [ "-O3"; "-Wall"; "-Wextra" ] *));
C.Flags.write_sexp "c-library-flags.sexp" conf.libs)
3 changes: 3 additions & 0 deletions config/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name discover)
(libraries dune-configurator))