Skip to content

Conversation

@dra27
Copy link
Member

@dra27 dra27 commented Mar 27, 2025

Rendered version. The first proof-of-concept of this work was presented at OCaml Workshop 2022.

The OCaml compiler distribution requires the Standard Library to be stored in a fixed location, specified when the compiler itself was compiled. Executables produced by the bytecode compiler (ocamlc) by default also require the interpreter (ocamlrun) and the Standard Library to be stored in a similarly-fixed location.

A consequence of this is that in order to "move" the compiler to a new location, it is necessary to build a new compiler from scratch, configured with the new location, and then recompile any bytecode executables which were built with the previous compiler.

This can be readily seen in opam today:

# Create an opam local switch
dra@Tau:~/work$ opam switch create . ocaml.5.3.0
...

# Report the Standard Library location from both builds of ocamlc
dra@Tau:~/work$ opam exec -- ocamlc.byte -where
/home/dra/work/_opam/lib/ocaml
dra@Tau:~/work$ opam exec -- ocamlc.opt -where
/home/dra/work/_opam/lib/ocaml

# Rename the directory
dra@Tau:~/work$ cd ..
dra@Tau:~$ mv work new-work
dra@Tau:~$ cd new-work

# Repeat the previous test
dra@Tau:~/new-work$ opam exec -- ocamlc.byte -where
Fatal error: exception /usr/local/bin/opam: "execvpe" failed on /home/dra/new-work/_opam/bin/ocamlc.byte: No such file or directory
dra@Tau:~/new-work$ opam exec -- ocamlc.opt -where
/home/dra/work/_opam/lib/ocaml

ocamlc.byte cannot be run, because the interpreter specified in its "shebang" line (#!/home/dra/work/_opam/bin/ocamlrun) no longer exists. ocamlc.opt can be run, but returns the original location of the Standard Library, which no longer exists, rather than the new location of the files in /home/dra/new-work/_opam/lib/ocaml.

Relocatable OCaml proposes to fix this. An intended consequence of the proposal here is that not only can the directory containing a compiler installation be moved, but it may also be copied, specifically:

# Create an opam local switch using Relocatable OCaml
dra@Tau:~/compiler1$ opam switch create . --repos=relocatable,default ocaml.5.3.0
...

# Clone it
dra@Tau:~/compiler1$ cd ..
dra@Tau:~$ cp -a compiler1 compiler2

# Report the Standard Library location from each directory, without using opam
dra@Tau:~$ compiler1/_opam/bin/ocamlc -where
/home/dra/compiler1/_opam/lib/ocaml
dra~Tau:~$ compiler2/_opam/bin/ocamlc -where
/home/dra/compiler2/_opam/lib/ocaml

@shindere
Copy link

shindere commented Mar 27, 2025 via email

Copy link

@nojb nojb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This RFC was discussed in yesterday's dev meeting and there was consensus to move to the review stage of this work. Thus, I think the RFC can be considered approved. Thanks @dra27!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants