Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix variable CC content + add test #3695

Merged
merged 2 commits into from
Aug 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/dune/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,12 @@ open! Stdune
open Import

let default_context_flags (ctx : Context.t) =
(* 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
(* TODO DUNE3 To ensure full backward compatibility, ocaml_cflags are still
present in the :standard set of flags. However these should not as they are
already prepended when calling the compiler, causing flag duplication. *)
let c = Ocaml_config.ocamlc_cflags ctx.ocaml_config in
let cxx =
Ocaml_config.ocamlc_cflags ctx.ocaml_config
|> List.filter ~f:(fun s -> not (String.is_prefix s ~prefix:"-std="))
List.filter c ~f:(fun s -> not (String.is_prefix s ~prefix:"-std="))
in
Foreign.Language.Dict.make ~c ~cxx

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 2.0)
33 changes: 33 additions & 0 deletions test/blackbox-tests/test-cases/variables/var-cc.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
According to the doc: CC is the C compiler command line (list made of the
compiler name followed by its flags) that was used to compile OCaml in the
current build context.

In practice it consists in the concatenation of OCaml's `c_compiler` and flags
The flags are made of the :standard (= ocamlc_cflags) set of ocamlc_flags
merged with (and sometimes replaced by) the flags in the env stanza.

$ O_CC=$(ocamlc -config-var c_compiler)
$ O_CCF=$(ocamlc -config-var ocamlc_cflags)

No env
$ cat > dune <<'EOF'
> (rule
> (alias cc)
> (action (echo %{cc})))

$ dune build @cc | sed "s,${O_CC} ${O_CCF},OK,"
OK

With added env flags
$ cat >> dune <<'EOF'
> (env (_ (c_flags :standard -fPIC)))
> EOF

$ dune build @cc | sed "s,${O_CC} ${O_CCF} -fPIC,OK,"
OK

With redefining env flags
$ sed -i "s/:standard //g" dune

$ dune build @cc | sed "s,${O_CC} -fPIC,OK,"
OK