@@ -20,7 +20,11 @@ pub struct Sysroot {
2020}
2121
2222impl Sysroot {
23- pub fn install ( sha : String , triple : & str ) -> anyhow:: Result < Self > {
23+ pub fn install (
24+ sha : String ,
25+ triple : & str ,
26+ backends : Vec < CodegenBackend > ,
27+ ) -> anyhow:: Result < Self > {
2428 let unpack_into = "cache" ;
2529
2630 fs:: create_dir_all ( unpack_into) ?;
@@ -31,10 +35,13 @@ impl Sysroot {
3135 triple : triple. to_owned ( ) ,
3236 } ;
3337
34- download. get_and_extract ( ModuleVariant :: Rustc ) ?;
35- download. get_and_extract ( ModuleVariant :: Std ) ?;
36- download. get_and_extract ( ModuleVariant :: Cargo ) ?;
37- download. get_and_extract ( ModuleVariant :: RustSrc ) ?;
38+ download. get_and_extract ( Component :: Rustc ) ?;
39+ download. get_and_extract ( Component :: Std ) ?;
40+ download. get_and_extract ( Component :: Cargo ) ?;
41+ download. get_and_extract ( Component :: RustSrc ) ?;
42+ if backends. contains ( & CodegenBackend :: Cranelift ) {
43+ download. get_and_extract ( Component :: Cranelift ) ?;
44+ }
3845
3946 let sysroot = download. into_sysroot ( ) ?;
4047
@@ -70,29 +77,30 @@ struct SysrootDownload {
7077
7178const BASE_URL : & str = "https://ci-artifacts.rust-lang.org/rustc-builds" ;
7279
73- // FIXME(eddyb) rename to just `Component`.
7480#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
75- enum ModuleVariant {
81+ enum Component {
7682 Cargo ,
7783 Rustc ,
7884 Std ,
7985 RustSrc ,
86+ Cranelift ,
8087}
8188
82- impl fmt:: Display for ModuleVariant {
89+ impl fmt:: Display for Component {
8390 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
8491 match * self {
85- ModuleVariant :: Cargo => write ! ( f, "cargo" ) ,
86- ModuleVariant :: Rustc => write ! ( f, "rustc" ) ,
87- ModuleVariant :: Std => write ! ( f, "rust-std" ) ,
88- ModuleVariant :: RustSrc => write ! ( f, "rust-src" ) ,
92+ Component :: Cargo => write ! ( f, "cargo" ) ,
93+ Component :: Rustc => write ! ( f, "rustc" ) ,
94+ Component :: Std => write ! ( f, "rust-std" ) ,
95+ Component :: RustSrc => write ! ( f, "rust-src" ) ,
96+ Component :: Cranelift => write ! ( f, "rustc-codegen-cranelift" ) ,
8997 }
9098 }
9199}
92100
93- impl ModuleVariant {
101+ impl Component {
94102 fn url ( & self , channel : & str , sysroot : & SysrootDownload , triple : & str ) -> String {
95- let suffix = if * self == ModuleVariant :: RustSrc {
103+ let suffix = if * self == Component :: RustSrc {
96104 String :: new ( )
97105 } else {
98106 format ! ( "-{}" , triple)
@@ -137,15 +145,15 @@ impl SysrootDownload {
137145 } )
138146 }
139147
140- fn get_and_extract ( & self , variant : ModuleVariant ) -> anyhow:: Result < ( ) > {
148+ fn get_and_extract ( & self , component : Component ) -> anyhow:: Result < ( ) > {
141149 let archive_path = self . directory . join ( format ! (
142150 "{}-{}-{}.tar.xz" ,
143- self . rust_sha, self . triple, variant ,
151+ self . rust_sha, self . triple, component ,
144152 ) ) ;
145153 if archive_path. exists ( ) {
146154 let reader = BufReader :: new ( File :: open ( & archive_path) ?) ;
147155 let decompress = XzDecoder :: new ( reader) ;
148- let extract = self . extract ( variant , decompress) ;
156+ let extract = self . extract ( component , decompress) ;
149157 match extract {
150158 Ok ( ( ) ) => return Ok ( ( ) ) ,
151159 Err ( err) => {
@@ -158,17 +166,17 @@ impl SysrootDownload {
158166 // We usually have nightlies but we want to avoid breaking down if we
159167 // accidentally end up with a beta or stable commit.
160168 let urls = [
161- variant . url ( "nightly" , self , & self . triple ) ,
162- variant . url ( "beta" , self , & self . triple ) ,
163- variant . url ( "stable" , self , & self . triple ) ,
169+ component . url ( "nightly" , self , & self . triple ) ,
170+ component . url ( "beta" , self , & self . triple ) ,
171+ component . url ( "stable" , self , & self . triple ) ,
164172 ] ;
165173 for url in & urls {
166174 log:: debug!( "requesting: {}" , url) ;
167175 let resp = reqwest:: blocking:: get ( url) ?;
168176 log:: debug!( "{}" , resp. status( ) ) ;
169177 if resp. status ( ) . is_success ( ) {
170178 let reader = XzDecoder :: new ( BufReader :: new ( resp) ) ;
171- match self . extract ( variant , reader) {
179+ match self . extract ( component , reader) {
172180 Ok ( ( ) ) => return Ok ( ( ) ) ,
173181 Err ( err) => {
174182 log:: warn!( "extracting {} failed: {:?}" , url, err) ;
@@ -181,17 +189,17 @@ impl SysrootDownload {
181189 "unable to download sha {} triple {} module {} from any of {:?}" ,
182190 self . rust_sha,
183191 self . triple,
184- variant ,
192+ component ,
185193 urls
186194 ) )
187195 }
188196
189- fn extract < T : Read > ( & self , variant : ModuleVariant , reader : T ) -> anyhow:: Result < ( ) > {
197+ fn extract < T : Read > ( & self , component : Component , reader : T ) -> anyhow:: Result < ( ) > {
190198 let mut archive = Archive :: new ( reader) ;
191- let prefix = if variant == ModuleVariant :: Std {
192- format ! ( "rust-std-{}" , self . triple)
193- } else {
194- variant . to_string ( )
199+ let prefix = match component {
200+ Component :: Std => format ! ( "rust-std-{}" , self . triple) ,
201+ Component :: Cranelift => format ! ( "{component}-preview" ) ,
202+ _ => component . to_string ( ) ,
195203 } ;
196204
197205 let unpack_into = self . directory . join ( & self . rust_sha ) ;
0 commit comments