@@ -55,18 +55,29 @@ pub fn kani_playback_lib() -> PathBuf {
55
55
path_buf ! ( kani_sysroot( ) , "playback/lib" )
56
56
}
57
57
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
+
58
63
/// Returns the path to where Kani's pre-compiled binaries are stored.
59
64
fn kani_sysroot_bin ( ) -> PathBuf {
60
65
path_buf ! ( kani_sysroot( ) , "bin" )
61
66
}
62
67
68
+ /// Returns the build target
69
+ fn build_target ( ) -> & ' static str {
70
+ env ! ( "TARGET" )
71
+ }
72
+
63
73
/// Build the `lib/` folder and `lib-playback/` for the new sysroot.
64
74
/// - The `lib/` folder contains the sysroot for verification.
65
75
/// - The `lib-playback/` folder contains the sysroot used for playback.
66
76
pub fn build_lib ( bin_folder : & Path ) -> Result < ( ) > {
67
77
let compiler_path = bin_folder. join ( "kani-compiler" ) ;
68
78
build_verification_lib ( & compiler_path) ?;
69
- build_playback_lib ( & compiler_path)
79
+ build_playback_lib ( & compiler_path) ?;
80
+ build_no_core_lib ( & compiler_path)
70
81
}
71
82
72
83
/// Build the `lib/` folder for the new sysroot used during verification.
@@ -75,34 +86,40 @@ fn build_verification_lib(compiler_path: &Path) -> Result<()> {
75
86
let extra_args =
76
87
[ "-Z" , "build-std=panic_abort,std,test" , "--config" , "profile.dev.panic=\" abort\" " ] ;
77
88
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 )
79
92
}
80
93
81
94
/// Build the `lib-playback/` folder that will be used during counter example playback.
82
95
/// This will include Kani's libraries compiled with `concrete-playback` feature enabled.
83
96
fn build_playback_lib ( compiler_path : & Path ) -> Result < ( ) > {
84
97
let extra_args =
85
98
[ "--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 )
87
110
}
88
111
89
112
fn build_kani_lib (
90
113
compiler_path : & Path ,
91
- output_path : & Path ,
114
+ packages : & [ & str ] ,
92
115
extra_cargo_args : & [ & str ] ,
93
116
extra_rustc_args : & [ & str ] ,
94
- ) -> Result < ( ) > {
117
+ ) -> Result < Vec < Artifact > > {
95
118
// Run cargo build with -Z build-std
96
- let target = env ! ( "TARGET" ) ;
119
+ let target = build_target ( ) ;
97
120
let target_dir = env ! ( "KANI_BUILD_LIBS" ) ;
98
121
let args = [
99
122
"build" ,
100
- "-p" ,
101
- "std" ,
102
- "-p" ,
103
- "kani" ,
104
- "-p" ,
105
- "kani_macros" ,
106
123
"-Z" ,
107
124
"unstable-options" ,
108
125
"--target-dir" ,
@@ -137,6 +154,7 @@ fn build_kani_lib(
137
154
. env ( "CARGO_ENCODED_RUSTFLAGS" , rustc_args. join ( "\x1f " ) )
138
155
. env ( "RUSTC" , compiler_path)
139
156
. args ( args)
157
+ . args ( packages. iter ( ) . copied ( ) . flat_map ( |pkg| [ "-p" , pkg] ) )
140
158
. args ( extra_cargo_args)
141
159
. stdout ( Stdio :: piped ( ) )
142
160
. spawn ( )
@@ -152,20 +170,24 @@ fn build_kani_lib(
152
170
}
153
171
154
172
// Create sysroot folder hierarchy.
155
- copy_artifacts ( & artifacts, output_path , target )
173
+ Ok ( artifacts)
156
174
}
157
175
158
176
/// 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.
161
179
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) ?;
164
181
165
182
// Copy Kani libraries into sysroot top folder.
166
183
copy_libs ( & artifacts, & sysroot_lib, & is_kani_lib) ;
184
+
167
185
// 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
+ }
169
191
Ok ( ( ) )
170
192
}
171
193
0 commit comments