@@ -56,6 +56,11 @@ struct Args {
56
56
build_kind : BuildKind ,
57
57
template : Option < String > ,
58
58
list_templates : bool ,
59
+ // This is a String instead of an
60
+ // enum since one can have custom
61
+ // toolchains (ex. a rustc developer
62
+ // will probably have `stage1`).
63
+ toolchain_version : Option < String > ,
59
64
60
65
#[ cfg( windows) ]
61
66
install_file_association : bool ,
@@ -235,6 +240,15 @@ fn parse_args() -> Args {
235
240
. takes_value ( true )
236
241
. requires ( "expr" )
237
242
)
243
+ . arg ( Arg :: new ( "toolchain-version" )
244
+ . about ( "Build the script using the given toolchain version." )
245
+ . long ( "toolchain-version" )
246
+ // "channel"
247
+ . short ( 'c' )
248
+ . takes_value ( true )
249
+ // FIXME: remove if benchmarking is stabilized
250
+ . conflicts_with ( "bench" )
251
+ )
238
252
. arg ( Arg :: new ( "list-templates" )
239
253
. about ( "List the available templates." )
240
254
. long ( "list-templates" )
@@ -289,6 +303,7 @@ fn parse_args() -> Args {
289
303
build_kind : BuildKind :: from_flags ( m. is_present ( "test" ) , m. is_present ( "bench" ) ) ,
290
304
template : m. value_of ( "template" ) . map ( Into :: into) ,
291
305
list_templates : m. is_present ( "list-templates" ) ,
306
+ toolchain_version : m. value_of ( "toolchain-version" ) . map ( Into :: into) ,
292
307
#[ cfg( windows) ]
293
308
install_file_association : m. is_present ( "install-file-association" ) ,
294
309
#[ cfg( windows) ]
@@ -658,7 +673,12 @@ struct InputAction {
658
673
*/
659
674
using_cache : bool ,
660
675
661
- use_nightly : bool ,
676
+ /**
677
+ Which toolchain the script should be built with.
678
+
679
+ `None` indicates that the script should be built with a stable toolchain.
680
+ */
681
+ toolchain_version : Option < String > ,
662
682
663
683
/// The package metadata structure for the current invocation.
664
684
metadata : PackageMetadata ,
@@ -685,7 +705,7 @@ impl InputAction {
685
705
cargo (
686
706
cmd,
687
707
& * self . manifest_path ( ) . to_string_lossy ( ) ,
688
- self . use_nightly ,
708
+ self . toolchain_version . as_ref ( ) . map ( |s| s . as_str ( ) ) ,
689
709
& self . metadata ,
690
710
script_args,
691
711
run_quietly,
@@ -788,14 +808,22 @@ fn decide_action_for(
788
808
} ;
789
809
info ! ( "input_meta: {:?}" , input_meta) ;
790
810
811
+ let toolchain_version = args
812
+ . toolchain_version
813
+ . clone ( )
814
+ . or_else ( || match args. build_kind {
815
+ BuildKind :: Bench => Some ( "nightly" . into ( ) ) ,
816
+ _ => None ,
817
+ } ) ;
818
+
791
819
let mut action = InputAction {
792
820
cargo_output : args. cargo_output ,
793
821
force_compile : force,
794
822
emit_metadata : true ,
795
823
execute : true ,
796
824
pkg_path,
797
825
using_cache,
798
- use_nightly : matches ! ( args . build_kind , BuildKind :: Bench ) ,
826
+ toolchain_version ,
799
827
metadata : input_meta,
800
828
old_metadata : None ,
801
829
manifest : mani_str,
@@ -1127,14 +1155,14 @@ Constructs a Cargo command that runs on the script package.
1127
1155
fn cargo (
1128
1156
cmd_name : & str ,
1129
1157
manifest : & str ,
1130
- nightly : bool ,
1158
+ maybe_toolchain_version : Option < & str > ,
1131
1159
meta : & PackageMetadata ,
1132
1160
script_args : & [ String ] ,
1133
1161
run_quietly : bool ,
1134
1162
) -> MainResult < Command > {
1135
1163
let mut cmd = Command :: new ( "cargo" ) ;
1136
- if nightly {
1137
- cmd. arg ( "+nightly" ) ;
1164
+ if let Some ( toolchain_version ) = maybe_toolchain_version {
1165
+ cmd. arg ( format ! ( "+{}" , toolchain_version ) ) ;
1138
1166
}
1139
1167
cmd. arg ( cmd_name) ;
1140
1168
0 commit comments