@@ -527,17 +527,6 @@ module Pkg = struct
527527 |> List. fold_left ~init: Dep.Set. empty ~f: (fun acc t -> dep t |> Dep.Set. add acc)
528528 ;;
529529
530- let install_roots t =
531- let default_install_roots = Paths. install_roots t.paths in
532- match Pkg_toolchain. is_compiler_and_toolchains_enabled t.info.name with
533- | false -> default_install_roots
534- | true ->
535- (* Compiler packages store their libraries in a subdirectory named "ocaml". *)
536- { default_install_roots with
537- lib_root = Path. relative default_install_roots.lib_root " ocaml"
538- }
539- ;;
540-
541530 (* Given a list of packages, construct an env containing variables
542531 set by each package. Variables containing delimited lists of
543532 paths (e.g. PATH) which appear in multiple package's envs are
@@ -548,7 +537,7 @@ module Pkg = struct
548537 let build_env_of_deps ts =
549538 List. fold_left ts ~init: Env.Map. empty ~f: (fun env t ->
550539 let env =
551- let roots = install_roots t in
540+ let roots = Paths. install_roots t.paths in
552541 let init = Value_list_env. add_path env Env_path. var roots.bin in
553542 let vars = Install.Roots. to_env_without_path roots ~relative: Path. relative in
554543 List. fold_left vars ~init ~f: (fun acc (var , path ) ->
@@ -1356,12 +1345,42 @@ module DB = struct
13561345 { id : Id .t
13571346 ; pkg_digest_table : Pkg_table .t
13581347 ; system_provided : Package.Name.Set .t
1348+ ; is_relocatable_compiler_context : bool
13591349 }
13601350
13611351 let equal x y = Id. equal x.id y.id
13621352
1363- let create ~pkg_digest_table ~system_provided =
1364- { id = Id. gen () ; pkg_digest_table; system_provided }
1353+ let create =
1354+ (* In dra27's relocatable repository, a compiler is relocatable if it
1355+ depends on this meta-package. *)
1356+ let [@ inline] is_relocatable_compiler_meta_package name =
1357+ Package.Name. equal name (Package.Name. of_string " relocatable-compiler" )
1358+ in
1359+ (* OCaml 5.5.0+ is natively relocatable. *)
1360+ let [@ inline] is_ocaml_5_5_or_above name version =
1361+ Dune_pkg.Dev_tool. is_compiler_package name
1362+ && OpamPackage.Version. compare
1363+ (Dune_pkg.Package_version. to_opam_package_version version)
1364+ (OpamPackage.Version. of_string " 5.5.0" )
1365+ |> Ordering. of_int
1366+ |> function
1367+ | Gt | Eq -> true
1368+ | Lt -> false
1369+ in
1370+ fun ~pkg_digest_table ~system_provided ->
1371+ { id = Id. gen ()
1372+ ; pkg_digest_table
1373+ ; system_provided
1374+ (* To know if a given package table has the relocatable compiler, we
1375+ need to find either the "relocatable-compiler" meta-package or
1376+ assert that the version of the OCaml compiler is at least 5.5.0. *)
1377+ ; is_relocatable_compiler_context =
1378+ Pkg_digest.Map. existsi
1379+ pkg_digest_table
1380+ ~f: (fun _ { Pkg_table. pkg = { info = { name; version; _ } ; _ } ; _ } ->
1381+ is_relocatable_compiler_meta_package name
1382+ || is_ocaml_5_5_or_above name version)
1383+ }
13651384 ;;
13661385
13671386 let pkg_digest_of_name lock_dir platform pkg_name ~system_provided =
@@ -1590,9 +1609,11 @@ end = struct
15901609 let build_command = Option. map build_command ~f: relocate_build in
15911610 let paths =
15921611 let paths = Paths. map_path write_paths ~f: Path. build in
1593- match Pkg_toolchain. is_compiler_and_toolchains_enabled info.name with
1594- | false -> paths
1595- | true ->
1612+ if
1613+ db.is_relocatable_compiler_context
1614+ || not (Pkg_toolchain. is_compiler_package_with_toolchains_enabled info.name)
1615+ then paths
1616+ else (
15961617 (* Modify the environment as well as build and install commands for
15971618 the compiler package. The specific changes are:
15981619 - setting the prefix in the build environment to inside the user's
@@ -1603,16 +1624,21 @@ end = struct
16031624 toolchain directory
16041625 - if a matching version of the compiler is
16051626 already installed in the user's toolchain directory then the
1606- build and install commands are replaced with no-ops *)
1627+ build and install commands are replaced with no-ops
1628+ - compiler packages store their libraries in a subdirectory
1629+ named "ocaml" *)
16071630 let prefix = Pkg_toolchain. installation_prefix pkg in
16081631 let install_roots =
1609- Pkg_toolchain. install_roots ~prefix
1610- |> Install.Roots. map ~f: Path. outside_build_dir
1632+ let roots =
1633+ Pkg_toolchain. install_roots ~prefix
1634+ |> Install.Roots. map ~f: Path. outside_build_dir
1635+ in
1636+ { roots with lib_root = Path. relative roots.lib_root " ocaml" }
16111637 in
16121638 { paths with
16131639 prefix = Path. outside_build_dir prefix
16141640 ; install_roots = Lazy. from_val install_roots
1615- }
1641+ })
16161642 in
16171643 let t =
16181644 { Pkg. id
0 commit comments