@@ -5,7 +5,7 @@ extern crate cargo_metadata;
5
5
use std:: path:: { PathBuf , Path } ;
6
6
use std:: io:: { self , Write } ;
7
7
use std:: process:: Command ;
8
-
8
+ use std :: fs :: { self , File } ;
9
9
10
10
const CARGO_MIRI_HELP : & str = r#"Interprets bin crates
11
11
@@ -133,6 +133,59 @@ fn setup(ask_user: bool) {
133
133
show_error ( format ! ( "Failed to install xargo" ) ) ;
134
134
}
135
135
}
136
+
137
+ // Then, we also need rust-src. Let's see if it is already installed.
138
+ let sysroot = Command :: new ( "rustc" ) . args ( & [ "--print" , "sysroot" ] ) . output ( ) . unwrap ( ) . stdout ;
139
+ let sysroot = std:: str:: from_utf8 ( & sysroot[ ..] ) . unwrap ( ) ;
140
+ let src = Path :: new ( sysroot. trim_end_matches ( '\n' ) ) . join ( "lib/rustlib/src" ) ;
141
+ if !src. exists ( ) {
142
+ println ! ( "Could not find {:?}" , src) ;
143
+ if ask_user {
144
+ ask ( "It seems you do not have the rust-src component installed. I will run `rustup component add rust-src`. Proceed?" ) ;
145
+ }
146
+ if !Command :: new ( "rustup" ) . args ( & [ "component" , "add" , "rust-src" ] ) . status ( ) . unwrap ( ) . success ( ) {
147
+ show_error ( format ! ( "Failed to install rust-src component" ) ) ;
148
+ }
149
+ }
150
+
151
+ // Next, we need our own libstd. We will do this work in ~/.miri.
152
+ let dir = dirs:: home_dir ( ) . unwrap ( ) . join ( ".miri" ) ;
153
+ if !dir. exists ( ) {
154
+ fs:: create_dir ( & dir) . unwrap ( ) ;
155
+ }
156
+ // The interesting bit: Xargo.toml
157
+ File :: create ( dir. join ( "Xargo.toml" ) ) . unwrap ( )
158
+ . write_all ( br#"
159
+ [dependencies.std]
160
+ features = ["panic_unwind", "backtrace"]
161
+
162
+ [dependencies.test]
163
+ stage = 1
164
+ "# ) . unwrap ( ) ;
165
+ // The boring bits: A dummy project for xargo
166
+ File :: create ( dir. join ( "Cargo.toml" ) ) . unwrap ( )
167
+ . write_all ( br#"
168
+ [package]
169
+ name = "miri-xargo"
170
+ description = "A dummy project for building libstd with xargo."
171
+ version = "0.0.0"
172
+
173
+ [lib]
174
+ path = "lib.rs"
175
+ "# ) . unwrap ( ) ;
176
+ File :: create ( dir. join ( "lib.rs" ) ) . unwrap ( ) ;
177
+ // Run xargo
178
+ if !Command :: new ( "xargo" ) . arg ( "build" )
179
+ . current_dir ( & dir)
180
+ . env ( "RUSTFLAGS" , miri:: miri_default_args ( ) . join ( " " ) )
181
+ . env ( "XARGO_HOME" , dir. to_str ( ) . unwrap ( ) )
182
+ . status ( ) . unwrap ( ) . success ( )
183
+ {
184
+ show_error ( format ! ( "Failed to run xargo" ) ) ;
185
+ }
186
+
187
+ // That should be it!
188
+ std:: env:: set_var ( "MIRI_SYSROOT" , dir. join ( "HOST" ) ) ;
136
189
}
137
190
138
191
fn main ( ) {
0 commit comments