Skip to content

Commit 75f8ebd

Browse files
committed
Cross compilation: Also generate 'prefix'/'prefixexec' sections for .install files
1 parent 78067f4 commit 75f8ebd

18 files changed

Lines changed: 156 additions & 30 deletions

File tree

bin/install_uninstall.ml

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ let get_dirs context ~prefix_from_command_line ~from_command_line =
5757
~hints:
5858
[ Pp.concat
5959
~sep:Pp.space
60-
[ Pp.text "It can be specified with"
61-
; User_message.command "--prefix"
62-
; Pp.textf "or by setting"
63-
; User_message.command (sprintf "--%s" name)
64-
]
60+
([ Pp.text "It can be specified with"; User_message.command "--prefix" ]
61+
@
62+
if String.equal name "prefix"
63+
then []
64+
else
65+
[ Pp.textf "or by setting"; User_message.command (sprintf "--%s" name) ]
66+
)
6567
|> Pp.hovbox
6668
]
6769
in
@@ -73,6 +75,7 @@ let get_dirs context ~prefix_from_command_line ~from_command_line =
7375
; doc_root = must_be_defined "docdir" roots.doc_root
7476
; share_root = must_be_defined "datadir" roots.share_root
7577
; man = must_be_defined "mandir" roots.man
78+
; prefix = must_be_defined "prefix" roots.prefix
7679
}
7780
;;
7881

