Skip to content

feat(pkg): relocatable compiler support#13321

Merged
Alizter merged 1 commit intoocaml:mainfrom
Alizter:push-ssmqlovpkqol
Apr 2, 2026
Merged

feat(pkg): relocatable compiler support#13321
Alizter merged 1 commit intoocaml:mainfrom
Alizter:push-ssmqlovpkqol

Conversation

@Alizter
Copy link
Copy Markdown
Collaborator

@Alizter Alizter commented Jan 15, 2026

This PR adds a way for us to detect if a compiler in our "package universe" is relocatable. Knowing this means we can avoid the use of our toolchains functionality and instead build the compiler like a regular package.

The current chosen heuristic for knowing so is by inspecting if we have the reloctable-compiler meta-package available (for interoperability with David's relocatable opam repository) or by checking for the relocatable meta-package in opam-repository.

We add a test checking the checking behaviour and making sure that compiler-like packages are able to be cached in these cases.

To try it out for yourself, put the following in dune-workspace:

(repository
 (name dra27-relocatable)
 (url "git+https://github.com/dra27/opam-repository.git#relocatable"))

(lock_dir
 (repositories dra27-relocatable :standard))

Or use (ocaml (= 5.5.0)) relocatable in your package (depends).

Part of the work on:

@Alizter Alizter mentioned this pull request Jan 15, 2026
13 tasks
Alizter referenced this pull request Jan 15, 2026
According to [1] and [2], `build-id` is a SHA256 hash identifying the
precise package version with all its dependencies.

Consumers of this variable, such as the process.sh script in [3], use
this to identify specific packages in existing opam switches. In [3]
this is used to find an already-built relocatable OCaml compiler.

In dune we wish to re-use [3] for choosing the relocatable compiler,
therefore we need to substitute the value with something that will not
be picked up as a hash from an existing opam valuation of build-id.

For now we choose a magic number that is easily recognizable in case
anything needs to be debugged.

[1]
https://github.com/ocaml/opam/blob/master/src/state/opamPackageVar.ml
[2]
https://github.com/ocaml/opam/wiki/Spec-for-Extended-package-specific-variables
[3] https://github.com/dra27/opam-repository/tree/relocatable

Addressing relevant concern in:
- #13229
@Alizter Alizter force-pushed the push-ssmqlovpkqol branch 5 times, most recently from 96d4bac to eaaebab Compare January 26, 2026 10:22
@Alizter Alizter force-pushed the push-ssmqlovpkqol branch 3 times, most recently from b604e28 to 4fcca47 Compare February 3, 2026 00:34
@Alizter Alizter force-pushed the push-ssmqlovpkqol branch 2 times, most recently from ead22d4 to e389f75 Compare February 23, 2026 15:53
@Alizter Alizter force-pushed the push-ssmqlovpkqol branch 2 times, most recently from 1f6b442 to a0d27ac Compare March 12, 2026 17:37
@Alizter Alizter force-pushed the push-ssmqlovpkqol branch from a0d27ac to 0468eb4 Compare March 20, 2026 07:52
@Alizter Alizter marked this pull request as ready for review March 20, 2026 15:42
@Alizter Alizter requested review from ElectreAAS and rgrinberg March 20, 2026 15:42
@Alizter Alizter force-pushed the push-ssmqlovpkqol branch from 0468eb4 to fba12b9 Compare March 23, 2026 08:52
@avsm
Copy link
Copy Markdown
Member

avsm commented Mar 23, 2026

@dra27 did this which is merged now (a relocatable package in opam itself). ocaml/opam-repository#29451

Does its existence let the heuristics here be replaced with a conflict check for that package instead?

@Alizter Alizter marked this pull request as draft March 23, 2026 09:18
@Alizter
Copy link
Copy Markdown
Collaborator Author

Alizter commented Mar 23, 2026

@avsm I've deleted my earlier rushed meesage.

The heuristic here is to detect the relocatable compiler during build time. That way we can decide whether or not to treat it as a "toolchain" or a regular package. This will have to stay around, and can now be expanded to use the relocatable meta package too.

We invoke this heuristic when interpreting a lock file which is currently configured by the user.

The question of forcing relocatable for all users is not handled in this PR however. That will follow once we have good user-support for OCaml versions older than 5.4, for which either David's repository or our overlays will handle.

Detect relocatable compilers and bypass the toolchain mechanism for
them. Relocatable compilers can be installed as normal packages since
they don't have hardcoded absolute paths.

A compiler is considered relocatable if either:
- The relocatable-compiler meta-package is present (dra27's repo)
- The OCaml version is >= 5.5.0 (natively relocatable)

When a relocatable compiler is detected, the toolchain mechanism
(prefix redirect, DESTDIR install, shared cache) is skipped entirely.

Also set OPAMSWITCH=dune in the package build environment so that the
relocatable compiler's process.sh script can progress without an
actual opam switch.

Signed-off-by: Ali Caglayan <alizter@gmail.com>
@Alizter Alizter force-pushed the push-ssmqlovpkqol branch from 1daa1b0 to 610035c Compare March 30, 2026 11:26
@Alizter Alizter marked this pull request as ready for review March 30, 2026 13:06
@Alizter Alizter requested a review from rgrinberg March 30, 2026 13:27
@Alizter Alizter merged commit f1624a4 into ocaml:main Apr 2, 2026
29 checks passed
@Alizter Alizter deleted the push-ssmqlovpkqol branch April 2, 2026 10:36
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