Skip to content

Commit

Permalink
Dunify the build
Browse files Browse the repository at this point in the history
  • Loading branch information
tmattio committed Nov 5, 2023
1 parent b975908 commit d64f883
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 35 deletions.
16 changes: 5 additions & 11 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,20 @@ 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 ocaml-dune 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
run: rm -rf tests && dune build

MacOS:
runs-on: macos-latest
steps:
- name: Install packages
run: brew install ocaml ocaml-findlib gmp
run: brew install ocaml gmp dune
- name: Checkout
uses: actions/checkout@v2
- name: configure tree
run: ./configure
- name: Build
run: make
run: dune build
- name: Run the testsuite
run: make -C tests test
run: dune test
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 1.12+dune (2022-04-01)

- PR #1: dunify the package and allow the cross-compilation via `opam monorepo`
[Romain Calascibetta, Lucas Pluvinage, Thomas Gazagnaire]
8 changes: 4 additions & 4 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Release 1.9 (2019-08-22):
- Issue #50: add opam file, make it easy to "opam publish" new versions
- Issue #38: configure detects 32bit OCaml switch on 64bit host
- Fix #36: change Q.equal, leq, geq comparisons for undef
- Request #47: move infix comparison operators of Z in submodule
- Request #47: move infix comparison operators of Z in submodule
avoid shadowing the polymorphic compare [Bernhard Schommer]
- Fix #49: INT_MAX undeclared
- Request #46: add prefixnonocaml option [Et7f3]
Expand All @@ -59,9 +59,9 @@ Release 1.8 (2019-03-30):
- Issue #22: wrong stack marking directive in caml_z_x86_64_mingw64.S
[Bernhard Schommer]
- Issue #24: generate and install .cmti files for easy access to documentation
- Issue #25: false alarm in tests/zq.ml owing to unreliable printing
- Issue #25: false alarm in tests/zq.ml owing to unreliable printing
of FP values
- Request #28: better handling of absolute paths in "configure"
- Request #28: better handling of absolute paths in "configure"

Release 1.7 (2017-10-13):
- Issue#14, pull request#15: ARM assembly code was broken.
Expand Down Expand Up @@ -129,7 +129,7 @@ Release 1.1 (2012-03-24):
- PR#1034: support for static linking of GMP/MPIR
- PR#1046: autodetection of ocamlopt and dynlink
- PR#1048: autodetection of more platforms that we support
- PR#1051: support architectures with strict alignment constraints for
- PR#1051: support architectures with strict alignment constraints for
64-bit integers (e.g. Sparc)
- Fixed 1-bit precision loss when converting doubles to rationals
- Improved support for the forthcoming release 4.00 of OCaml
Expand Down
51 changes: 51 additions & 0 deletions discover.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
let () = Printexc.record_backtrace true

let () =
if Array.length Sys.argv <> 2 then (
print_endline "Usage: ./configure_env.exe %{cc}";
exit 1)

let uname () =
let ic = Unix.open_process_in "uname -s" in
let s = input_line ic in
String.trim s

module Var : sig
val os : string
val is_homebrew_amr64 : bool
end = struct
let is_homebrew_amr64 = Sys.file_exists "/opt/homebrew/bin/brew"

let normalise raw =
match String.lowercase_ascii raw with "darwin" | "osx" -> "macos" | s -> s

let os = normalise (match Sys.os_type with "Unix" -> uname () | s -> s)
end

let cc = Sys.argv.(1)

let ldflags =
match Unix.getenv "LDFLAGS" with exception Not_found -> "" | s -> s

let cflags =
match Unix.getenv "CFLAGS" with exception Not_found -> "" | s -> s

let flags =
match Var.os with
| "openbsd" | "freebsd" ->
Printf.sprintf
"LDFLAGS=\"%s -L/usr/local/lib\" CFLAGS=\"%s -I/usr/local/include\""
ldflags cflags
| "macos" when Var.is_homebrew_amr64 ->
Printf.sprintf
"LDFLAGS=\"%s -L/opt/homebrew/lib\" CFLAGS=\"%s \
-I/opt/homebrew/include\""
ldflags cflags
| "macos" ->
Printf.sprintf
"LDFLAGS=\"%s -L/opt/local/lib -L/usr/local/lib\" CFLAGS=\"%s \
-I/opt/local/include -I/usr/local/include\""
ldflags cflags
| _ -> ""

let () = Printf.printf "CC=\"%s\" %s%!" cc flags
78 changes: 78 additions & 0 deletions dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
(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.sexp)))
(c_library_flags
(:include libs.sexp)))

(executable
(name discover)
(libraries unix)
(modules discover))

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

(rule
(target gmp.env)
(deps
(:exe discover.exe))
(action
(with-stdout-to
%{target}
(run %{exe} "%{cc}"))))

(rule
(target cflags.sexp)
(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.sexp)
(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))
3 changes: 3 additions & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(lang dune 2.0)
(name zarith)
(formatting disabled)
4 changes: 2 additions & 2 deletions project.mak
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# This file is part of the Zarith library
# This file is part of the Zarith library
# http://forge.ocamlcore.org/projects/zarith .
# It is distributed under LGPL 2 licensing, with static linking exception.
# See the LICENSE file included in the distribution.
#
#
# Copyright (c) 2010-2011 Antoine Miné, Abstraction project.
# Abstraction is part of the LIENS (Laboratoire d'Informatique de l'ENS),
# a joint laboratory by:
Expand Down
56 changes: 56 additions & 0 deletions tests/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
(env
(dev
(flags
(:standard -w -27-35))))

(executable
(name zq)
(modes byte exe)
(modules zq)
(libraries zarith))

(rule
(alias runtest)
(action
(progn
(with-stdout-to zq.out (run ./zq.exe))
(diff zq.output%{ocaml-config:word_size} zq.out))))

(rule
(alias runtest)
(action
(progn
(with-stdout-to zq.out.bc (run ./zq.bc))
(diff zq.output%{ocaml-config:word_size} zq.out.bc))))

(executable
(name pi)
(modes exe)
(modules pi)
(libraries zarith))

(rule
(alias runtest)
(action
(progn
(with-stdout-to pi.out (run ./pi.exe 500))
(diff pi.output pi.out))))

(test
(name ofstring)
(modules ofstring)
(modes exe)
(libraries zarith))

(test
(name timings)
(modules timings)
(modes exe)
(libraries zarith))

(test
(name tofloat)
(modules tofloat)
(modes exe)
(foreign_stubs (language c) (names setround))
(libraries zarith))
23 changes: 5 additions & 18 deletions zarith.opam
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
opam-version: "2.0"
name: "zarith"
maintainer: "Xavier Leroy <[email protected]>"
authors: [
"Antoine Miné"
Expand All @@ -11,25 +10,13 @@ bug-reports: "https://github.com/ocaml/Zarith/issues"
dev-repo: "git+https://github.com/ocaml/Zarith.git"
license: "LGPL-2.0-only WITH OCaml-LGPL-linking-exception"
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" "subst" ] {pinned}
[ "dune" "build" "-p" name "-j" jobs ]
[ "dune" "runtest" "-p" name "-j" jobs ]
]
depends: [
"ocaml" {>= "4.04.0"}
"ocamlfind"
"ocaml" {>="4.05.0"}
"dune" {>="2.0"}
"conf-gmp"
]
synopsis:
Expand Down

0 comments on commit d64f883

Please sign in to comment.