@@ -624,7 +627,7 @@ let run
624627
if relocatable
625628
then (
626629
match prefix_from_command_line with
627-
| Some dir -> Some (Path.of_string dir)
630+
| Some dir -> Some (Path.of_string_allow_outside_workspace dir)
628631
| None ->
629632
User_error.raise
630633
[ Pp.concat
@@ -853,16 +856,18 @@ let make ~what =
853856
let common, config = Common.init builder in
854857
Scheduler_setup.no_build_no_rpc ~config (fun () ->
855858
let from_command_line =
856-
{ Install.Roots.lib_root = libdir_from_command_line
857-
; etc_root = etcdir_from_command_line
858-
; doc_root = docdir_from_command_line
859-
; man = mandir_from_command_line
860-
; bin = bindir_from_command_line
861-
; sbin = sbindir_from_command_line
862-
; libexec_root = libexecdir_from_command_line
863-
; share_root = datadir_from_command_line
859+
let path_of_string = Option.map ~f:Path.of_string in
860+
{ Install.Roots.lib_root = path_of_string libdir_from_command_line
861+
; etc_root = path_of_string etcdir_from_command_line
862+
; doc_root = path_of_string docdir_from_command_line
863+
; man = path_of_string mandir_from_command_line
864+
; bin = path_of_string bindir_from_command_line
865+
; sbin = path_of_string sbindir_from_command_line
866+
; libexec_root = path_of_string libexecdir_from_command_line
867+
; share_root = path_of_string datadir_from_command_line
868+
; prefix =
869+
Option.map ~f:Path.of_string_allow_outside_workspace prefix_from_command_line
864870
}
865-
|> Install.Roots.map ~f:(Option.map ~f:Path.of_string)
866871
|> Install.Roots.complete
867872
in
868873
run

boot/configure.ml

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ let () =
129129
pr " ; bin = %s" (option string !bindir);
130130
pr " ; sbin = %s" (option string !sbindir);
131131
pr " ; libexec_root = %s" (option string !libexecdir);
132+
pr " ; prefix = %s" (option string !prefix);
132133
pr " }";
133134
pr "";
134135
pr "let prefix : string option = %s" (option string !prefix);

otherlibs/dune-private-libs/section/dune_section.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type t =
1313
| Stublibs
1414
| Man
1515
| Misc
16+
| Prefix
17+
| Prefixexec
1618

1719
let all =
1820
[ Lib, "lib"
@@ -29,6 +31,8 @@ let all =
2931
; Stublibs, "stublibs"
3032
; Man, "man"
3133
; Misc, "misc"
34+
; Prefix, "prefix"
35+
; Prefixexec, "prefixexec"
3236
]
3337
;;
3438

otherlibs/dune-private-libs/section/dune_section.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type t =
1313
| Stublibs
1414
| Man
1515
| Misc
16+
| Prefix
17+
| Prefixexec
1618

1719
val all : (t * string) list
1820
val of_string : string -> t option

src/dune_lang/section.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ let encode v =
4141
let all = Set.of_list (List.map ~f:fst Dune_section.all)
4242

4343
let should_set_executable_bit = function
44-
| Lib | Lib_root | Toplevel | Share | Share_root | Etc | Doc | Man | Misc -> false
45-
| Libexec | Libexec_root | Bin | Sbin | Stublibs -> true
44+
| Lib | Lib_root | Toplevel | Share | Share_root | Etc | Doc | Man | Misc | Prefix ->
45+
false
46+
| Libexec | Libexec_root | Bin | Sbin | Stublibs | Prefixexec -> true
4647
;;

src/dune_rules/install_entry_with_site.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ let make_with_site (section : Section_with_site.t) ?dst get_section ~kind src =
3030
| Share_root
3131
| Stublibs
3232
| Man
33+
| Prefix
34+
| Prefixexec
3335
| Misc -> section, dst
3436
in
3537
Entry.Unexpanded.make_with_dst section dst ~kind ~src

src/dune_rules/install_rules.ml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,14 +1436,31 @@ let gen_package_install_file_rules sctx (package : Package.t) =
14361436
let toolchain = Context_name.to_string toolchain in
14371437
Path.of_string (toolchain ^ "-sysroot")
14381438
in
1439-
List.rev_map entries ~f:(fun (e : Install.Entry.Sourced.Expanded.t) ->
1440-
{ e with
1441-
entry =
1442-
Install.Entry.Expanded.add_install_prefix
1443-
e.entry
1444-
~paths:install_paths
1445-
~prefix
1446-
})
1439+
let parent_dir_hacked =
1440+
(* pre-opam 2.6, the best way to install an alternative sysroot
1441+
was to generate .install files with ../.., which was disallowed in opam 2.5.1 *)
1442+
List.rev_map entries ~f:(fun (e : Install.Entry.Sourced.Expanded.t) ->
1443+
{ e with
1444+
entry =
1445+
Install.Entry.Expanded.add_install_prefix
1446+
e.entry
1447+
~paths:install_paths
1448+
~prefix
1449+
})
1450+
in
1451+
let prefix_entries =
1452+
(* opam 2.6+ supports a 'prefix' and 'prefixexec' key that allows us to directly specify this *)
1453+
List.rev_map entries ~f:(fun (e : Install.Entry.Sourced.Expanded.t) ->
1454+
{ e with
1455+
entry =
1456+
Install.Entry.Expanded.install_in_sysroot
1457+
e.entry
1458+
~paths:install_paths
1459+
~prefix
1460+
})
1461+
in
1462+
(* generating both is fine, since any given version of opam will only recognize one or the other *)
1463+
parent_dir_hacked @ prefix_entries
14471464
in
14481465
if not (Package.allow_empty package)
14491466
then

src/dune_rules/setup.defaults.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ let roots : string option Install.Roots.t =
99
; bin = None
1010
; sbin = None
1111
; libexec_root = None
12+
; prefix = None
1213
}
1314

1415
let prefix : string option = None

src/install/entry.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,22 @@ module Expanded = struct
215215
{ t with dst = Dst.explicit dst }
216216
;;
217217

218+
let install_in_sysroot t ~paths ~prefix =
219+
let i_want_to_install_the_file_as =
220+
relative_installed_path t ~paths
221+
|> Path.as_in_source_tree_exn
222+
|> Path.append_source prefix
223+
in
224+
let dst = Path.to_string i_want_to_install_the_file_as in
225+
{ t with
226+
dst = Dst.explicit dst
227+
; section =
228+
(if Section.should_set_executable_bit t.section
229+
then Section.Prefixexec
230+
else Section.Prefix)
231+
}
232+
;;
233+
218234
let of_install_file ~optional ~src ~dst ~section =
219235
{ src
220236
; section

src/install/entry.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module Expanded : sig
3434

3535
val set_src : _ t -> 'src -> 'src t
3636
val add_install_prefix : 'src t -> paths:Path.t Paths.t -> prefix:Path.t -> 'src t
37+
val install_in_sysroot : 'src t -> paths:Path.t Paths.t -> prefix:Path.t -> 'src t
3738
val gen_install_file : Path.t t list -> string
3839
val load_install_file : Path.t -> (Path.Local.t -> Path.t) -> Path.t t list
3940
end

0 commit comments

Comments
 (0)