Skip to content

Commit

Permalink
fix: allow ocaml.5.3.0 to be built with package management
Browse files Browse the repository at this point in the history
Signed-off-by: Etienne Marais <dev@maiste.fr>
  • Loading branch information
maiste committed Jan 16, 2025
1 parent c72c8c0 commit 4676a05
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
21 changes: 15 additions & 6 deletions src/dune_rules/pkg_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1931,14 +1931,23 @@ let ocaml_toolchain context =
| `System_provided -> None
| `Inside_lock_dir pkg ->
let toolchain =
let cookie = (Pkg_installed.of_paths pkg.paths).cookie in
let open Action_builder.O in
let* cookie = cookie in
(* TODO we should use the closure of [pkg] *)
let binaries =
Section.Map.find cookie.files Bin |> Option.value ~default:[] |> Path.Set.of_list
let transitive_deps = pkg :: Pkg.deps_closure pkg in
let* env, binaries =
Action_builder.List.fold_left
~init:(Global.env (), Path.Set.empty)
~f:(fun (env, binaries) pkg ->
let env = Env.extend_env env (Pkg.exported_env pkg) in
let+ cookie = (Pkg_installed.of_paths pkg.paths).cookie in
let binaries =
Section.Map.find cookie.files Bin
|> Option.value ~default:[]
|> Path.Set.of_list
|> Path.Set.union binaries
in
env, binaries)
transitive_deps
in
let env = Env.extend_env (Global.env ()) (Pkg.exported_env pkg) in
let path = Env_path.path (Global.env ()) in
Action_builder.of_memo @@ Ocaml_toolchain.of_binaries ~path context env binaries
in
Expand Down
31 changes: 16 additions & 15 deletions src/dune_rules/pkg_toolchain.ml
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,14 @@ let is_compiler_and_toolchains_enabled name =
(* TODO don't hardcode these names here *)
[ Package_name.of_string "ocaml-base-compiler"
; Package_name.of_string "ocaml-variants"
; Package_name.of_string
"ocaml-compiler" (* HACK: This is required for ocaml.5.3.0 *)
]
in
List.mem compiler_package_names name ~equal:Package_name.equal
| `Disabled -> false
;;

let ocaml context env ~bin_dir =
let which prog =
let path = Path.Outside_build_dir.relative bin_dir prog in
let+ exists = Fs_memo.file_exists path in
if exists then Some (Path.outside_build_dir path) else None
in
let get_ocaml_tool ~dir:_ prog = which prog in
Ocaml_toolchain.make context ~which ~env ~get_ocaml_tool
;;

(* Returns the path to the directory containing the artifacts within the
temporary install directory. When installing with the DESTDIR variable, the
absolute path to the final installation directory is concatenated to the
Expand Down Expand Up @@ -174,11 +166,20 @@ let modify_install_action ~prefix ~suffix action =
(* Create an empty config.cache file so other packages see that the
compiler package is installed. *)
let touch_config_cache =
Dune_lang.Action.Run
[ Slang.text "touch"
; Slang.concat
[ Slang.pform (Pform.Var (Pform.Var.Pkg Pform.Var.Pkg.Build))
; Slang.text "/config.cache"
Dune_lang.Action.Progn
[ Dune_lang.Action.Run
[ Slang.text "touch"
; Slang.concat
[ Slang.pform (Pform.Var (Pform.Var.Pkg Pform.Var.Pkg.Build))
; Slang.text "/config.cache"
]
]
; Dune_lang.Action.Run
[ Slang.text "touch"
; Slang.concat
[ Slang.pform (Pform.Var (Pform.Var.Pkg Pform.Var.Pkg.Build))
; Slang.text "/config.status"
]
]
]
;;
Expand Down
6 changes: 0 additions & 6 deletions src/dune_rules/pkg_toolchain.mli
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ val pkg_dir : Dune_pkg.Lock_dir.Pkg.t -> Path.Outside_build_dir.t
script. *)
val installation_prefix : pkg_dir:Path.Outside_build_dir.t -> Path.Outside_build_dir.t

val ocaml
: Context_name.t
-> Env.t
-> bin_dir:Path.Outside_build_dir.t
-> Ocaml_toolchain.t Memo.t

(** Rewrite the OCaml compiler install action so that it installs the compiler
package to the users toolchain directory. If the compiler is found to be
already installed in the users toolchain directory, the action is instead
Expand Down

0 comments on commit 4676a05

Please sign in to comment.