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

Do not pass native include dirs when compiling bytecode #4200

Merged
merged 3 commits into from
Feb 4, 2021
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Unreleased
- Add `ocaml` command subgroup for OCaml related commands such as `utop`, `top`,
and `merlin` (#3936, @rgrinberg).

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

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

Expand Down
4 changes: 3 additions & 1 deletion bin/top.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ let term =
let requires =
Dune_rules.Lib.closure ~linking:true libs |> Result.ok_exn
in
let include_paths = Dune_rules.Lib.L.include_paths requires in
let include_paths =
Dune_rules.Lib.L.include_paths requires Dune_rules.Mode.Byte
in
let files = link_deps requires in
let* () =
Memo.Build.run (do_build (List.map files ~f:(fun f -> Target.File f)))
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 @@ -538,7 +542,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_flags : t -> _ Command.Args.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 =
Action_builder.of_result_map requires_compile ~f:(fun libs ->
Action_builder.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 ocaml 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