Skip to content

best-effort multi-platform support for opam lock #6587

Description

@kit-ty-kate

Currently opam lock generates a lock file based on what is actually installed in the current switch of the user.
This works fine if the lock file is only used for that user on that exact machine. However when multiple users and multiple platforms come into play, the system breaks apart because some dependencies might not be available on that platform, or an extra dependency might be needed there)

To remedy this, the goal would be for opam lock to generate a lock file on "best-effort basis", meaning that platform-specific disjunctions and conflicts would be kept as-is in the lock file, until opam lock is re-ran on that platform.

Example of workflow:

  • user 1 on linux: calls opam lock on a project that depend on eio_main. The version currently installed is 1.2 and according to the definition of that package eio_linux and eio_posix are installed. The generated lock file should look like this:
depends: [
  ...
  "eio_main" {= "1.2"}
  ( ("eio_linux" {= "1.2" & os = "linux" & (os-distribution != "centos" | os-version > "7")} &
     "eio_posix" {= "1.2" & os != "win32"}) |
   "eio_windows" {= "1.2" & os = "win32"})
]
  • user 1 pushes that lock file on a public repository
  • user 2 on Windows: starts working on that project, calls opam install --lock . then opam lock. The latter command should merge both what the old lock file and the new state, and in this case end-up with the exact same lock file.

Other examples include lock files where the version number doesn't appear in the opam definition such as:

depends: [
  "pkg1" {arch = "x86_64"}
  "pkg2" {arch = "arm64"}
]

which would, on x86_64 platforms have a lock file like:

depends: [
  "pkg1" {= "1" & arch = "x86_64"}
  "pkg2" {arch = "arm64"}
]

and upon calling opam lock on an arm64 platform would end up with:

depends: [
  "pkg1" {= "1.0.0" & arch = "x86_64"}
  "pkg2" {= "3.2.0" & arch = "arm64"}
]

Prior art: uv (python package manager): https://www.youtube.com/watch?v=gSKTfG1GXYQ

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions