25
25
//!
26
26
//! For more information see <https://crates.io/substrate-wasm-builder>
27
27
28
- use std:: { env, process:: Command , fs, path:: { PathBuf , Path } } ;
28
+ use std:: { env, process:: { Command , self } , fs, path:: { PathBuf , Path } } ;
29
29
30
30
/// Environment variable that tells us to skip building the WASM binary.
31
31
const SKIP_BUILD_ENV : & str = "SKIP_WASM_BUILD" ;
@@ -56,8 +56,13 @@ pub enum WasmBuilderSource {
56
56
repo : & ' static str ,
57
57
rev : & ' static str ,
58
58
} ,
59
- /// Use the given version released on crates.io
59
+ /// Use the given version released on crates.io.
60
60
Crates ( & ' static str ) ,
61
+ /// Use the given version released on crates.io or from the given path.
62
+ CratesOrPath {
63
+ version : & ' static str ,
64
+ path : & ' static str ,
65
+ }
61
66
}
62
67
63
68
impl WasmBuilderSource {
@@ -75,6 +80,15 @@ impl WasmBuilderSource {
75
80
WasmBuilderSource :: Crates ( version) => {
76
81
format ! ( "version = \" {}\" " , version)
77
82
}
83
+ WasmBuilderSource :: CratesOrPath { version, path } => {
84
+ replace_back_slashes (
85
+ format ! (
86
+ "path = \" {}\" , version = \" {}\" " ,
87
+ manifest_dir. join( path) . display( ) ,
88
+ version
89
+ )
90
+ )
91
+ }
78
92
}
79
93
}
80
94
}
@@ -87,9 +101,9 @@ impl WasmBuilderSource {
87
101
/// constant `WASM_BINARY` which contains the build wasm binary.
88
102
/// `wasm_builder_path` - Path to the wasm-builder project, relative to `CARGO_MANIFEST_DIR`.
89
103
pub fn build_current_project ( file_name : & str , wasm_builder_source : WasmBuilderSource ) {
90
- generate_rerun_if_changed_instructions ( ) ;
91
-
92
104
if check_skip_build ( ) {
105
+ // If we skip the build, we still want to make sure to be called when an env variable changes
106
+ generate_rerun_if_changed_instructions ( ) ;
93
107
return ;
94
108
}
95
109
@@ -110,6 +124,10 @@ pub fn build_current_project(file_name: &str, wasm_builder_source: WasmBuilderSo
110
124
create_project ( & project_folder, & file_path, & manifest_dir, wasm_builder_source, & cargo_toml_path) ;
111
125
run_project ( & project_folder) ;
112
126
}
127
+
128
+ // As last step we need to generate our `rerun-if-changed` stuff. If a build fails, we don't
129
+ // want to spam the output!
130
+ generate_rerun_if_changed_instructions ( ) ;
113
131
}
114
132
115
133
fn create_project (
@@ -164,7 +182,8 @@ fn run_project(project_folder: &Path) {
164
182
}
165
183
166
184
if !cmd. status ( ) . map ( |s| s. success ( ) ) . unwrap_or ( false ) {
167
- panic ! ( "Running WASM build runner failed!" ) ;
185
+ // Don't spam the output with backtraces when a build failed!
186
+ process:: exit ( 1 ) ;
168
187
}
169
188
}
170
189
0 commit comments