@@ -83,6 +83,42 @@ let with_runtime_files ~runtime_wasm_files f =
8383 in
8484 Wat_preprocess. with_preprocessed_files ~variables: [] ~inputs f
8585
86+ let build_runtime ~runtime_file =
87+ (* Keep this variables in sync with gen/gen.ml *)
88+ let variables =
89+ [ ( " effects"
90+ , Wat_preprocess. String
91+ (match Config. effects () with
92+ | `Jspi -> " jspi"
93+ | `Cps -> " cps"
94+ | `Disabled | `Double_translation -> assert false ) )
95+ ]
96+ in
97+ match
98+ List. find_opt Runtime_files. precompiled_runtimes ~f: (fun (flags , _ ) ->
99+ assert (
100+ List. length flags = List. length variables
101+ && List. for_all2 ~f: (fun (k , _ ) (k' , _ ) -> String. equal k k') flags variables);
102+ Poly. equal flags variables)
103+ with
104+ | Some (_ , contents ) -> Fs. write_file ~name: runtime_file ~contents
105+ | None ->
106+ let inputs =
107+ List. map
108+ ~f: (fun (module_name , contents ) ->
109+ { Wat_preprocess. module_name
110+ ; file = module_name ^ " .wat"
111+ ; source = Contents contents
112+ })
113+ Runtime_files. wat_files
114+ in
115+ Runtime. build
116+ ~link_options: [ " -g" ]
117+ ~opt_options: [ " -g" ; " -O2" ]
118+ ~variables
119+ ~inputs
120+ ~output_file: runtime_file
121+
86122let link_and_optimize
87123 ~profile
88124 ~sourcemap_root
@@ -101,7 +137,7 @@ let link_and_optimize
101137 let enable_source_maps = Option. is_some opt_sourcemap_file in
102138 Fs. with_intermediate_file (Filename. temp_file " runtime" " .wasm" )
103139 @@ fun runtime_file ->
104- Fs. write_file ~name: runtime_file ~contents: Runtime_files. wasm_runtime ;
140+ build_runtime ~ runtime_file ;
105141 Fs. with_intermediate_file (Filename. temp_file " wasm-merged" " .wasm" )
106142 @@ fun temp_file ->
107143 opt_with
@@ -147,7 +183,7 @@ let link_and_optimize
147183
148184let link_runtime ~profile runtime_wasm_files output_file =
149185 if List. is_empty runtime_wasm_files
150- then Fs. write_file ~name : output_file ~contents: Runtime_files. wasm_runtime
186+ then build_runtime ~runtime_file : output_file
151187 else
152188 Fs. with_intermediate_file (Filename. temp_file " extra_runtime" " .wasm" )
153189 @@ fun extra_runtime ->
@@ -169,7 +205,7 @@ let link_runtime ~profile runtime_wasm_files output_file =
169205 () ;
170206 Fs. with_intermediate_file (Filename. temp_file " runtime" " .wasm" )
171207 @@ fun runtime_file ->
172- Fs. write_file ~name: runtime_file ~contents: Runtime_files. wasm_runtime ;
208+ build_runtime ~ runtime_file ;
173209 Binaryen. link
174210 ~opt_output_sourcemap: None
175211 ~inputs:
0 commit comments