@@ -5,29 +5,41 @@ use crate::utils::{
5
5
} ;
6
6
7
7
use std:: fs;
8
- use std:: path:: Path ;
8
+ use std:: path:: { Path , PathBuf } ;
9
9
10
10
fn prepare_libcore (
11
11
sysroot_path : & Path ,
12
12
libgccjit12_patches : bool ,
13
13
cross_compile : bool ,
14
+ sysroot_source : Option < String > ,
14
15
) -> Result < ( ) , String > {
15
- let rustc_path = match get_rustc_path ( ) {
16
- Some ( path) => path,
17
- None => return Err ( "`rustc` path not found" . to_string ( ) ) ,
18
- } ;
16
+ let rustlib_dir: PathBuf ;
19
17
20
- let parent = match rustc_path. parent ( ) {
21
- Some ( path) => path,
22
- None => return Err ( format ! ( "No parent for `{}`" , rustc_path. display( ) ) ) ,
23
- } ;
18
+ if let Some ( path) = sysroot_source {
19
+ rustlib_dir = Path :: new ( & path)
20
+ . canonicalize ( )
21
+ . map_err ( |error| format ! ( "Failed to canonicalize path: {:?}" , error) ) ?;
22
+ if !rustlib_dir. is_dir ( ) {
23
+ return Err ( format ! ( "Custom sysroot path {:?} not found" , rustlib_dir) ) ;
24
+ }
25
+ } else {
26
+ let rustc_path = match get_rustc_path ( ) {
27
+ Some ( path) => path,
28
+ None => return Err ( "`rustc` path not found" . to_string ( ) ) ,
29
+ } ;
30
+
31
+ let parent = match rustc_path. parent ( ) {
32
+ Some ( path) => path,
33
+ None => return Err ( format ! ( "No parent for `{}`" , rustc_path. display( ) ) ) ,
34
+ } ;
24
35
25
- let rustlib_dir = parent
26
- . join ( "../lib/rustlib/src/rust" )
27
- . canonicalize ( )
28
- . map_err ( |error| format ! ( "Failed to canonicalize path: {:?}" , error) ) ?;
29
- if !rustlib_dir. is_dir ( ) {
30
- return Err ( "Please install `rust-src` component" . to_string ( ) ) ;
36
+ rustlib_dir = parent
37
+ . join ( "../lib/rustlib/src/rust" )
38
+ . canonicalize ( )
39
+ . map_err ( |error| format ! ( "Failed to canonicalize path: {:?}" , error) ) ?;
40
+ if !rustlib_dir. is_dir ( ) {
41
+ return Err ( "Please install `rust-src` component" . to_string ( ) ) ;
42
+ }
31
43
}
32
44
33
45
let sysroot_dir = sysroot_path. join ( "sysroot_src" ) ;
@@ -151,27 +163,39 @@ struct PrepareArg {
151
163
cross_compile : bool ,
152
164
only_libcore : bool ,
153
165
libgccjit12_patches : bool ,
166
+ sysroot_source : Option < String > ,
154
167
}
155
168
156
169
impl PrepareArg {
157
170
fn new ( ) -> Result < Option < Self > , String > {
158
171
let mut only_libcore = false ;
159
172
let mut cross_compile = false ;
160
173
let mut libgccjit12_patches = false ;
174
+ let mut sysroot_source = None ;
161
175
162
- for arg in std:: env:: args ( ) . skip ( 2 ) {
176
+ let mut args = std:: env:: args ( ) . skip ( 2 ) ;
177
+ while let Some ( arg) = args. next ( ) {
163
178
match arg. as_str ( ) {
164
179
"--only-libcore" => only_libcore = true ,
165
180
"--cross" => cross_compile = true ,
166
181
"--libgccjit12-patches" => libgccjit12_patches = true ,
182
+ "--sysroot-source" => {
183
+ if let Some ( path) = args. next ( ) {
184
+ sysroot_source = Some ( path) ;
185
+ } else {
186
+ return Err (
187
+ "Expected a value after `--sysroot-source`, found nothing" . to_string ( )
188
+ ) ;
189
+ }
190
+ }
167
191
"--help" => {
168
192
Self :: usage ( ) ;
169
193
return Ok ( None ) ;
170
194
}
171
195
a => return Err ( format ! ( "Unknown argument `{a}`" ) ) ,
172
196
}
173
197
}
174
- Ok ( Some ( Self { cross_compile, only_libcore, libgccjit12_patches } ) )
198
+ Ok ( Some ( Self { cross_compile, only_libcore, libgccjit12_patches, sysroot_source } ) )
175
199
}
176
200
177
201
fn usage ( ) {
@@ -182,6 +206,7 @@ impl PrepareArg {
182
206
--only-libcore : Only setup libcore and don't clone other repositories
183
207
--cross : Apply the patches needed to do cross-compilation
184
208
--libgccjit12-patches : Apply patches needed for libgccjit12
209
+ --sysroot-source : Specify custom path for sysroot source
185
210
--help : Show this help"#
186
211
)
187
212
}
@@ -193,7 +218,12 @@ pub fn run() -> Result<(), String> {
193
218
None => return Ok ( ( ) ) ,
194
219
} ;
195
220
let sysroot_path = get_sysroot_dir ( ) ;
196
- prepare_libcore ( & sysroot_path, args. libgccjit12_patches , args. cross_compile ) ?;
221
+ prepare_libcore (
222
+ & sysroot_path,
223
+ args. libgccjit12_patches ,
224
+ args. cross_compile ,
225
+ args. sysroot_source ,
226
+ ) ?;
197
227
198
228
if !args. only_libcore {
199
229
cargo_install ( "hyperfine" ) ?;
0 commit comments