Skip to content

Commit

Permalink
feat: use pkg-install to build the deps
Browse files Browse the repository at this point in the history
Attached it to the workspace.

Signed-off-by: Etienne Marais <[email protected]>
  • Loading branch information
maiste committed Nov 12, 2024
1 parent 975741e commit 877dbbe
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/dune_rules/alias0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ let check = standard "check"
let install = standard "install"
let ocaml_index = standard "ocaml-index"
let runtest = standard "runtest"
let pkg_deps = standard "pkg-deps"
let pkg_install = standard "pkg-install"
let all = standard "all"
2 changes: 1 addition & 1 deletion src/dune_rules/alias0.mli
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ val check : Name.t
val ocaml_index : Name.t
val install : Name.t
val runtest : Name.t
val pkg_deps : Name.t
val pkg_install : Name.t
val all : Name.t
val is_standard : Name.t -> bool
val register_as_standard : Name.t -> unit
11 changes: 11 additions & 0 deletions src/dune_rules/gen_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,17 @@ let gen_project_rules =
and+ () = Odoc.gen_project_rules sctx project
and+ () = Odoc_new.gen_project_rules sctx project
and+ () = Ocaml_index.project_rule sctx project
and+ () =
let ctx = Super_context.context sctx in
let ctx_name = Context.name ctx in
let* is_lock_dir_active = Lock_dir.lock_dir_active ctx_name in
if is_lock_dir_active
then (
let dir =
Path.Build.append_source (Context.build_dir ctx) @@ Dune_project.root project
in
Pkg_rules.gen_rule_from_universe ~dir ctx_name)
else Memo.return ()
and+ () =
let version = 2, 8 in
match Dune_project.allow_approximate_merlin project with
Expand Down
27 changes: 21 additions & 6 deletions src/dune_rules/pkg_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1937,14 +1937,29 @@ let build_rule context_name ~source_deps (pkg : Pkg.t) =
~directory_targets:[ pkg.write_paths.target_dir ]
;;

let gen_package_alias_rules ~dir source_deps =
let alias = Alias.make Alias0.pkg_deps ~dir in
Action_builder.deps source_deps |> Rules.Produce.Alias.add_deps alias
let gen_rule_from_universe ~dir ctx_name =
let to_target_path pkg =
let pkg_name = Dune_lang.Package_name.to_string pkg in
let path =
Path.Build.L.relative
Private_context.t.build_dir
[ Context_name.to_string ctx_name; ".pkg"; pkg_name; "target" ]
|> Path.build
in
path
in
let* packages =
Package_universe.lock_dir (Project_dependencies ctx_name)
>>| (fun lock_dir -> lock_dir.packages)
>>| Dune_lang.Package_name.Map.keys
in
let alias = Alias.make Alias0.pkg_install ~dir in
let package_targets = List.map ~f:to_target_path packages in
Action_builder.paths package_targets |> Rules.Produce.Alias.add_deps alias
;;

let gen_rules ~dir context_name (pkg : Pkg.t) =
let gen_rules context_name (pkg : Pkg.t) =
let* source_deps, copy_rules = source_rules pkg in
let* () = gen_package_alias_rules ~dir source_deps in
let* () = copy_rules
and* build_rule = build_rule context_name pkg ~source_deps in
rule ~loc:Loc.none (* TODO *) build_rule
Expand Down Expand Up @@ -1986,7 +2001,7 @@ let setup_package_rules ~package_universe ~dir ~pkg_name : Gen_rules.result Memo
Gen_rules.Build_only_sub_dirs.singleton ~dir Subdir_set.empty
in
let context_name = Package_universe.context_name package_universe in
let rules = Rules.collect_unit (fun () -> gen_rules ~dir context_name pkg) in
let rules = Rules.collect_unit (fun () -> gen_rules context_name pkg) in
Gen_rules.make ~directory_targets ~build_dir_only_sub_dirs rules
;;

Expand Down
3 changes: 3 additions & 0 deletions src/dune_rules/pkg_rules.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ val which : Context_name.t -> (Filename.t -> Path.t option Memo.t) Staged.t
val exported_env : Context_name.t -> Env.t Memo.t
val ocamlpath : Context_name.t -> Path.t list Memo.t
val find_package : Context_name.t -> Package.Name.t -> unit Action_builder.t option Memo.t

(** TODO: Give me a better description. *)
val gen_rule_from_universe : dir:Path.Build.t -> Context_name.t -> unit Memo.t

0 comments on commit 877dbbe

Please sign in to comment.