@@ -20,7 +20,11 @@ pub struct Sysroot {
20
20
}
21
21
22
22
impl 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 > {
24
28
let unpack_into = "cache" ;
25
29
26
30
fs:: create_dir_all ( unpack_into) ?;
@@ -31,10 +35,13 @@ impl Sysroot {
31
35
triple : triple. to_owned ( ) ,
32
36
} ;
33
37
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
+ }
38
45
39
46
let sysroot = download. into_sysroot ( ) ?;
40
47
@@ -70,29 +77,30 @@ struct SysrootDownload {
70
77
71
78
const BASE_URL : & str = "https://ci-artifacts.rust-lang.org/rustc-builds" ;
72
79
73
- // FIXME(eddyb) rename to just `Component`.
74
80
#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
75
- enum ModuleVariant {
81
+ enum Component {
76
82
Cargo ,
77
83
Rustc ,
78
84
Std ,
79
85
RustSrc ,
86
+ Cranelift ,
80
87
}
81
88
82
- impl fmt:: Display for ModuleVariant {
89
+ impl fmt:: Display for Component {
83
90
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
84
91
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" ) ,
89
97
}
90
98
}
91
99
}
92
100
93
- impl ModuleVariant {
101
+ impl Component {
94
102
fn url ( & self , channel : & str , sysroot : & SysrootDownload , triple : & str ) -> String {
95
- let suffix = if * self == ModuleVariant :: RustSrc {
103
+ let suffix = if * self == Component :: RustSrc {
96
104
String :: new ( )
97
105
} else {
98
106
format ! ( "-{}" , triple)
@@ -137,15 +145,15 @@ impl SysrootDownload {
137
145
} )
138
146
}
139
147
140
- fn get_and_extract ( & self , variant : ModuleVariant ) -> anyhow:: Result < ( ) > {
148
+ fn get_and_extract ( & self , component : Component ) -> anyhow:: Result < ( ) > {
141
149
let archive_path = self . directory . join ( format ! (
142
150
"{}-{}-{}.tar.xz" ,
143
- self . rust_sha, self . triple, variant ,
151
+ self . rust_sha, self . triple, component ,
144
152
) ) ;
145
153
if archive_path. exists ( ) {
146
154
let reader = BufReader :: new ( File :: open ( & archive_path) ?) ;
147
155
let decompress = XzDecoder :: new ( reader) ;
148
- let extract = self . extract ( variant , decompress) ;
156
+ let extract = self . extract ( component , decompress) ;
149
157
match extract {
150
158
Ok ( ( ) ) => return Ok ( ( ) ) ,
151
159
Err ( err) => {
@@ -158,17 +166,17 @@ impl SysrootDownload {
158
166
// We usually have nightlies but we want to avoid breaking down if we
159
167
// accidentally end up with a beta or stable commit.
160
168
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 ) ,
164
172
] ;
165
173
for url in & urls {
166
174
log:: debug!( "requesting: {}" , url) ;
167
175
let resp = reqwest:: blocking:: get ( url) ?;
168
176
log:: debug!( "{}" , resp. status( ) ) ;
169
177
if resp. status ( ) . is_success ( ) {
170
178
let reader = XzDecoder :: new ( BufReader :: new ( resp) ) ;
171
- match self . extract ( variant , reader) {
179
+ match self . extract ( component , reader) {
172
180
Ok ( ( ) ) => return Ok ( ( ) ) ,
173
181
Err ( err) => {
174
182
log:: warn!( "extracting {} failed: {:?}" , url, err) ;
@@ -181,17 +189,17 @@ impl SysrootDownload {
181
189
"unable to download sha {} triple {} module {} from any of {:?}" ,
182
190
self . rust_sha,
183
191
self . triple,
184
- variant ,
192
+ component ,
185
193
urls
186
194
) )
187
195
}
188
196
189
- fn extract < T : Read > ( & self , variant : ModuleVariant , reader : T ) -> anyhow:: Result < ( ) > {
197
+ fn extract < T : Read > ( & self , component : Component , reader : T ) -> anyhow:: Result < ( ) > {
190
198
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 ( ) ,
195
203
} ;
196
204
197
205
let unpack_into = self . directory . join ( & self . rust_sha ) ;
0 commit comments