From c6ca2db1e463063f71e70f58bb5e5c4332f80053 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Mon, 22 Jun 2020 13:23:01 +0200 Subject: [PATCH] No config flags in `:standard`. Always prepend to cc. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ulysse GĂ©rard --- src/dune/foreign_rules.ml | 10 ++++++++-- src/dune/super_context.ml | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/dune/foreign_rules.ml b/src/dune/foreign_rules.ml index 595ef0a9b0e6..c92d739fc1e2 100644 --- a/src/dune/foreign_rules.ml +++ b/src/dune/foreign_rules.ml @@ -78,12 +78,18 @@ let build_c_or_cxx_file ~language ~sctx ~dir ~expander ~include_flags let flags = let ctx_flags = match language with - | Foreign.Language.C -> Fdo.c_flags ctx + | Foreign.Language.C -> + let cfg = ctx.ocaml_config in + List.concat + [ Ocaml_config.ocamlc_cflags cfg + ; Ocaml_config.ocamlc_cppflags cfg + ; Fdo.c_flags ctx + ] | Foreign.Language.Cxx -> Fdo.cxx_flags ctx in let flags = Foreign.Source.flags src in Super_context.foreign_flags sctx ~dir ~expander ~flags ~language - |> Build.map ~f:(List.append ctx_flags) + |> Build.map ~f:List.(rev_append (rev ctx_flags)) in let output_param = match ctx.lib_config.ccomp_type with diff --git a/src/dune/super_context.ml b/src/dune/super_context.ml index 00bac4aaa7fe..b3260499498c 100644 --- a/src/dune/super_context.ml +++ b/src/dune/super_context.ml @@ -2,9 +2,16 @@ open! Stdune open Import let default_context_flags (ctx : Context.t) = - let c = Ocaml_config.ocamlc_cflags ctx.ocaml_config in + (* TODO (v3) Current flag behavior is different when calling the C compiler or + the C++ compiler: 1.[ocamlc_cflags] and [ocamlc_cppflags] are always + prenpended to the C compiler arguments to reproduce [ocamlc]'s behavior, 2. + [ocamlc_cflags] are present in [:standard] and prepended to the C++ + compiler arguments only if the user didn't redefined them (or used + [:standard] to extend them) *) + let c = [] in let cxx = - List.filter c ~f:(fun s -> not (String.is_prefix s ~prefix:"-std=")) + Ocaml_config.ocamlc_cflags ctx.ocaml_config + |> List.filter ~f:(fun s -> not (String.is_prefix s ~prefix:"-std=")) in Foreign.Language.Dict.make ~c ~cxx