@@ -48,6 +48,7 @@ impl WasmBuilderSelectProject {
4848 file_name : None ,
4949 project_cargo_toml : get_manifest_dir ( ) . join ( "Cargo.toml" ) ,
5050 features_to_enable : Vec :: new ( ) ,
51+ disable_runtime_version_section_check : false ,
5152 }
5253 }
5354
@@ -63,6 +64,7 @@ impl WasmBuilderSelectProject {
6364 file_name : None ,
6465 project_cargo_toml : path,
6566 features_to_enable : Vec :: new ( ) ,
67+ disable_runtime_version_section_check : false ,
6668 } )
6769 } else {
6870 Err ( "Project path must point to the `Cargo.toml` of the project" )
@@ -93,6 +95,8 @@ pub struct WasmBuilder {
9395 project_cargo_toml : PathBuf ,
9496 /// Features that should be enabled when building the wasm binary.
9597 features_to_enable : Vec < String > ,
98+ /// Should the builder not check that the `runtime_version` section exists in the wasm binary?
99+ disable_runtime_version_section_check : bool ,
96100}
97101
98102impl WasmBuilder {
@@ -143,6 +147,17 @@ impl WasmBuilder {
143147 self
144148 }
145149
150+ /// Disable the check for the `runtime_version` wasm section.
151+ ///
152+ /// By default the `wasm-builder` will ensure that the `runtime_version` section will
153+ /// exists in the build wasm binary. This `runtime_version` section is used to get the
154+ /// `RuntimeVersion` without needing to call into the wasm binary. However, for some
155+ /// use cases (like tests) you may want to disable this check.
156+ pub fn disable_runtime_version_section_check ( mut self ) -> Self {
157+ self . disable_runtime_version_section_check = true ;
158+ self
159+ }
160+
146161 /// Build the WASM binary.
147162 pub fn build ( self ) {
148163 let out_dir = PathBuf :: from ( env:: var ( "OUT_DIR" ) . expect ( "`OUT_DIR` is set by cargo!" ) ) ;
@@ -165,6 +180,7 @@ impl WasmBuilder {
165180 self . rust_flags . into_iter ( ) . map ( |f| format ! ( "{} " , f) ) . collect ( ) ,
166181 self . features_to_enable ,
167182 self . file_name ,
183+ !self . disable_runtime_version_section_check ,
168184 ) ;
169185
170186 // As last step we need to generate our `rerun-if-changed` stuff. If a build fails, we don't
@@ -215,7 +231,7 @@ fn generate_rerun_if_changed_instructions() {
215231/// The current project is determined by using the `CARGO_MANIFEST_DIR` environment variable.
216232///
217233/// `file_name` - The name + path of the file being generated. The file contains the
218- /// constant `WASM_BINARY`, which contains the built WASM binary.
234+ /// constant `WASM_BINARY`, which contains the built wasm binary.
219235///
220236/// `project_cargo_toml` - The path to the `Cargo.toml` of the project that should be built.
221237///
@@ -224,14 +240,17 @@ fn generate_rerun_if_changed_instructions() {
224240/// `features_to_enable` - Features that should be enabled for the project.
225241///
226242/// `wasm_binary_name` - The optional wasm binary name that is extended with
227- ///
228243/// `.compact.compressed.wasm`. If `None`, the project name will be used.
244+ ///
245+ /// `check_for_runtime_version_section` - Should the wasm binary be checked for the
246+ /// `runtime_version` section?
229247fn build_project (
230248 file_name : PathBuf ,
231249 project_cargo_toml : PathBuf ,
232250 default_rustflags : String ,
233251 features_to_enable : Vec < String > ,
234252 wasm_binary_name : Option < String > ,
253+ check_for_runtime_version_section : bool ,
235254) {
236255 let cargo_cmd = match crate :: prerequisites:: check ( ) {
237256 Ok ( cmd) => cmd,
@@ -247,6 +266,7 @@ fn build_project(
247266 cargo_cmd,
248267 features_to_enable,
249268 wasm_binary_name,
269+ check_for_runtime_version_section,
250270 ) ;
251271
252272 let ( wasm_binary, wasm_binary_bloaty) = if let Some ( wasm_binary) = wasm_binary {
0 commit comments