Skip to content

Commit

Permalink
Do not pass native include dirs when compiling bytecode (#4200)
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
nojb authored and rgrinberg committed Mar 7, 2021
1 parent e3594b4 commit 2698bb4
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Unreleased
easier for `dune top` to locate C stubs associated to concerned libraries.
(#4242, fixes #4231, @nojb)

- Do not pass include directories containing native objects when compiling
bytecode (#4200, @nojb)

2.8.2 (21/01/2021)
------------------

Expand Down
8 changes: 5 additions & 3 deletions src/dune_rules/compilation_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ module Includes = struct
| Error exn ->
Cm_kind.Dict.make_all (Command.Args.Fail { fail = (fun () -> raise exn) })
| Ok libs ->
let iflags = Lib.L.include_flags ~project libs in
let iflags mode = Lib.L.include_flags ~project libs mode in
let cmi_includes =
Command.Args.memo
(Command.Args.S
[ iflags; Hidden_deps (Lib_file_deps.deps libs ~groups:[ Cmi ]) ])
[ iflags Byte
; Hidden_deps (Lib_file_deps.deps libs ~groups:[ Cmi ])
])
in
let cmx_includes =
Command.Args.memo
(Command.Args.S
[ iflags
[ iflags Native
; Hidden_deps
( if opaque then
List.map libs ~f:(fun lib ->
Expand Down
16 changes: 11 additions & 5 deletions src/dune_rules/lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ module L = struct
Command.Args.Path dir :: A "-I" :: acc)
|> List.rev )

let include_paths ?project ts =
let include_paths ?project ts mode =
let visible_cmi =
match project with
| None -> fun _ -> true
Expand All @@ -513,14 +513,18 @@ module L = struct
else
acc
in
let native_dir = Obj_dir.native_dir obj_dir in
Path.Set.add acc native_dir)
match mode with
| Mode.Byte -> acc
| Native ->
let native_dir = Obj_dir.native_dir obj_dir in
Path.Set.add acc native_dir)
in
match ts with
| [] -> dirs
| x :: _ -> Path.Set.remove dirs x.lib_config.stdlib_dir

let include_flags ?project ts = to_iflags (include_paths ?project ts)
let include_flags ?project ts mode =
to_iflags (include_paths ?project ts mode)

let c_include_paths ts =
let dirs =
Expand All @@ -547,7 +551,9 @@ module L = struct
let params = List.map link ~f:(fun t -> Link_params.get t mode) in
let dirs =
let dirs =
Path.Set.union (include_paths compile) (c_include_paths link)
Path.Set.union
(include_paths compile (Link_mode.mode mode))
(c_include_paths link)
in
List.fold_left params ~init:dirs ~f:(fun acc (p : Link_params.t) ->
List.fold_left p.include_dirs ~init:acc ~f:Path.Set.add)
Expand Down
4 changes: 2 additions & 2 deletions src/dune_rules/lib.mli
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ module L : sig

val to_iflags : Path.Set.t -> _ Command.Args.t

val include_paths : ?project:Dune_project.t -> t -> Path.Set.t
val include_paths : ?project:Dune_project.t -> t -> Mode.t -> Path.Set.t

val include_flags : ?project:Dune_project.t -> t -> _ Command.Args.t
val include_flags : ?project:Dune_project.t -> t -> Mode.t -> _ Command.Args.t

val c_include_paths : t -> Path.Set.t

Expand Down
4 changes: 3 additions & 1 deletion src/dune_rules/toplevel.ml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ let setup_module_rules t =
let main_ml =
Build.of_result_map requires_compile ~f:(fun libs ->
Build.return
(let include_dirs = Path.Set.to_list (Lib.L.include_paths libs) in
(let include_dirs =
Path.Set.to_list (Lib.L.include_paths libs Mode.Byte)
in
let pp_ppx = pp_flags t in
let pp_dirs = Source.pp_ml t.source ~include_dirs in
let pp = Pp.seq pp_ppx pp_dirs in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Test toplevel-init-file on a tiny project

$ dune top
#directory "$TESTCASE_ROOT/_build/default/.test.objs/byte";;
#directory "$TESTCASE_ROOT/_build/default/.test.objs/native";;
#load "$TESTCASE_ROOT/_build/default/test.cma";;

$ ocaml -stdin <<EOF
Expand Down

0 comments on commit 2698bb4

Please sign in to comment.