Skip to content

Commit

Permalink
Build with -warn-error +A only in the dev profile
Browse files Browse the repository at this point in the history
Use Dune's env stanza to apply -warn-error +A only in the (default) dev
profile.

The Makefile now recognises an equivalent PROFILE variable which should
be either be auto, dev, or release. If the build tree includes a .git
directory then the dev profile is assumed.

CI explicitly specifies PROFILE=dev and the opam installation explicitly
specifies PROFILE=release.
  • Loading branch information
dra27 committed Nov 9, 2023
1 parent 4d1fc81 commit 2bcc488
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- run: opam pin add num . --no-action

# Check building with make
- run: opam exec -- make
- run: opam exec -- make PROFILE=dev
- run: opam exec -- make test
- run: opam exec -- make clean

Expand Down
26 changes: 26 additions & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,29 @@ else
NATIVE_COMPILER = true
endif
endif

# PROFILE=dev or PROFILE=release
PROFILE ?= auto

# Assume we're in release mode if there's no .git directory (means that an old
# school installation from a tarball assumes release mode, but a Git clone
# assumes development mode)
ifeq "$(PROFILE)" "auto"
# This file is included from a sub-directory, hence the ../
ifeq "$(wildcard ../.git)" ""
PROFILE = release
else
PROFILE = dev
endif
endif

ifneq "$(filter-out release dev, $(PROFILE))$(word 2, $(PROFILE))" ""
$(error The PROFILE variable must be one of auto, dev, or release)
endif

# Only use -warn-error in dev mode
ifeq "$(PROFILE)" "dev"
WARN_ERROR = -warn-error +A
else
WARN_ERROR =
endif
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ More documentation on the functions provided in this library can be found in _Th

Prerequisites: OCaml version 4.04 or newer.
```
make all
make all PROFILE=release
make test
make install
make clean
Expand Down
16 changes: 16 additions & 0 deletions dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(rule (with-stdout-to warnings.sexp (echo
; Add any warnings to this string (-warn-error +A is appended for the dev
; profile)
"(-w +a-4-9-41-42-44-45-48)"
)))

(rule (with-stdout-to flags.sexp (echo
; Add any compilation flags to this string
"(-safe-string -strict-sequence -strict-formats)"
)))

(env
(dev
(flags (:include warnings.sexp) -warn-error +A (:include flags.sexp)))
(release
(flags (:include warnings.sexp) (:include flags.sexp))))
3 changes: 2 additions & 1 deletion num.opam
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ homepage: "https://github.com/ocaml/num/"
bug-reports: "https://github.com/ocaml/num/issues"
dev-repo: "git+https://github.com/ocaml/num.git"
build: [
[make "opam-legacy" {!ocaml:preinstalled & ocaml:version < "5.0.0~~"}
[make "PROFILE=release"
"opam-legacy" {!ocaml:preinstalled & ocaml:version < "5.0.0~~"}
"opam-modern" {ocaml:preinstalled | ocaml:version >= "5.0.0~~"}]
[make "test"] {with-test}
]
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ else
BNG_ARCH=$(ARCH)
endif

CAMLCFLAGS=-w +a-4-9-41-42-44-45-48 -warn-error +A -bin-annot -g \
CAMLCFLAGS=-w +a-4-9-41-42-44-45-48 $(WARN_ERROR) -bin-annot -g \
-safe-string -strict-sequence -strict-formats -I +compiler-libs
CAMLOPTFLAGS=$(CAMLCFLAGS)
ifeq "$(FLAMBDA)" "true"
Expand Down
3 changes: 1 addition & 2 deletions src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
(language c)
(names nat_stubs bng)
(extra_deps (glob_files *.c))
(flags "-DBNG_ARCH_%{architecture}"))
(flags -w +a-4-9-41-42-44-45-48 -warn-error +A -g -safe-string -strict-sequence -strict-formats))
(flags "-DBNG_ARCH_%{architecture}")))
3 changes: 2 additions & 1 deletion test/dune
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
(library
(name test_lib)
(modules test test_nats test_big_ints test_ratios test_nums test_io end_test)
(libraries num))
(libraries num)
(flags ))

(executable
(name driver)
Expand Down
3 changes: 1 addition & 2 deletions toplevel/dune
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
(public_name num.top)
(libraries num compiler-libs)
(wrapped false)
(modes byte)
(flags -w +a-4-9-41-42-44-45-48 -warn-error +A -safe-string -strict-sequence -strict-formats))
(modes byte))

(rule
(with-stdout-to META.shim
Expand Down

0 comments on commit 2bcc488

Please sign in to comment.