@@ -30,7 +30,7 @@ let resolve_package cwd package_name =
30
30
let x = Bsb_pkg. resolve_bs_package ~cwd package_name in
31
31
{
32
32
Bsb_config_types. package_name ;
33
- package_install_path = x // Bsb_config. lib_ocaml
33
+ package_install_path = x // ! Bsb_global_backend. lib_ocaml_dir
34
34
}
35
35
36
36
type json_map = Ext_json_types .t Map_string .t
@@ -49,8 +49,8 @@ let extract_main_entries (map :json_map) =
49
49
let kind = ref " js" in
50
50
let main = ref None in
51
51
let _ = map
52
- |? (Bsb_build_schemas. kind , `Str (fun x -> kind := x))
53
- |? (Bsb_build_schemas. main , `Str (fun x -> main := Some x))
52
+ |? (Bsb_build_schemas. backend , `Str (fun x -> kind := x))
53
+ |? (Bsb_build_schemas. main_module , `Str (fun x -> main := Some x))
54
54
in
55
55
let path = begin match ! main with
56
56
(* This is technically optional when compiling to js *)
@@ -74,7 +74,15 @@ let extract_main_entries (map :json_map) =
74
74
begin match Map_string. find_opt map Bsb_build_schemas. entries with
75
75
| Some (Arr {content = s } ) -> entries := extract_entries s
76
76
| _ -> ()
77
- end ; ! entries
77
+ end ;
78
+ if not ! Bsb_global_backend. backend_is_set then
79
+ begin match ! entries with
80
+ | []
81
+ | (Bsb_config_types. JsTarget _ ) :: _ -> Bsb_global_backend. set_backend Bsb_config_types. Js
82
+ | (Bsb_config_types. NativeTarget _ ) :: _ -> Bsb_global_backend. set_backend Bsb_config_types. Native
83
+ | (Bsb_config_types. BytecodeTarget _ ) :: _ -> Bsb_global_backend. set_backend Bsb_config_types. Bytecode
84
+ end ;
85
+ ! entries
78
86
#else
79
87
let extract_main_entries (_ :json_map ) = []
80
88
#end
@@ -173,7 +181,7 @@ let check_stdlib (map : json_map) cwd (*built_in_package*) =
173
181
check_version_exit map stdlib_path;
174
182
Some {
175
183
Bsb_config_types. package_name = current_package;
176
- package_install_path = stdlib_path // Bsb_config. lib_ocaml ;
184
+ package_install_path = stdlib_path // ! Bsb_global_backend. lib_ocaml_dir ;
177
185
}
178
186
179
187
| _ -> assert false
@@ -403,6 +411,9 @@ let interpret_json
403
411
let refmt = extract_refmt map per_proj_dir in
404
412
let gentype_config = extract_gentype_config map per_proj_dir in
405
413
let bs_suffix = extract_bs_suffix_exn map in
414
+ (* This line has to be before any calls to Bsb_global_backend.backend, because it'll read the entries
415
+ array from the bsconfig and set the backend_ref to the first entry, if any. *)
416
+ let entries = extract_main_entries map in
406
417
(* The default situation is empty *)
407
418
let built_in_package = check_stdlib map per_proj_dir in
408
419
let package_specs =
@@ -470,7 +481,7 @@ let interpret_json
470
481
generate_merlin =
471
482
extract_boolean map Bsb_build_schemas. generate_merlin true ;
472
483
reason_react_jsx ;
473
- entries = extract_main_entries map ;
484
+ entries;
474
485
generators = extract_generators map ;
475
486
cut_generators ;
476
487
number_of_dev_groups;
0 commit comments