Skip to content

Dev tools and special compiler branches #12868

@Sudha247

Description

@Sudha247

There are certain dev tools like ocamllsp that require to have a matching compiler version as the project. The check currently assumes the compiler package is ocaml and installs the dev tool with the same ocaml package.

dune/bin/lock_dev_tool.ml

Lines 98 to 152 in da89573

let compiler_package_name = Package_name.of_string "ocaml"
(* Some dev tools must be built with the same version of the ocaml
compiler as the project. This function returns the version of the
"ocaml" package used to compile the project in the default build
context.
TODO: This only makes sure that the version of compiler used to
build the dev tool matches the version of the compiler used to
build this project. This will fail if the project is built with a
custom compiler (e.g. ocaml-variants) since the version of the
compiler will be the same between the project and dev tool while
they still use different compilers. A more robust solution would be
to ensure that the exact compiler package used to build the dev
tool matches the package used to build the compiler. *)
let locked_ocaml_compiler_version () =
let open Memo.O in
let context =
(* Dev tools are only ever built with the default context. *)
Context_name.default
in
let* result = Dune_rules.Lock_dir.get context
and* platform =
Pkg.Pkg_common.poll_solver_env_from_current_system () |> Memo.of_reproducible_fiber
in
match result with
| Error _ ->
User_error.raise
[ Pp.text "Unable to load the lockdir for the default build context." ]
~hints:
[ Pp.concat
~sep:Pp.space
[ Pp.text "Try running"; User_message.command "dune pkg lock" ]
]
| Ok { packages; _ } ->
let packages = Lock_dir.Packages.pkgs_on_platform_by_name packages ~platform in
(match Package_name.Map.find packages compiler_package_name with
| None ->
User_error.raise
[ Pp.textf
"The lockdir doesn't contain a lockfile for the package %S."
(Package_name.to_string compiler_package_name)
]
~hints:
[ Pp.concat
~sep:Pp.space
[ Pp.textf
"Add a dependency on %S to one of the packages in dune-project and \
then run"
(Package_name.to_string compiler_package_name)
; User_message.command "dune pkg lock"
]
]
| Some pkg -> Memo.return pkg.info.version)
;;

However, this does not capture other possible compilers. #12834 proposes to improve this by taking into account more possible compiler packages, such as ocaml-variants, ocaml-base-compiler. However, it doesn't cover the cases where the user has special compiler branches pinned, as @rgrinberg explained here: #12834 (comment). In this case it should ideally go through compiler pins and add it as a pin to the dev tool.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions