File tree Expand file tree Collapse file tree 12 files changed +173
-1
lines changed Expand file tree Collapse file tree 12 files changed +173
-1
lines changed Original file line number Diff line number Diff line change 26
26
matrix :
27
27
# Kani does not support windows.
28
28
os : [ubuntu-latest, macos-latest]
29
+ include :
30
+ - os : ubuntu-latest
31
+ base : ubuntu
32
+ - os : macos-latest
33
+ base : macos
29
34
steps :
30
35
- name : Checkout Library
31
36
uses : actions/checkout@v4
41
46
path : kani
42
47
ref : features/verify-rust-std
43
48
49
+ - name : Setup Dependencies
50
+ working-directory : kani
51
+ run : |
52
+ ./scripts/setup/${{ matrix.base }}/install_deps.sh
53
+
44
54
- name : Build `Kani`
45
55
working-directory : kani
46
56
run : |
52
62
env :
53
63
RUST_BACKTRACE : 1
54
64
run : |
55
- kani verify-std -Z unstable-options ./library --target-dir "target"
65
+ kani verify-std -Z unstable-options ./library --target-dir ${{ runner.temp }} -Z function-contracts \
66
+ -Z mem-predicates -Z ptr-to-ref-cast-checks
56
67
Original file line number Diff line number Diff line change 61
61
62
62
- name : Run tests
63
63
working-directory : upstream
64
+ env :
65
+ # Avoid error due to unexpected `cfg`.
66
+ RUSTFLAGS : " --check-cfg cfg(kani) --check-cfg cfg(feature,values(any()))"
64
67
run : |
65
68
./configure --set=llvm.download-ci-llvm=true
66
69
./x test --stage 0 library/std
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ Session.vim
26
26
* .rlib
27
27
* .rmeta
28
28
* .mir
29
+ Cargo.lock
29
30
30
31
# # Temporary files
31
32
* ~
Original file line number Diff line number Diff line change
1
+ # Copyright Kani Contributors
2
+ # SPDX-License-Identifier: Apache-2.0 OR MIT
3
+
4
+ [package ]
5
+ name = " safety"
6
+ version = " 0.1.0"
7
+ edition = " 2021"
8
+ license = " MIT OR Apache-2.0"
9
+
10
+ [lib ]
11
+ proc-macro = true
12
+
13
+ [dependencies ]
14
+ proc-macro2 = " 1.0"
15
+ proc-macro-error = " 1.0.4"
16
+ quote = " 1.0.20"
17
+ syn = { version = " 2.0.18" , features = [" full" ] }
Original file line number Diff line number Diff line change
1
+ fn main ( ) {
2
+ // We add the configurations here to be checked.
3
+ println ! ( "cargo:rustc-check-cfg=cfg(kani_host)" ) ;
4
+ }
Original file line number Diff line number Diff line change
1
+ use proc_macro:: { TokenStream } ;
2
+ use quote:: { quote, format_ident} ;
3
+ use syn:: { ItemFn , parse_macro_input} ;
4
+
5
+ pub ( crate ) fn requires ( attr : TokenStream , item : TokenStream ) -> TokenStream {
6
+ rewrite_attr ( attr, item, "requires" )
7
+ }
8
+
9
+ pub ( crate ) fn ensures ( attr : TokenStream , item : TokenStream ) -> TokenStream {
10
+ rewrite_attr ( attr, item, "ensures" )
11
+ }
12
+
13
+ fn rewrite_attr ( attr : TokenStream , item : TokenStream , name : & str ) -> TokenStream {
14
+ let args = proc_macro2:: TokenStream :: from ( attr) ;
15
+ let fn_item = parse_macro_input ! ( item as ItemFn ) ;
16
+ let attribute = format_ident ! ( "{}" , name) ;
17
+ quote ! (
18
+ #[ kani_core:: #attribute( #args) ]
19
+ #fn_item
20
+ ) . into ( )
21
+ }
Original file line number Diff line number Diff line change
1
+ //! Implement a few placeholders for contract attributes until they get implemented upstream.
2
+ //! Each tool should implement their own version in a separate module of this crate.
3
+
4
+ use proc_macro:: TokenStream ;
5
+ use proc_macro_error:: proc_macro_error;
6
+
7
+ #[ cfg( kani_host) ]
8
+ #[ path = "kani.rs" ]
9
+ mod tool;
10
+
11
+ #[ cfg( not( kani_host) ) ]
12
+ #[ path = "runtime.rs" ]
13
+ mod tool;
14
+
15
+ #[ proc_macro_error]
16
+ #[ proc_macro_attribute]
17
+ pub fn requires ( attr : TokenStream , item : TokenStream ) -> TokenStream {
18
+ tool:: requires ( attr, item)
19
+ }
20
+
21
+ #[ proc_macro_error]
22
+ #[ proc_macro_attribute]
23
+ pub fn ensures ( attr : TokenStream , item : TokenStream ) -> TokenStream {
24
+ tool:: ensures ( attr, item)
25
+ }
Original file line number Diff line number Diff line change
1
+ use proc_macro:: TokenStream ;
2
+
3
+ /// For now, runtime requires is a no-op.
4
+ ///
5
+ /// TODO: At runtime the `requires` should become an assert unsafe precondition.
6
+ pub ( crate ) fn requires ( _attr : TokenStream , item : TokenStream ) -> TokenStream {
7
+ item
8
+ }
9
+
10
+ /// For now, runtime requires is a no-op.
11
+ ///
12
+ /// TODO: At runtime the `ensures` should become an assert as well.
13
+ pub ( crate ) fn ensures ( _attr : TokenStream , item : TokenStream ) -> TokenStream {
14
+ item
15
+ }
Original file line number Diff line number Diff line change @@ -24,6 +24,9 @@ name = "corebenches"
24
24
path = " benches/lib.rs"
25
25
test = true
26
26
27
+ [dependencies ]
28
+ safety = {path = " ../contracts/safety" }
29
+
27
30
[dev-dependencies ]
28
31
rand = { version = " 0.8.5" , default-features = false }
29
32
rand_xorshift = { version = " 0.3.0" , default-features = false }
Original file line number Diff line number Diff line change @@ -431,6 +431,9 @@ mod unit;
431
431
#[ stable( feature = "core_primitive" , since = "1.43.0" ) ]
432
432
pub mod primitive;
433
433
434
+ #[ cfg( kani) ]
435
+ kani_core:: kani_lib!( core) ;
436
+
434
437
// Pull in the `core_arch` crate directly into core. The contents of
435
438
// `core_arch` are in a different repository: rust-lang/stdarch.
436
439
//
You can’t perform that action at this time.
0 commit comments