@@ -47,48 +47,9 @@ use rustc_hir::definitions::DefPathHash;
4747use rustc_interface:: Config ;
4848use rustc_session:: config:: ErrorOutputType ;
4949use session:: json_panic_hook;
50+ use std:: env;
5051use std:: ffi:: OsStr ;
51- use std:: path:: PathBuf ;
5252use std:: rc:: Rc ;
53- use std:: { env, fs} ;
54-
55- /// This function generates all rustc configurations required by our goto-c codegen.
56- fn rustc_gotoc_flags ( lib_path : & str ) -> Vec < String > {
57- // The option below provides a mechanism by which definitions in the
58- // standard library can be overriden. See
59- // https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/.E2.9C.94.20Globally.20override.20an.20std.20macro/near/268873354
60- // for more details.
61- let kani_std_rlib = PathBuf :: from ( lib_path) . join ( "libstd.rlib" ) ;
62- let kani_std_wrapper = format ! ( "noprelude:std={}" , kani_std_rlib. to_str( ) . unwrap( ) ) ;
63- let args = vec ! [
64- "-C" ,
65- "overflow-checks=on" ,
66- "-C" ,
67- "panic=abort" ,
68- "-Z" ,
69- "unstable-options" ,
70- "-Z" ,
71- "panic_abort_tests=yes" ,
72- "-Z" ,
73- "trim-diagnostic-paths=no" ,
74- "-Z" ,
75- "human_readable_cgu_names" ,
76- "-Z" ,
77- "always-encode-mir" ,
78- "--cfg=kani" ,
79- "-Z" ,
80- "crate-attr=feature(register_tool)" ,
81- "-Z" ,
82- "crate-attr=register_tool(kanitool)" ,
83- "-L" ,
84- lib_path,
85- "--extern" ,
86- "kani" ,
87- "--extern" ,
88- kani_std_wrapper. as_str( ) ,
89- ] ;
90- args. iter ( ) . map ( |s| s. to_string ( ) ) . collect ( )
91- }
9253
9354/// Main function. Configure arguments and run the compiler.
9455fn main ( ) -> Result < ( ) , & ' static str > {
@@ -152,35 +113,9 @@ impl Callbacks for KaniCallbacks {
152113 }
153114}
154115
155- /// The Kani root folder has all binaries inside bin/ and libraries inside lib/.
156- /// This folder can also be used as a rustc sysroot.
157- fn kani_root ( ) -> PathBuf {
158- match env:: current_exe ( ) {
159- Ok ( exe_path) => {
160- let mut path = fs:: canonicalize ( & exe_path) . unwrap_or ( exe_path) ;
161- // Current folder (bin/)
162- path. pop ( ) ;
163- // Top folder
164- path. pop ( ) ;
165- path
166- }
167- Err ( e) => panic ! ( "Failed to get current exe path: {e}" ) ,
168- }
169- }
170-
171116/// Generate the arguments to pass to rustc_driver.
172117fn generate_rustc_args ( args : & ArgMatches ) -> Vec < String > {
173118 let mut rustc_args = vec ! [ String :: from( "rustc" ) ] ;
174- if args. get_flag ( parser:: GOTO_C ) {
175- let mut default_path = kani_root ( ) ;
176- default_path. push ( "lib" ) ;
177- let gotoc_args = rustc_gotoc_flags (
178- args. get_one :: < String > ( parser:: KANI_LIB )
179- . unwrap_or ( & default_path. to_str ( ) . unwrap ( ) . to_string ( ) ) ,
180- ) ;
181- rustc_args. extend_from_slice ( & gotoc_args) ;
182- }
183-
184119 if args. get_flag ( parser:: RUSTC_VERSION ) {
185120 rustc_args. push ( String :: from ( "--version" ) )
186121 }
@@ -192,9 +127,6 @@ fn generate_rustc_args(args: &ArgMatches) -> Vec<String> {
192127 if let Some ( extra_flags) = args. get_raw ( parser:: RUSTC_OPTIONS ) {
193128 extra_flags. for_each ( |arg| rustc_args. push ( convert_arg ( arg) ) ) ;
194129 }
195- let sysroot = sysroot_path ( args) ;
196- rustc_args. push ( String :: from ( "--sysroot" ) ) ;
197- rustc_args. push ( convert_arg ( sysroot. as_os_str ( ) ) ) ;
198130 tracing:: debug!( ?rustc_args, "Compile" ) ;
199131 rustc_args
200132}
@@ -205,72 +137,6 @@ fn convert_arg(arg: &OsStr) -> String {
205137 arg. to_str ( ) . expect ( format ! ( "[Error] Cannot parse argument \" {arg:?}\" ." ) . as_str ( ) ) . to_string ( )
206138}
207139
208- /// Get the sysroot, for our specific version of Rust nightly.
209- ///
210- /// Rust normally finds its sysroot by looking at where itself (the `rustc`
211- /// executable) is located. This will fail for us because we're `kani-compiler`
212- /// and not located under the rust sysroot.
213- ///
214- /// We do know the actual name of the toolchain we need, however.
215- /// We look for our toolchain in the usual place for rustup.
216- ///
217- /// We previously used to pass `--sysroot` in `KANIFLAGS` from `kani-driver`,
218- /// but this failed to have effect when building a `build.rs` file.
219- /// This wasn't used anywhere but passing down here, so we've just migrated
220- /// the code to find the sysroot path directly into this function.
221- ///
222- /// This function will soon be removed.
223- #[ deprecated]
224- fn toolchain_sysroot_path ( ) -> PathBuf {
225- // If we're installed normally, we'll find `$KANI/toolchain` as a symlink to our desired toolchain
226- {
227- let kani_root = kani_root ( ) ;
228- let toolchain_path = kani_root. join ( "toolchain" ) ;
229- if toolchain_path. exists ( ) {
230- return toolchain_path;
231- }
232- }
233-
234- // rustup sets some environment variables during build, but this is not clearly documented.
235- // https://github.com/rust-lang/rustup/blob/master/src/toolchain.rs (search for RUSTUP_HOME)
236- // We're using RUSTUP_TOOLCHAIN here, which is going to be set by our `rust-toolchain.toml` file.
237- // This is a *compile-time* constant, not a dynamic lookup at runtime, so this is reliable.
238- let toolchain = env ! ( "RUSTUP_TOOLCHAIN" ) ;
239-
240- // We use the home crate to do a *runtime* determination of where rustup toolchains live
241- let rustup = home:: rustup_home ( ) . expect ( "Couldn't find RUSTUP_HOME" ) ;
242- let path = rustup. join ( "toolchains" ) . join ( toolchain) ;
243-
244- if !path. exists ( ) {
245- panic ! ( "Couldn't find Kani Rust toolchain {toolchain}. Tried: {}" , path. display( ) ) ;
246- }
247- path
248- }
249-
250- /// Get the sysroot relative to the binary location.
251- ///
252- /// Kani uses a custom sysroot. The `std` library and dependencies are compiled in debug mode and
253- /// include the entire MIR definitions needed by Kani.
254- ///
255- /// We do provide a `--sysroot` option that users may want to use instead.
256- #[ allow( deprecated) ]
257- fn sysroot_path ( args : & ArgMatches ) -> PathBuf {
258- let sysroot_arg = args. get_one :: < String > ( parser:: SYSROOT ) ;
259- let path = if let Some ( s) = sysroot_arg {
260- PathBuf :: from ( s)
261- } else if !args. get_flag ( parser:: GOTO_C ) {
262- toolchain_sysroot_path ( )
263- } else {
264- kani_root ( )
265- } ;
266-
267- if !path. exists ( ) {
268- panic ! ( "Couldn't find Kani Rust toolchain {:?}." , path. display( ) ) ;
269- }
270- tracing:: debug!( ?path, ?sysroot_arg, "Sysroot path." ) ;
271- path
272- }
273-
274140/// Find the stub mapping for the given harness.
275141///
276142/// This function is necessary because Kani currently allows a harness to be
0 commit comments