@@ -11,10 +11,13 @@ pub fn rustup_add_wasm_target() -> Result<(), Error> {
11
11
emoji:: TARGET
12
12
) ;
13
13
let pb = PBAR . message ( & step) ;
14
+ ensure_nightly ( ) ?;
14
15
let output = Command :: new ( "rustup" )
15
16
. arg ( "target" )
16
17
. arg ( "add" )
17
18
. arg ( "wasm32-unknown-unknown" )
19
+ . arg ( "--toolchain" )
20
+ . arg ( "nightly" )
18
21
. output ( ) ?;
19
22
pb. finish ( ) ;
20
23
if !output. status . success ( ) {
@@ -25,6 +28,22 @@ pub fn rustup_add_wasm_target() -> Result<(), Error> {
25
28
}
26
29
}
27
30
31
+ fn ensure_nightly ( ) -> Result < ( ) , Error > {
32
+ let nightly_check = Command :: new ( "rustc" ) . arg ( "+nightly" ) . arg ( "-V" ) . output ( ) ?;
33
+ if !nightly_check. status . success ( ) {
34
+ let res = Command :: new ( "rustup" )
35
+ . arg ( "toolchain" )
36
+ . arg ( "install" )
37
+ . arg ( "nightly" )
38
+ . output ( ) ?;
39
+ if !res. status . success ( ) {
40
+ let s = String :: from_utf8_lossy ( & res. stderr ) ;
41
+ return Error :: cli ( "Adding the nightly toolchain failed" , s) ;
42
+ }
43
+ }
44
+ Ok ( ( ) )
45
+ }
46
+
28
47
pub fn cargo_build_wasm ( path : & str , debug : bool ) -> Result < ( ) , Error > {
29
48
let step = format ! (
30
49
"{} {}Compiling to WASM..." ,
@@ -34,7 +53,7 @@ pub fn cargo_build_wasm(path: &str, debug: bool) -> Result<(), Error> {
34
53
let pb = PBAR . message ( & step) ;
35
54
let output = {
36
55
let mut cmd = Command :: new ( "cargo" ) ;
37
- cmd. current_dir ( path) . arg ( "build" ) ;
56
+ cmd. current_dir ( path) . arg ( "+nightly" ) . arg ( " build") ;
38
57
if !debug {
39
58
cmd. arg ( "--release" ) ;
40
59
}
0 commit comments