From 39a6c57d171d2906d0f74b266875284932e64b69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Fri, 21 Nov 2025 17:24:27 +0100 Subject: [PATCH 1/9] Stop changing the default OCaml warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- src/dune_lang/pform.ml | 6 +++++- src/dune_lang/pform.mli | 1 + src/dune_rules/expander.ml | 9 +++++++++ src/dune_rules/ocaml_flags.ml | 12 +++++++++--- src/dune_rules/ocaml_flags.mli | 6 ++++++ 5 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/dune_lang/pform.ml b/src/dune_lang/pform.ml index 378d6ebc3ac..d705ff41eb1 100644 --- a/src/dune_lang/pform.ml +++ b/src/dune_lang/pform.ml @@ -137,6 +137,7 @@ module Var = struct | Toolchain | Pkg of Pkg.t | Oxcaml_supported + | Dune_warnings let compare : t -> t -> Ordering.t = Poly.compare @@ -191,7 +192,8 @@ module Var = struct | Toolchain -> variant "Toolchain" [] | Os os -> Os.to_dyn os | Pkg pkg -> Pkg.to_dyn pkg - | Oxcaml_supported -> variant "Oxcaml_supported" []) + | Oxcaml_supported -> variant "Oxcaml_supported" [] + | Dune_warnings -> variant "Dune_warnings" []) ;; let of_opam_global_variable_name name = @@ -538,6 +540,7 @@ let encode_to_latest_dune_lang_version t = | Os os -> Some (Var.Os.to_string os) | Pkg pkg -> Some (Var.Pkg.encode_to_latest_dune_lang_version pkg) | Oxcaml_supported -> Some "oxcaml_supported" + | Dune_warnings -> Some "dune-warnings" with | None -> Pform_was_deleted | Some name -> Success { name; payload = None }) @@ -753,6 +756,7 @@ module Env = struct ; "toolchains", since ~version:(3, 0) Var.Toolchain ; ( "oxcaml_supported" , since ~what:Oxcaml.syntax ~version:(0, 1) Var.Oxcaml_supported ) + ; "dune-warnings", since ~version:(3, 21) Var.Dune_warnings ] in let os = diff --git a/src/dune_lang/pform.mli b/src/dune_lang/pform.mli index c73b8b64921..46830a47f7a 100644 --- a/src/dune_lang/pform.mli +++ b/src/dune_lang/pform.mli @@ -91,6 +91,7 @@ module Var : sig | Toolchain | Pkg of Pkg.t | Oxcaml_supported + | Dune_warnings val compare : t -> t -> Ordering.t val to_dyn : t -> Dyn.t diff --git a/src/dune_rules/expander.ml b/src/dune_rules/expander.ml index b0934633415..a3770fb5e43 100644 --- a/src/dune_rules/expander.ml +++ b/src/dune_rules/expander.ml @@ -572,6 +572,15 @@ let expand_pform_var (context : Context.t) ~dir ~source (var : Pform.Var.t) = let ocaml_version = Ocaml_config.version_string ocaml.ocaml_config in [ Value.of_bool (Ocaml.Version.supports_oxcaml ocaml_version) ]) |> static + | Dune_warnings -> + Need_full_expander + (fun { scope; _ } -> + Deps.Without + (let open Memo.O in + let+ scope = scope in + let dune_version = Dune_project.dune_version (Scope.project scope) in + let profile = Context.profile context in + Value.L.strings (Ocaml_flags.dune_warnings ~dune_version ~profile))) ;; let ocaml_config_macro source macro_invocation context = diff --git a/src/dune_rules/ocaml_flags.ml b/src/dune_rules/ocaml_flags.ml index 4d343741b79..80034224bc0 100644 --- a/src/dune_rules/ocaml_flags.ml +++ b/src/dune_rules/ocaml_flags.ml @@ -51,19 +51,25 @@ let vendored_warnings = [ "-w"; "-a" ] let vendored_alerts = [ "-alert"; "-all" ] let default_warnings = "-40" -let default_flags ~dune_version ~profile = +let dune_warnings ~dune_version ~profile = if Profile.is_dev profile then [ "-w" ; dev_mode_warnings ~dune_version ^ default_warnings ; "-strict-sequence" ; "-strict-formats" - ; "-short-paths" - ; "-keep-locs" ] else [ "-w"; default_warnings ] ;; +let default_flags ~dune_version ~profile = + if dune_version < (3, 21) + then dune_warnings ~dune_version ~profile + else if Profile.is_dev profile + then [ "-short-paths"; "-keep-locs"; "-warn-error"; "+a" ] + else [] +;; + type t = string list Action_builder.t Dune_lang.Ocaml_flags.t let empty = diff --git a/src/dune_rules/ocaml_flags.mli b/src/dune_rules/ocaml_flags.mli index 48e8ad2fd3a..a9f816da9ee 100644 --- a/src/dune_rules/ocaml_flags.mli +++ b/src/dune_rules/ocaml_flags.mli @@ -14,6 +14,12 @@ val make -> t val allow_only_melange : t -> t + +val dune_warnings + : dune_version:Dune_lang.Syntax.Version.t + -> profile:Profile.t + -> string list + val default : dune_version:Dune_lang.Syntax.Version.t -> profile:Profile.t -> t val empty : t val of_list : string list -> t From 7fbe8fb7c910fdcb4b3b79597e686d0a1e127165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Fri, 21 Nov 2025 17:56:55 +0100 Subject: [PATCH 2/9] Add test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- .../blackbox-tests/test-cases/dune-warnings.t | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 test/blackbox-tests/test-cases/dune-warnings.t diff --git a/test/blackbox-tests/test-cases/dune-warnings.t b/test/blackbox-tests/test-cases/dune-warnings.t new file mode 100644 index 00000000000..aada42dce2b --- /dev/null +++ b/test/blackbox-tests/test-cases/dune-warnings.t @@ -0,0 +1,89 @@ +Black-box testing: we check that warning 32 (unused-value-declaration) is +enabled by default in the dev profile in Dune version 3.20 but not in 3.21. + + $ cat >dune-project < (lang dune 3.20) + > EOF + + $ cat >main.ml < let unused = 42 + > EOF + + $ cat >main.mli < EOF + + $ cat >dune < (executable (name main)) + > EOF + + $ dune build + File "main.ml", line 1, characters 4-10: + 1 | let unused = 42 + ^^^^^^ + Error (warning 32 [unused-value-declaration]): unused value unused. + [1] + +Now in 3.21... + + $ cat >dune-project < (lang dune 3.21) + > EOF + + $ dune build + +Version check for %{dune-warnings}. + + $ cat >dune-project < (lang dune 3.20) + > EOF + + $ cat >dune < (executable (name main) (flags :standard %{dune-warnings})) + > EOF + + $ dune build + File "dune", line 1, characters 41-57: + 1 | (executable (name main) (flags :standard %{dune-warnings})) + ^^^^^^^^^^^^^^^^ + Error: %{dune-warnings} is only available since version 3.21 of the dune + language. Please update your dune-project file to have (lang dune 3.21). + [1] + + $ cat >dune-project < (lang dune 3.21) + > EOF + + $ dune build + File "main.ml", line 1, characters 4-10: + 1 | let unused = 42 + ^^^^^^ + Error (warning 32 [unused-value-declaration]): unused value unused. + [1] + +What _is_ %{dune-warnings} ? + + $ cat >dune < (rule (alias show) (action (echo "%{dune-warnings}\n"))) + > EOF + + $ dune build @show + -w @1..3@5..28@31..39@43@46..47@49..57@61..62@67@69-40 -strict-sequence -strict-formats + +Warnings are still fatal in dev mode. + + $ cat >main.ml < let f = function 0 -> 1 + > EOF + + $ cat >dune < (executable (name main)) + > EOF + + $ dune build + File "main.ml", line 1, characters 8-23: + 1 | let f = function 0 -> 1 + ^^^^^^^^^^^^^^^ + Error (warning 8 [partial-match]): this pattern-matching is not exhaustive. + Here is an example of a case that is not matched: + 1 + [1] From 68caf05b004c5f64fe5dd826e5a50943bcb63de7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Fri, 21 Nov 2025 20:29:45 +0100 Subject: [PATCH 3/9] %{dune-warnings} should not depend on the profile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- src/dune_rules/expander.ml | 3 +-- test/blackbox-tests/test-cases/dune-warnings.t | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/dune_rules/expander.ml b/src/dune_rules/expander.ml index a3770fb5e43..ef5041fae6d 100644 --- a/src/dune_rules/expander.ml +++ b/src/dune_rules/expander.ml @@ -579,8 +579,7 @@ let expand_pform_var (context : Context.t) ~dir ~source (var : Pform.Var.t) = (let open Memo.O in let+ scope = scope in let dune_version = Dune_project.dune_version (Scope.project scope) in - let profile = Context.profile context in - Value.L.strings (Ocaml_flags.dune_warnings ~dune_version ~profile))) + Value.L.strings (Ocaml_flags.dune_warnings ~dune_version ~profile:Dev))) ;; let ocaml_config_macro source macro_invocation context = diff --git a/test/blackbox-tests/test-cases/dune-warnings.t b/test/blackbox-tests/test-cases/dune-warnings.t index aada42dce2b..cfa1ef084d9 100644 --- a/test/blackbox-tests/test-cases/dune-warnings.t +++ b/test/blackbox-tests/test-cases/dune-warnings.t @@ -16,7 +16,7 @@ enabled by default in the dev profile in Dune version 3.20 but not in 3.21. > (executable (name main)) > EOF - $ dune build + $ dune build File "main.ml", line 1, characters 4-10: 1 | let unused = 42 ^^^^^^ From 1556ac65748009dbcb9f27a23edb63cee9c72d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Fri, 21 Nov 2025 20:36:28 +0100 Subject: [PATCH 4/9] Changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- doc/changes/changed/12766.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 doc/changes/changed/12766.md diff --git a/doc/changes/changed/12766.md b/doc/changes/changed/12766.md new file mode 100644 index 00000000000..caaa7cd567c --- /dev/null +++ b/doc/changes/changed/12766.md @@ -0,0 +1,5 @@ +- Starting with version 3.21 of the Dune language, Dune no longer changes the + default set of compiler warnings (as it did when building in the `dev` + profile). For users that would like to keep the old behaviour, the special + variable `%{dune-warnings}` can be used in the `(ocaml_flags)` field. + (#12766, @nojb) \ No newline at end of file From f5ea47017e4cdf5698c5380311d5a1c67ea7e54e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Fri, 21 Nov 2025 21:40:33 +0100 Subject: [PATCH 5/9] Doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- doc/changes/changed/12766.md | 2 +- doc/concepts/variables.rst | 9 +++++++++ doc/overview.rst | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/changes/changed/12766.md b/doc/changes/changed/12766.md index caaa7cd567c..b29dda926a7 100644 --- a/doc/changes/changed/12766.md +++ b/doc/changes/changed/12766.md @@ -1,5 +1,5 @@ - Starting with version 3.21 of the Dune language, Dune no longer changes the default set of compiler warnings (as it did when building in the `dev` profile). For users that would like to keep the old behaviour, the special - variable `%{dune-warnings}` can be used in the `(ocaml_flags)` field. + variable `%{dune-warnings}` can be used in the `(flags)` field. (#12766, @nojb) \ No newline at end of file diff --git a/doc/concepts/variables.rst b/doc/concepts/variables.rst index 19f82c88c37..40b92be9ae4 100644 --- a/doc/concepts/variables.rst +++ b/doc/concepts/variables.rst @@ -69,6 +69,15 @@ Dune supports the following variables: - ``ignoring_promoted_rules`` is ``true`` if ``--ignore-promoted-rules`` was passed on the command line and ``false`` otherwise. +- ``dune-warnings`` is the list of OCaml warnings that Dune used by default up + until version 3.20 of the Dune language when building in the ``dev`` profile. + This was a larger set of warnings than the default one used by the OCaml + compiler, and in version 3.21 of the Dune language the set of warnings used by + the ``dev`` profile was reverted to the default one used by the compiler. This + variable is made available for those users who would like to keep using Dune's + stricter warning set. The old behaviour of Dune can be recovered by using the + following stanza in a top-level ``dune`` file: ``(env (dev (flags :standard + %{dune-warnings})))``. - ``:`` where ```` is one of ``cmo``, ``cmi``, ``cma``, ``cmx``, or ``cmxa``. See :ref:`variables-for-artifacts`. - ``env:= Date: Sat, 22 Nov 2025 09:15:13 +0100 Subject: [PATCH 6/9] Fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- src/dune_rules/ocaml_flags.ml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/dune_rules/ocaml_flags.ml b/src/dune_rules/ocaml_flags.ml index 80034224bc0..c65f51b77e8 100644 --- a/src/dune_rules/ocaml_flags.ml +++ b/src/dune_rules/ocaml_flags.ml @@ -63,10 +63,13 @@ let dune_warnings ~dune_version ~profile = ;; let default_flags ~dune_version ~profile = - if dune_version < (3, 21) - then dune_warnings ~dune_version ~profile - else if Profile.is_dev profile - then [ "-short-paths"; "-keep-locs"; "-warn-error"; "+a" ] + (if dune_version < (3, 21) then dune_warnings ~dune_version ~profile else []) + @ + if Profile.is_dev profile + then + "-short-paths" + :: "-keep-locs" + :: (if dune_version >= (3, 21) then [ "-warn-error"; "+a" ] else []) else [] ;; From 746953ea4892712c82b54af35437b7e433d7945e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Sat, 22 Nov 2025 13:26:55 +0100 Subject: [PATCH 7/9] Wording MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- doc/changes/changed/12766.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/doc/changes/changed/12766.md b/doc/changes/changed/12766.md index b29dda926a7..7d22e4cfa5f 100644 --- a/doc/changes/changed/12766.md +++ b/doc/changes/changed/12766.md @@ -1,5 +1,4 @@ - Starting with version 3.21 of the Dune language, Dune no longer changes the - default set of compiler warnings (as it did when building in the `dev` - profile). For users that would like to keep the old behaviour, the special - variable `%{dune-warnings}` can be used in the `(flags)` field. + default set of compiler warnings. For users that would like to keep the old + behaviour, the variable `%{dune-warnings}` can be used in the `(flags)` field. (#12766, @nojb) \ No newline at end of file From 5c4861b044724cc4dfed63850b2371d94690b206 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Sun, 23 Nov 2025 11:51:35 +0100 Subject: [PATCH 8/9] Use %{dune-warnings} in Dune itself MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- dune-file | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dune-file b/dune-file index daa164807d0..06cf0e9bb73 100644 --- a/dune-file +++ b/dune-file @@ -46,7 +46,7 @@ (env (_ - (flags :standard -alert -unstable) + (flags :standard %{dune-warnings} -alert -unstable) (env-vars ; Workaround for #6607 (CLICOLOR_FORCE 0)))) From 051c53f0200fc749ed4c9543d18750304493c3ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ojeda=20B=C3=A4r?= Date: Mon, 24 Nov 2025 11:15:55 +0100 Subject: [PATCH 9/9] Changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ojeda Bär --- doc/changes/changed/12766.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/changes/changed/12766.md b/doc/changes/changed/12766.md index 7d22e4cfa5f..7a9368e9e5e 100644 --- a/doc/changes/changed/12766.md +++ b/doc/changes/changed/12766.md @@ -1,4 +1,5 @@ - Starting with version 3.21 of the Dune language, Dune no longer changes the default set of compiler warnings. For users that would like to keep the old - behaviour, the variable `%{dune-warnings}` can be used in the `(flags)` field. + behaviour, the variable `%{dune-warnings}` can be used in an `(env)` stanza in + a top-level Dune file: `(env (dev (flags :standard %{dune-warnings})))`. (#12766, @nojb) \ No newline at end of file