Skip to content

Commit ab455e3

Browse files
authored
fix(rules): cross compilation bug (#6958)
It's possible for a context with targets to be a cross compilation context for other contexts. Previously, we'd assume that wasn't the case. fixes #6843 Signed-off-by: Rudi Grinberg <[email protected]>
1 parent 4eb93fd commit ab455e3

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

CHANGES.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Unreleased
22
----------
33

4+
- Fix cross compilation configuration when a context with targets is itself a
5+
host of another context (#6958, fixes #6843, @rgrinberg)
6+
47
- Fix parsing of the `<=` operator in *blang* expressions of `dune` files.
58
Previously, the operator would be interpreted as `,`. (#6928, @tatchi)
69

src/dune_rules/context.ml

+15-11
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ let check_fdo_support has_native ocfg ~name =
346346
version_string
347347
]
348348

349+
type instance =
350+
{ native : t
351+
; targets : t list
352+
}
353+
349354
let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets
350355
~host_context ~host_toolchain ~profile ~fdo_target_exe
351356
~dynamically_linked_foreign_archives ~instrument_with =
@@ -680,7 +685,7 @@ let create ~(kind : Kind.t) ~path ~env ~env_nodes ~name ~merlin ~targets
680685
~findlib_toolchain:(Some findlib_toolchain)
681686
>>| Option.some)
682687
in
683-
native :: List.filter_opt others
688+
{ native; targets = List.filter_opt others }
684689

685690
let which t fname = Program.which ~path:t.path fname
686691

@@ -735,9 +740,9 @@ let create_for_opam ~loc ~root ~env ~env_nodes ~targets ~profile ~switch ~name
735740
~instrument_with
736741

737742
module rec Instantiate : sig
738-
val instantiate : Context_name.t -> t list Memo.t
743+
val instantiate : Context_name.t -> instance Memo.t
739744
end = struct
740-
let instantiate_impl name : t list Memo.t =
745+
let instantiate_impl name : instance Memo.t =
741746
let env = Global.env () in
742747
let* workspace = Workspace.workspace () in
743748
let context =
@@ -747,13 +752,9 @@ end = struct
747752
let* host_context =
748753
match Workspace.Context.host_context context with
749754
| None -> Memo.return None
750-
| Some context_name -> (
751-
let+ contexts = Instantiate.instantiate context_name in
752-
match contexts with
753-
| [ x ] -> Some x
754-
| [] -> assert false (* checked by workspace *)
755-
| _ :: _ -> assert false)
756-
(* target cannot be host *)
755+
| Some context_name ->
756+
let+ { native; targets = _ } = Instantiate.instantiate context_name in
757+
Some native
757758
in
758759
let env_nodes =
759760
let context = Workspace.Context.env context in
@@ -826,7 +827,10 @@ module DB = struct
826827
let* workspace = Workspace.workspace () in
827828
let+ contexts =
828829
Memo.parallel_map workspace.contexts ~f:(fun c ->
829-
Instantiate.instantiate (Workspace.Context.name c))
830+
let+ { native; targets } =
831+
Instantiate.instantiate (Workspace.Context.name c)
832+
in
833+
native :: targets)
830834
in
831835
let all = List.concat contexts in
832836
List.iter all ~f:(fun t ->

test/blackbox-tests/test-cases/custom-cross-compilation/github6843.t

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Cross compilation setup that causes dune to crash
2121
$ export OCAMLFIND_CONF=$PWD/etc/findlib.conf
2222
$ mkdir -p etc/findlib.conf.d
2323
$ touch etc/findlib.conf etc/findlib.conf.d/esperanto.conf
24-
$ dune build -x esperanto ./cat.exe 2>&1 | awk '/I must not/,/Only I will remain/'
25-
I must not crash. Uncertainty is the mind-killer. Exceptions are the
26-
little-death that brings total obliteration. I will fully express my cases.
27-
Execution will pass over me and through me. And when it has gone past, I
28-
will unwind the stack along its path. Where the cases are handled there will
29-
be nothing. Only I will remain.
24+
$ dune build -x esperanto ./cat.exe
25+
File "dune", line 1, characters 18-21:
26+
1 | (executable (name cat))
27+
^^^
28+
Error: Module "Cat" doesn't exist.
29+
[1]

0 commit comments

Comments
 (0)