@@ -68,7 +68,7 @@ let run
6868 { Cmd_arg. common
6969 ; profile
7070 ; source_map
71- ; runtime_files
71+ ; runtime_files = runtime_files_from_cmdline
7272 ; no_runtime
7373 ; input_file
7474 ; output_file
@@ -87,6 +87,7 @@ let run
8787 ; fs_external
8888 ; export_file
8989 ; keep_unit_names
90+ ; include_partial_runtime
9091 } =
9192 let include_cmis = toplevel && not no_cmis in
9293 let custom_header = common.Jsoo_cmdline.Arg. custom_header in
@@ -120,11 +121,13 @@ let run
120121 Some (Hashtbl. fold (fun cmi () acc -> cmi :: acc) t [] )
121122 in
122123 let runtime_files =
123- if toplevel || dynlink
124+ if ( not no_runtime) && ( toplevel || dynlink)
124125 then
125126 let add_if_absent x l = if List. mem x ~set: l then l else x :: l in
126- runtime_files |> add_if_absent " +toplevel.js" |> add_if_absent " +dynlink.js"
127- else runtime_files
127+ runtime_files_from_cmdline
128+ |> add_if_absent " +toplevel.js"
129+ |> add_if_absent " +dynlink.js"
130+ else runtime_files_from_cmdline
128131 in
129132 let runtime_files, builtin =
130133 List. partition_map runtime_files ~f: (fun name ->
@@ -176,7 +179,7 @@ let run
176179 , noloc )
177180 ])
178181 in
179- let output (one : Parse_bytecode.one ) ~standalone ~source_map ~linkall output_file =
182+ let output (one : Parse_bytecode.one ) ~standalone ~source_map ~link output_file =
180183 check_debug one;
181184 let init_pseudo_fs = fs_external && standalone in
182185 let sm =
@@ -194,7 +197,7 @@ let run
194197 ~target: (JavaScript fmt)
195198 ~standalone
196199 ?profile
197- ~linkall
200+ ~link
198201 ~wrap_with_fun
199202 ?source_map
200203 one.debug
@@ -218,7 +221,7 @@ let run
218221 ~target: (JavaScript fmt)
219222 ~standalone
220223 ?profile
221- ~linkall
224+ ~link
222225 ~wrap_with_fun
223226 ?source_map
224227 one.debug
@@ -229,7 +232,14 @@ let run
229232 let instr = fs_instr2 in
230233 let code = Code. prepend Code. empty instr in
231234 let pfs_fmt = Pretty_print. to_out_channel chan in
232- Driver. f' ~standalone ?profile ~wrap_with_fun pfs_fmt one.debug code));
235+ Driver. f'
236+ ~standalone
237+ ~link: `Needed
238+ ?profile
239+ ~wrap_with_fun
240+ pfs_fmt
241+ one.debug
242+ code));
233243 res
234244 in
235245 if times () then Format. eprintf " compilation: %a@." Timer. print t;
@@ -245,11 +255,32 @@ let run
245255 let uinfo = Unit_info. of_cmo cmo in
246256 Pretty_print. string fmt " \n " ;
247257 Pretty_print. string fmt (Unit_info. to_string uinfo);
248- output code ~source_map ~standalone ~linkall: false output_file
258+ output code ~source_map ~standalone ~link: `No output_file
259+ in
260+ let output_partial_runtime ~standalone ~source_map ((_ , fmt ) as output_file ) =
261+ assert (not standalone);
262+ let uinfo =
263+ Unit_info. of_primitives
264+ (Linker. list_all ~from: runtime_files_from_cmdline () |> StringSet. elements)
265+ in
266+ Pretty_print. string fmt " \n " ;
267+ Pretty_print. string fmt (Unit_info. to_string uinfo);
268+ let code =
269+ { Parse_bytecode. code = Code. empty
270+ ; cmis = StringSet. empty
271+ ; debug = Parse_bytecode.Debug. create ~include_cmis: false false
272+ }
273+ in
274+ output
275+ code
276+ ~source_map
277+ ~standalone
278+ ~link: (`All_from runtime_files_from_cmdline)
279+ output_file
249280 in
250281 (if runtime_only
251282 then (
252- let prims = Primitive. get_external () |> StringSet. elements in
283+ let prims = Linker. list_all () |> StringSet. elements in
253284 assert (List. length prims > 0 );
254285 let code, uinfo = Parse_bytecode. predefined_exceptions ~target: `JavaScript in
255286 let uinfo = { uinfo with primitives = uinfo.primitives @ prims } in
@@ -268,7 +299,7 @@ let run
268299 (fun ~standalone ~source_map ((_ , fmt ) as output_file ) ->
269300 Pretty_print. string fmt " \n " ;
270301 Pretty_print. string fmt (Unit_info. to_string uinfo);
271- output code ~source_map ~standalone ~linkall: true output_file))
302+ output code ~source_map ~standalone ~link: `All output_file))
272303 else
273304 let kind, ic, close_ic, include_dirs =
274305 match input_file with
@@ -307,7 +338,7 @@ let run
307338 ~build_info: (Build_info. create `Exe )
308339 ~source_map
309340 (fst output_file)
310- (output code ~linkall )
341+ (output code ~link: ( if linkall then `All else `Needed ) )
311342 | `Cmo cmo ->
312343 let output_file =
313344 match output_file, keep_unit_names with
@@ -338,8 +369,35 @@ let run
338369 ~build_info: (Build_info. create `Cmo )
339370 ~source_map
340371 output_file
341- (output_partial cmo code)
372+ (fun ~standalone ~source_map output ->
373+ let source_map =
374+ if not include_partial_runtime
375+ then source_map
376+ else output_partial_runtime ~standalone ~source_map output
377+ in
378+ output_partial cmo code ~standalone ~source_map output)
342379 | `Cma cma when keep_unit_names ->
380+ (if include_partial_runtime
381+ then
382+ let output_file =
383+ let gen dir = Filename. concat dir " runtime.js" in
384+ match output_file with
385+ | `Stdout , false -> gen " ./"
386+ | `Name x , false -> gen (Filename. dirname x)
387+ | `Name x, true
388+ when String. length x > 0 && Char. equal x.[String. length x - 1 ] '/' ->
389+ gen x
390+ | `Stdout , true | `Name _ , true ->
391+ failwith " use [-o dirname/] or remove [--keep-unit-names]"
392+ in
393+ output_gen
394+ ~standalone: false
395+ ~custom_header
396+ ~build_info: (Build_info. create `Runtime )
397+ ~source_map
398+ (`Name output_file)
399+ (fun ~standalone ~source_map output ->
400+ output_partial_runtime ~standalone ~source_map output));
343401 List. iter cma.lib_units ~f: (fun cmo ->
344402 let output_file =
345403 match output_file with
@@ -377,6 +435,11 @@ let run
377435 (output_partial cmo code))
378436 | `Cma cma ->
379437 let f ~standalone ~source_map output =
438+ let source_map =
439+ if not include_partial_runtime
440+ then source_map
441+ else output_partial_runtime ~standalone ~source_map output
442+ in
380443 List. fold_left cma.lib_units ~init: source_map ~f: (fun source_map cmo ->
381444 let t1 = Timer. make () in
382445 let code =
0 commit comments