Skip to content

Commit 8ba42cd

Browse files
committed
Compiler: fix jsoo link when use-js-string is disabled
1 parent fa1ae1e commit 8ba42cd

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

compiler/lib/build_info.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,11 @@ let merge fname1 info1 fname2 info2 =
132132
| _, None, None -> assert false)
133133
info1
134134
info2
135+
136+
let configure t =
137+
StringMap.iter
138+
(fun k v ->
139+
match k with
140+
| "use-js-string" | "effects" -> Config.Flag.set k (bool_of_string v)
141+
| _ -> ())
142+
t

compiler/lib/build_info.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ exception
4444
val merge : string -> t -> string -> t -> t
4545

4646
val kind : t -> kind
47+
48+
val configure : t -> unit

compiler/lib/link_js.ml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -356,29 +356,31 @@ let link ~output ~linkall ~files ~resolve_sourcemap_url ~source_map =
356356
match build_info_for_file with
357357
| Some bi -> (
358358
match Build_info.kind bi with
359-
| `Runtime -> true
360-
| `Cma | `Exe | `Cmo | `Unknown -> false)
361-
| None -> false
359+
| `Runtime -> Some bi
360+
| `Cma | `Exe | `Cmo | `Unknown -> None)
361+
| None -> None
362362
in
363-
if is_runtime
364-
then (
365-
let primitives =
366-
List.fold_left units ~init:[] ~f:(fun acc (u : Unit_info.t) ->
367-
acc @ u.primitives)
368-
in
369-
let code = Parse_bytecode.link_info ~symtable:!sym ~primitives ~crcs:[] in
370-
let b = Buffer.create 100 in
371-
let fmt = Pretty_print.to_buffer b in
372-
Driver.configure fmt;
373-
Driver.f'
374-
~standalone:false
375-
~linkall:false
376-
~wrap_with_fun:`Iife
377-
fmt
378-
(Parse_bytecode.Debug.create ~include_cmis:false false)
379-
code;
380-
let content = Buffer.contents b in
381-
String.split_on_char ~sep:'\n' content |> List.iter ~f:(Line_writer.write oc));
363+
(match is_runtime with
364+
| None -> ()
365+
| Some bi ->
366+
Build_info.configure bi;
367+
let primitives =
368+
List.fold_left units ~init:[] ~f:(fun acc (u : Unit_info.t) ->
369+
acc @ u.primitives)
370+
in
371+
let code = Parse_bytecode.link_info ~symtable:!sym ~primitives ~crcs:[] in
372+
let b = Buffer.create 100 in
373+
let fmt = Pretty_print.to_buffer b in
374+
Driver.configure fmt;
375+
Driver.f'
376+
~standalone:false
377+
~linkall:false
378+
~wrap_with_fun:`Iife
379+
fmt
380+
(Parse_bytecode.Debug.create ~include_cmis:false false)
381+
code;
382+
let content = Buffer.contents b in
383+
String.split_on_char ~sep:'\n' content |> List.iter ~f:(Line_writer.write oc));
382384
(match !sm_for_file with
383385
| None -> ()
384386
| Some x -> sm := (x, !reloc) :: !sm);

0 commit comments

Comments
 (0)