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

Support for executable-only projects for dune top/utop #4882

Closed
wants to merge 2 commits into from
Closed
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
46 changes: 46 additions & 0 deletions src/dune_rules/utop.ml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,52 @@ let libs_and_ppx_under_dir sctx ~db ~dir =
, pps )
else
(acc, pps))
| Dune_file.Executables exes -> (
let* libs =
let open Memo.Build.O in
let* compile_info =
let project = Scope.project d.scope in
let dune_version = Dune_project.dune_version project in
let+ pps =
Resolve.Build.read_memo_build
(Preprocess.Per_module.with_instrumentation
exes.buildable.preprocess
~instrumentation_backend:
(Lib.DB.instrumentation_backend (Scope.libs d.scope)))
>>| Preprocess.Per_module.pps
in
Lib.DB.resolve_user_written_deps_for_exes db exes.names
exes.buildable.libraries ~pps ~dune_version
~allow_overlaps:
exes.buildable.allow_overlapping_dependencies
~forbidden_libraries:exes.forbidden_libraries
in
let+ available = Lib.Compile.direct_requires compile_info in
Resolve.peek available
in
match libs with
| Error () -> Memo.Build.return (acc, pps)
| Ok libs ->
Memo.Build.List.fold_left libs ~init:(acc, pps)
~f:(fun (acc, pps) lib ->
let info = Lib.info lib in
match Lib_info.kind info with
| Lib_kind.Ppx_rewriter _
| Ppx_deriver _ ->
Memo.Build.return
( Appendable_list.( @ )
(Appendable_list.singleton lib)
acc
, Appendable_list.( @ )
(Appendable_list.singleton
(Lib_info.loc info, Lib_info.name info))
pps )
| Normal ->
Memo.Build.return
( Appendable_list.( @ )
(Appendable_list.singleton lib)
acc
, pps )))
| _ -> Memo.Build.return (acc, pps)))
>>| fun (libs, pps) ->
(Appendable_list.to_list libs, Appendable_list.to_list pps)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(executable
(name foo)
(libraries bar))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Bar = Bar

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 2.5)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let run () = print_endline "loaded external library successfully"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(library
(name bar))
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let () =
Bar.run ();
exit 0
3 changes: 3 additions & 0 deletions test/blackbox-tests/test-cases/utop/utop-executables.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Running dune utop in a project with only executables loads external libraries
$ dune utop bin -- load_executable_libraries.ml
loaded external library successfully