Skip to content

Commit 65e3630

Browse files
author
Lucas Pluvinage
committed
Take advantage of host gmp when possible.
1 parent 276f3d6 commit 65e3630

File tree

3 files changed

+72
-20
lines changed

3 files changed

+72
-20
lines changed

.github/workflows/CI.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@ jobs:
1616
ocaml-version: ${{ matrix.ocaml-version }}
1717
- name: Add mirage-dev repository
1818
run: opam repo add mirage-dev git+https://github.com/mirage/mirage-dev#mirage-4
19-
- name: External dependencies
20-
run: opam depext -yt ocaml-freestanding solo5-bindings-spt
21-
- name: Install ocaml-freestanding, bindings, dune and opam-monorepo
22-
run: opam install -t -y ocaml-freestanding solo5-bindings-spt dune opam-monorepo
19+
- name: Pin ocaml-gmp
20+
run: opam pin -n -y git+https://github.com/mirage/ocaml-gmp.git#install-dynlib
21+
- name: Dune, global GMP
22+
run: opam depext -iyt conf-gmp dune
23+
- name: Compiling example project (host)
24+
run: opam exec -- dune build @install
25+
- name: Running tests (host)
26+
run: opam exec -- dune runtest
27+
- name: External dependencies for bindings
28+
run: opam depext -iyt ocaml-freestanding solo5-bindings-spt
29+
- name: Dune and opam-monorepo
30+
run: opam install -t -y dune opam-monorepo
2331
- name: Run opam-monorepo
2432
run: |
2533
opam monorepo lock
2634
opam monorepo pull
27-
- name: Compiling example project
28-
run: opam exec -- dune build --workspace dune-workspace.freestanding
29-
- name: Running tests
35+
- name: Compiling example project (freestanding)
36+
run: opam exec -- dune build @install --workspace dune-workspace.freestanding
37+
- name: Running tests (freestanding)
3038
run: opam exec -- dune runtest --workspace dune-workspace.freestanding

dune

Lines changed: 56 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,68 @@
44
(name zarith)
55
(public_name zarith)
66
(modules z q big_int_Z zarith_version)
7+
(wrapped false)
78
(foreign_stubs
8-
(language c)
9-
(names caml_z)
10-
(include_dirs (lib gmp))
11-
(flags :standard "-DHAS_GMP")
9+
(language c)
10+
(names caml_z)
11+
(flags :standard "-DHAS_GMP" (:include cflags.sxp))
1212
)
13-
(libraries gmp)
14-
(wrapped false))
13+
(c_library_flags (:include libs.sxp))
14+
)
15+
16+
(rule
17+
(target conf-gmp-cflags-false) ; global gmp
18+
(action (with-stdout-to %{target} (
19+
run echo "()"
20+
)))
21+
)
22+
23+
(rule
24+
(target conf-gmp-cflags-true) ; self built gmp
25+
(deps (package gmp))
26+
(action (with-stdout-to %{target} (
27+
bash "echo \"(-I$(dirname %{lib:gmp:META}))\""
28+
)))
29+
)
30+
31+
(rule
32+
(target cflags.sxp)
33+
(deps (:cflags conf-gmp-cflags-%{lib-available:gmp}))
34+
(action (copy %{cflags} cflags.sxp))
35+
)
36+
37+
38+
(rule
39+
(target conf-gmp-lib-false) ; global gmp
40+
(action (with-stdout-to %{target} (
41+
run echo "(-lgmp)"
42+
)))
43+
)
44+
45+
(rule
46+
(target conf-gmp-lib-true) ; self built gmp
47+
(deps (package gmp))
48+
(action (with-stdout-to %{target} (
49+
bash "echo \"(\\\"-L$(dirname %{lib:gmp:libgmp.so})\\\" -lgmp)\""
50+
)))
51+
)
52+
53+
(rule
54+
(target libs.sxp)
55+
(deps (:lib conf-gmp-lib-%{lib-available:gmp}))
56+
(action (copy %{lib} libs.sxp))
57+
)
58+
59+
(rule
60+
(deps META)
61+
(action (with-stdout-to zarith_version.ml (progn
62+
(run echo "let")
63+
(bash "grep \"version\" META | head -1")
64+
))))
1565

1666
(library
1767
(name zarith_top)
1868
(optional)
1969
(public_name zarith.top)
2070
(modules zarith_top)
2171
(libraries zarith compiler-libs.toplevel))
22-
23-
(rule
24-
(action (with-stdout-to zarith_version.ml (progn
25-
(run echo "let")
26-
(bash "grep \"version\" META | head -1")
27-
))))

zarith.opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ build: [
1414
]
1515
depends: [
1616
"ocaml" {>= "4.08.0"}
17-
"gmp"
17+
"gmp" | "conf-gmp"
1818
]
1919
synopsis:
2020
"Implements arithmetic and logical operations over arbitrary-precision integers"

0 commit comments

Comments
 (0)