Skip to content

Commit

Permalink
Rename option to 'use_standard_c_and_cxx_flags'
Browse files Browse the repository at this point in the history
Signed-off-by: Ulysse Gérard <[email protected]>
  • Loading branch information
voodoos committed Nov 19, 2020
1 parent 88f3e83 commit ddd2435
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Unreleased
- `dune describe` now also includes information about executables in addition to
that of libraries. (#3892, #3895, @nojb)

- Add the option `future_c_and_cxx_flags_handling` to `dune-project` that
- Add the option `use_standard_c_and_cxx_flags` to `dune-project` that
disables the unconditional use of the `ocamlc_cflags` and `ocamlc_cppflags`
from `ocamlc -config` in C compiler calls. These flags are present in the
`:standard` set instead. (#3875, fix #3718, @voodoos)
Expand Down
6 changes: 3 additions & 3 deletions doc/dune-files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -287,16 +287,16 @@ language: The syntax is as a list of the following elements:
.. _always-add-cflags:

future_c_and_cxx_flags_handling
-----------------
use_standard_c_and_cxx_flags
----------------------------

Since Dune 2.8, it is possible to deactivate the systematic prepending of flags
coming from ``ocamlc -config`` to the C compiler command line. This is done
adding the following field to the ``dune-project`` file:

.. code:: scheme
(future_c_and_cxx_flags_handling true)
(use_standard_c_and_cxx_flags true)
In this mode, dune will populate the ``:standard`` set of C flags with the
content of ``ocamlc_cflags`` and ``ocamlc_cppflags``. These flags can be
Expand Down
22 changes: 11 additions & 11 deletions src/dune_engine/dune_project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ type t =
; dune_version : Dune_lang.Syntax.Version.t
; allow_approx_merlin : bool
; generate_opam_files : bool
; future_c_and_cxx_flags_handling : bool option
; use_standard_c_and_cxx_flags : bool option
; file_key : File_key.t
; dialects : Dialect.DB.t
; explicit_js_mode : bool
Expand Down Expand Up @@ -195,7 +195,7 @@ let allow_approx_merlin t = t.allow_approx_merlin

let generate_opam_files t = t.generate_opam_files

let future_c_and_cxx_flags_handling t = t.future_c_and_cxx_flags_handling
let use_standard_c_and_cxx_flags t = t.use_standard_c_and_cxx_flags

let dialects t = t.dialects

Expand All @@ -216,7 +216,7 @@ let to_dyn
; dune_version
; allow_approx_merlin
; generate_opam_files
; future_c_and_cxx_flags_handling
; use_standard_c_and_cxx_flags
; file_key
; dialects
; explicit_js_mode
Expand All @@ -239,8 +239,8 @@ let to_dyn
; ("dune_version", Dune_lang.Syntax.Version.to_dyn dune_version)
; ("allow_approx_merlin", bool allow_approx_merlin)
; ("generate_opam_files", bool generate_opam_files)
; ( "future_c_and_cxx_flags_handling"
, option bool future_c_and_cxx_flags_handling )
; ( "use_standard_c_and_cxx_flags"
, option bool use_standard_c_and_cxx_flags )
; ("file_key", string file_key)
; ("dialects", Dialect.DB.to_dyn dialects)
; ("explicit_js_mode", bool explicit_js_mode)
Expand Down Expand Up @@ -616,7 +616,7 @@ let infer ~dir packages =
; dune_version = lang.version
; allow_approx_merlin = true
; generate_opam_files = false
; future_c_and_cxx_flags_handling =
; use_standard_c_and_cxx_flags =
( if lang.version < (3, 0) then
None
else
Expand Down Expand Up @@ -686,8 +686,8 @@ let parse ~dir ~lang ~opam_packages ~file =
and+ generate_opam_files =
field_o_b "generate_opam_files"
~check:(Dune_lang.Syntax.since Stanza.syntax (1, 10))
and+ future_c_and_cxx_flags_handling =
field_o_b "future_c_and_cxx_flags_handling"
and+ use_standard_c_and_cxx_flags =
field_o_b "use_standard_c_and_cxx_flags"
~check:(Dune_lang.Syntax.since Stanza.syntax (2, 8))
and+ dialects =
multi_field "dialect"
Expand Down Expand Up @@ -806,8 +806,8 @@ let parse ~dir ~lang ~opam_packages ~file =
let generate_opam_files =
Option.value ~default:false generate_opam_files
in
let future_c_and_cxx_flags_handling =
match future_c_and_cxx_flags_handling with
let use_standard_c_and_cxx_flags =
match use_standard_c_and_cxx_flags with
| None when dune_version >= (3, 0) -> Some false
| None -> None
| some -> some
Expand Down Expand Up @@ -840,7 +840,7 @@ let parse ~dir ~lang ~opam_packages ~file =
; dune_version
; allow_approx_merlin
; generate_opam_files
; future_c_and_cxx_flags_handling
; use_standard_c_and_cxx_flags
; dialects
; explicit_js_mode
; format_config
Expand Down
2 changes: 1 addition & 1 deletion src/dune_engine/dune_project.mli
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ val allow_approx_merlin : t -> bool

val generate_opam_files : t -> bool

val future_c_and_cxx_flags_handling : t -> bool option
val use_standard_c_and_cxx_flags : t -> bool option

val dialects : t -> Dialect.DB.t

Expand Down
10 changes: 5 additions & 5 deletions src/dune_rules/foreign_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ let build_c ~kind ~sctx ~dir ~expander ~include_flags (loc, src, dst) =
match kind with
| Foreign_language.C -> (
let cfg = ctx.ocaml_config in
match Dune_project.future_c_and_cxx_flags_handling project with
match Dune_project.use_standard_c_and_cxx_flags project with
| None
| Some false ->
(* In dune < 2.8 flags from ocamlc_config are always added *)
Expand All @@ -94,9 +94,9 @@ let build_c ~kind ~sctx ~dir ~expander ~include_flags (loc, src, dst) =
| Foreign_language.Cxx -> Fdo.cxx_flags ctx
in
let flags = Foreign.Source.flags src in
(* DUNE3 will have [future_c_and_cxx_flags_handling] disabled by default. To
(* DUNE3 will have [use_standard_c_and_cxx_flags] disabled by default. To
guide users toward this change we emit a warning when dune_lang is >=
1.8, [future_c_and_cxx_flags_handling] is not specified in the
1.8, [use_standard_c_and_cxx_flags] is not specified in the
[dune-project] file (thus defaulting to [true]) and the [:standard] set
of flags has been overriden *)
let has_standard = Ordered_set_lang.Unexpanded.has_standard flags in
Expand All @@ -107,7 +107,7 @@ let build_c ~kind ~sctx ~dir ~expander ~include_flags (loc, src, dst) =
in
if
Dune_project.dune_version project >= (2, 8)
&& Option.is_none (Dune_project.future_c_and_cxx_flags_handling project)
&& Option.is_none (Dune_project.use_standard_c_and_cxx_flags project)
&& (not is_vendored) && not has_standard
then
User_warning.emit ~loc
Expand All @@ -116,7 +116,7 @@ let build_c ~kind ~sctx ~dir ~expander ~include_flags (loc, src, dst) =
set of flags. However the flags in this standard set are still \
added to the compiler arguments by Dune. This might cause \
unexpected issues. You can disable this warning by defining the \
option `(future_c_and_cxx_flags_handling <bool>)` in your \
option `(use_standard_c_and_cxx_flags <bool>)` in your \
`dune-project` file. Setting this option to `true` will \
effectively prevent Dune from silently adding c-flags to the \
compiler arguments which is the new recommended behaviour."
Expand Down
2 changes: 1 addition & 1 deletion src/dune_rules/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let default_context_flags (ctx : Context.t) ~project =
List.filter cflags ~f:(fun s -> not (String.is_prefix s ~prefix:"-std="))
in
let c =
match Dune_project.future_c_and_cxx_flags_handling project with
match Dune_project.use_standard_c_and_cxx_flags project with
| None
| Some false ->
cflags
Expand Down
24 changes: 12 additions & 12 deletions test/blackbox-tests/test-cases/c-flags.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bar.c is built with an "empty" set of flags.
$ O_CCPPF=${O_CCPPF%% }


future_c_and_cxx_flags_handling = default (false)
use_standard_c_and_cxx_flags = default (false)
==================================

$ cat >dune-project <<EOF
Expand All @@ -25,7 +25,7 @@ future_c_and_cxx_flags_handling = default (false)
Warning: The flag set for these foreign sources overrides the `:standard` set
of flags. However the flags in this standard set are still added to the
compiler arguments by Dune. This might cause unexpected issues. You can
disable this warning by defining the option `(future_c_and_cxx_flags_handling
disable this warning by defining the option `(use_standard_c_and_cxx_flags
<bool>)` in your `dune-project` file. Setting this option to `true` will
effectively prevent Dune from silently adding c-flags to the compiler
arguments which is the new recommended behaviour.
Expand All @@ -37,7 +37,7 @@ future_c_and_cxx_flags_handling = default (false)
Warning: The flag set for these foreign sources overrides the `:standard` set
of flags. However the flags in this standard set are still added to the
compiler arguments by Dune. This might cause unexpected issues. You can
disable this warning by defining the option `(future_c_and_cxx_flags_handling
disable this warning by defining the option `(use_standard_c_and_cxx_flags
<bool>)` in your `dune-project` file. Setting this option to `true` will
effectively prevent Dune from silently adding c-flags to the compiler
arguments which is the new recommended behaviour.
Expand All @@ -59,12 +59,12 @@ ocamlc_cpp flags appear in the compiler command line:
$ cat out_bar | grep -ce "${O_CCF} ${O_CCPPF}"
1

future_c_and_cxx_flags_handling = true
use_standard_c_and_cxx_flags = true
=================================

$ cat >dune-project <<EOF
> (lang dune 2.8)
> (future_c_and_cxx_flags_handling true)
> (use_standard_c_and_cxx_flags true)

$ dune rules -m foo.o | tr -s '\t\n\\' ' ' > out_foo
$ dune rules -m bar.o | tr -s '\t\n\\' ' ' > out_bar
Expand All @@ -88,19 +88,19 @@ ocamlc_cpp are effectively removed from the compiler command line
0
[1]

future_c_and_cxx_flags_handling = true but dune < 2.8
use_standard_c_and_cxx_flags = true but dune < 2.8
================================================

$ cat >dune-project <<EOF
> (lang dune 2.7)
> (future_c_and_cxx_flags_handling true)
> (use_standard_c_and_cxx_flags true)

$ dune rules
File "dune-project", line 2, characters 0-38:
2 | (future_c_and_cxx_flags_handling true)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: 'future_c_and_cxx_flags_handling' is only available since version 2.8
of the dune language. Please update your dune-project file to have (lang dune
File "dune-project", line 2, characters 0-35:
2 | (use_standard_c_and_cxx_flags true)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: 'use_standard_c_and_cxx_flags' is only available since version 2.8 of
the dune language. Please update your dune-project file to have (lang dune
2.8).
[1]

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(lang dune 2.8)
(future_c_and_cxx_flags_handling true)
(use_standard_c_and_cxx_flags true)
2 changes: 1 addition & 1 deletion test/blackbox-tests/test-cases/variables/var-cc.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ With redefining env flags
$ dune build @cc | sed "s,${O_CC} -fPIC,OK,"
OK
Since dune 2.8, when using the future_c_and_cxx_flags_handling option the :standard
Since dune 2.8, when using the use_standard_c_and_cxx_flags option the :standard
set of flag and thus the %{cc} variable contain both the cflags and cppflags
from ocaml config. These flags are not added systematically anymore to the
compiler command line.
Expand Down

0 comments on commit ddd2435

Please sign in to comment.