@@ -55,18 +55,29 @@ pub fn kani_playback_lib() -> PathBuf {
5555 path_buf ! ( kani_sysroot( ) , "playback/lib" )
5656}
5757
58+ /// Returns the path to where Kani libraries for no_core is kept.
59+ pub fn kani_no_core_lib ( ) -> PathBuf {
60+ path_buf ! ( kani_sysroot( ) , "no_core/lib" )
61+ }
62+
5863/// Returns the path to where Kani's pre-compiled binaries are stored.
5964fn kani_sysroot_bin ( ) -> PathBuf {
6065 path_buf ! ( kani_sysroot( ) , "bin" )
6166}
6267
68+ /// Returns the build target
69+ fn build_target ( ) -> & ' static str {
70+ env ! ( "TARGET" )
71+ }
72+
6373/// Build the `lib/` folder and `lib-playback/` for the new sysroot.
6474/// - The `lib/` folder contains the sysroot for verification.
6575/// - The `lib-playback/` folder contains the sysroot used for playback.
6676pub fn build_lib ( bin_folder : & Path ) -> Result < ( ) > {
6777 let compiler_path = bin_folder. join ( "kani-compiler" ) ;
6878 build_verification_lib ( & compiler_path) ?;
69- build_playback_lib ( & compiler_path)
79+ build_playback_lib ( & compiler_path) ?;
80+ build_no_core_lib ( & compiler_path)
7081}
7182
7283/// Build the `lib/` folder for the new sysroot used during verification.
@@ -75,34 +86,40 @@ fn build_verification_lib(compiler_path: &Path) -> Result<()> {
7586 let extra_args =
7687 [ "-Z" , "build-std=panic_abort,std,test" , "--config" , "profile.dev.panic=\" abort\" " ] ;
7788 let compiler_args = [ "--kani-compiler" , "-Cllvm-args=--ignore-global-asm --build-std" ] ;
78- build_kani_lib ( compiler_path, & kani_sysroot_lib ( ) , & extra_args, & compiler_args)
89+ let packages = [ "std" , "kani" , "kani_macros" ] ;
90+ let artifacts = build_kani_lib ( compiler_path, & packages, & extra_args, & compiler_args) ?;
91+ copy_artifacts ( & artifacts, & kani_sysroot_lib ( ) , true )
7992}
8093
8194/// Build the `lib-playback/` folder that will be used during counter example playback.
8295/// This will include Kani's libraries compiled with `concrete-playback` feature enabled.
8396fn build_playback_lib ( compiler_path : & Path ) -> Result < ( ) > {
8497 let extra_args =
8598 [ "--features=std/concrete_playback,kani/concrete_playback" , "-Z" , "build-std=std,test" ] ;
86- build_kani_lib ( compiler_path, & kani_playback_lib ( ) , & extra_args, & [ ] )
99+ let packages = [ "std" , "kani" , "kani_macros" ] ;
100+ let artifacts = build_kani_lib ( compiler_path, & packages, & extra_args, & [ ] ) ?;
101+ copy_artifacts ( & artifacts, & kani_playback_lib ( ) , true )
102+ }
103+
104+ /// Build the no core library folder that will be used during std verification.
105+ fn build_no_core_lib ( compiler_path : & Path ) -> Result < ( ) > {
106+ let extra_args = [ "--features=kani_macros/no_core" ] ;
107+ let packages = [ "kani_core" , "kani_macros" ] ;
108+ let artifacts = build_kani_lib ( compiler_path, & packages, & extra_args, & [ ] ) ?;
109+ copy_artifacts ( & artifacts, & kani_no_core_lib ( ) , false )
87110}
88111
89112fn build_kani_lib (
90113 compiler_path : & Path ,
91- output_path : & Path ,
114+ packages : & [ & str ] ,
92115 extra_cargo_args : & [ & str ] ,
93116 extra_rustc_args : & [ & str ] ,
94- ) -> Result < ( ) > {
117+ ) -> Result < Vec < Artifact > > {
95118 // Run cargo build with -Z build-std
96- let target = env ! ( "TARGET" ) ;
119+ let target = build_target ( ) ;
97120 let target_dir = env ! ( "KANI_BUILD_LIBS" ) ;
98121 let args = [
99122 "build" ,
100- "-p" ,
101- "std" ,
102- "-p" ,
103- "kani" ,
104- "-p" ,
105- "kani_macros" ,
106123 "-Z" ,
107124 "unstable-options" ,
108125 "--target-dir" ,
@@ -137,6 +154,7 @@ fn build_kani_lib(
137154 . env ( "CARGO_ENCODED_RUSTFLAGS" , rustc_args. join ( "\x1f " ) )
138155 . env ( "RUSTC" , compiler_path)
139156 . args ( args)
157+ . args ( packages. iter ( ) . copied ( ) . flat_map ( |pkg| [ "-p" , pkg] ) )
140158 . args ( extra_cargo_args)
141159 . stdout ( Stdio :: piped ( ) )
142160 . spawn ( )
@@ -152,20 +170,24 @@ fn build_kani_lib(
152170 }
153171
154172 // Create sysroot folder hierarchy.
155- copy_artifacts ( & artifacts, output_path , target )
173+ Ok ( artifacts)
156174}
157175
158176/// Copy all the artifacts to their correct place to generate a valid sysroot.
159- fn copy_artifacts ( artifacts : & [ Artifact ] , sysroot_lib : & Path , target : & str ) -> Result < ( ) > {
160- // Create sysroot folder hierarchy .
177+ fn copy_artifacts ( artifacts : & [ Artifact ] , sysroot_lib : & Path , copy_std : bool ) -> Result < ( ) > {
178+ // Create sysroot folder.
161179 sysroot_lib. exists ( ) . then ( || fs:: remove_dir_all ( sysroot_lib) ) ;
162- let std_path = path_buf ! ( & sysroot_lib, "rustlib" , target, "lib" ) ;
163- fs:: create_dir_all ( & std_path) . expect ( & format ! ( "Failed to create {std_path:?}" ) ) ;
180+ fs:: create_dir_all ( sysroot_lib) ?;
164181
165182 // Copy Kani libraries into sysroot top folder.
166183 copy_libs ( & artifacts, & sysroot_lib, & is_kani_lib) ;
184+
167185 // Copy standard libraries into rustlib/<target>/lib/ folder.
168- copy_libs ( & artifacts, & std_path, & is_std_lib) ;
186+ if copy_std {
187+ let std_path = path_buf ! ( & sysroot_lib, "rustlib" , build_target( ) , "lib" ) ;
188+ fs:: create_dir_all ( & std_path) . expect ( & format ! ( "Failed to create {std_path:?}" ) ) ;
189+ copy_libs ( & artifacts, & std_path, & is_std_lib) ;
190+ }
169191 Ok ( ( ) )
170192}
171193
0 commit comments