18
18
19
19
use crate :: metadata:: { from_json, merge_kani_metadata, mock_proof_harness} ;
20
20
use crate :: session:: KaniSession ;
21
- use crate :: util:: { crate_name, guess_rlib_name } ;
21
+ use crate :: util:: crate_name;
22
22
use anyhow:: { Context , Result } ;
23
23
use kani_metadata:: {
24
24
artifact:: convert_type, ArtifactType , ArtifactType :: * , HarnessMetadata , KaniMetadata ,
@@ -270,8 +270,12 @@ pub fn cargo_project(session: &KaniSession, keep_going: bool) -> Result<Project>
270
270
}
271
271
272
272
/// Generate a project directly using `kani-compiler` on a single crate.
273
- pub fn standalone_project ( input : & Path , session : & KaniSession ) -> Result < Project > {
274
- StandaloneProjectBuilder :: try_new ( input, session) ?. build ( )
273
+ pub fn standalone_project (
274
+ input : & Path ,
275
+ crate_name : Option < String > ,
276
+ session : & KaniSession ,
277
+ ) -> Result < Project > {
278
+ StandaloneProjectBuilder :: try_new ( input, crate_name, session) ?. build ( )
275
279
}
276
280
277
281
/// Builder for a standalone project.
@@ -291,15 +295,15 @@ struct StandaloneProjectBuilder<'a> {
291
295
impl < ' a > StandaloneProjectBuilder < ' a > {
292
296
/// Create a `StandaloneProjectBuilder` from the given input and session.
293
297
/// This will perform a few validations before the build.
294
- fn try_new ( input : & Path , session : & ' a KaniSession ) -> Result < Self > {
298
+ fn try_new ( input : & Path , krate_name : Option < String > , session : & ' a KaniSession ) -> Result < Self > {
295
299
// Ensure the directory exist and it's in its canonical form.
296
300
let outdir = if let Some ( target_dir) = & session. args . target_dir {
297
301
std:: fs:: create_dir_all ( target_dir) ?; // This is a no-op if directory exists.
298
302
target_dir. canonicalize ( ) ?
299
303
} else {
300
304
input. canonicalize ( ) . unwrap ( ) . parent ( ) . unwrap ( ) . to_path_buf ( )
301
305
} ;
302
- let crate_name = crate_name ( & input) ;
306
+ let crate_name = if let Some ( name ) = krate_name { name } else { crate_name ( & input) } ;
303
307
let metadata = standalone_artifact ( & outdir, & crate_name, Metadata ) ;
304
308
Ok ( StandaloneProjectBuilder {
305
309
outdir,
@@ -313,7 +317,7 @@ impl<'a> StandaloneProjectBuilder<'a> {
313
317
/// Build a project by compiling `self.input` file.
314
318
fn build ( self ) -> Result < Project > {
315
319
// Register artifacts that may be generated by the compiler / linker for future deletion.
316
- let rlib_path = guess_rlib_name ( & self . outdir . join ( self . input . file_name ( ) . unwrap ( ) ) ) ;
320
+ let rlib_path = self . rlib_name ( ) ;
317
321
self . session . record_temporary_file ( & rlib_path) ;
318
322
self . session . record_temporary_file ( & self . metadata . path ) ;
319
323
@@ -339,6 +343,17 @@ impl<'a> StandaloneProjectBuilder<'a> {
339
343
}
340
344
result
341
345
}
346
+
347
+ /// Build the rlib name from the crate name.
348
+ /// This is only used by 'kani', never 'cargo-kani', so we hopefully don't have too many corner
349
+ /// cases to deal with.
350
+ fn rlib_name ( & self ) -> PathBuf {
351
+ let path = & self . outdir . join ( self . input . file_name ( ) . unwrap ( ) ) ;
352
+ let basedir = path. parent ( ) . unwrap_or ( Path :: new ( "." ) ) ;
353
+ let rlib_name = format ! ( "lib{}.rlib" , self . crate_name) ;
354
+
355
+ basedir. join ( rlib_name)
356
+ }
342
357
}
343
358
344
359
/// Generate a `KaniMetadata` by extending the original metadata to contain the function under
0 commit comments