Skip to content

Commit f3e57d0

Browse files
authored
Merge pull request #22 from os-checker/test-ci
Feat: incorporate kani submodule and make CI work
2 parents 9607675 + 1218369 commit f3e57d0

File tree

16 files changed

+1193
-1126
lines changed

16 files changed

+1193
-1126
lines changed

.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[env]
2+
KANI_DIR = "./kani/target/kani"

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@ on:
44
push:
55
branches:
66

7+
env:
8+
CARGO_TERM_COLOR: always
9+
710
jobs:
811
test:
912
runs-on: ubuntu-latest
1013
steps:
1114
- uses: actions/checkout@v4
15+
with:
16+
submodules: 'recursive'
17+
18+
- name: Install kani
19+
working-directory: kani
20+
run: |
21+
./scripts/setup/ubuntu/install_deps.sh
22+
cargo build-dev
23+
echo PATH=$(pwd)/scripts:$PATH >> $GITHUB_ENV
24+
25+
- name: Check kani folder
26+
run: kani --version
1227

1328
- name: Run tests
1429
run: cargo test -- --nocapture

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "kani"]
2+
path = kani
3+
url = https://github.com/model-checking/kani.git

kani

Submodule kani added at bfa2a98

rust-toolchain.toml

Lines changed: 0 additions & 6 deletions
This file was deleted.

rust-toolchain.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kani/rust-toolchain.toml

src/functions/mod.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Function {
7575
let attrs = KANI_TOOL_ATTRS.iter().flat_map(|v| inst_def.tool_attrs(v)).collect();
7676

7777
let span = inst_def.span();
78-
let file = span.get_filename();
78+
let file = file_path(&inst);
7979

8080
let fn_def = ty_to_fndef(inst.ty())?;
8181
let body = fn_def.body()?;
@@ -127,8 +127,8 @@ fn source_code_of_body(inst: &Instance, tcx: TyCtxt, src_map: &SourceMap) -> Opt
127127
}
128128

129129
fn cmp_callees(a: &Instance, b: &Instance, tcx: TyCtxt, src_map: &SourceMap) -> Ordering {
130-
let filename_a = a.def.span().get_filename();
131-
let filename_b = b.def.span().get_filename();
130+
let filename_a = file_path(a);
131+
let filename_b = file_path(b);
132132
match filename_a.cmp(&filename_b) {
133133
Ordering::Equal => (),
134134
ord => return ord,
@@ -138,3 +138,24 @@ fn cmp_callees(a: &Instance, b: &Instance, tcx: TyCtxt, src_map: &SourceMap) ->
138138
let body_b = source_code_of_body(b, tcx, src_map);
139139
body_a.cmp(&body_b)
140140
}
141+
142+
fn file_path(inst: &Instance) -> String {
143+
use std::sync::LazyLock;
144+
static PREFIXES: LazyLock<[String; 2]> = LazyLock::new(|| {
145+
let mut pwd = std::env::current_dir().unwrap().into_os_string().into_string().unwrap();
146+
pwd.push('/');
147+
148+
let out = std::process::Command::new("rustc").arg("--print=sysroot").output().unwrap();
149+
let sysroot = std::str::from_utf8(&out.stdout).unwrap().trim();
150+
let sysroot = format!("{sysroot}/lib/rustlib/src/rust/");
151+
[pwd, sysroot]
152+
});
153+
154+
let file = inst.def.span().get_filename();
155+
for prefix in &*PREFIXES {
156+
if let Some(file) = file.strip_prefix(prefix) {
157+
return file.to_owned();
158+
}
159+
}
160+
file
161+
}

src/functions/serialization.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl Callee {
7575
fn new(inst: &Instance, tcx: TyCtxt, src_map: &SourceMap) -> Self {
7676
let inst_def = &inst.def;
7777
let def_id = format_def_id(&inst_def.def_id());
78-
let file = inst_def.span().get_filename();
78+
let file = super::file_path(inst);
7979
let func = super::source_code_of_body(inst, tcx, src_map).unwrap_or_default();
8080
Callee { def_id, file, func }
8181
}

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,23 @@ pub struct Callee {
2424
pub file: String,
2525
pub func: String,
2626
}
27+
28+
/// A local path to kani's artifacts.
29+
///
30+
/// Choose the following if found
31+
/// * `$KANI_DIR`
32+
/// * or `$KANI_HOME/kani-{version}`
33+
/// * or `$HOME/.kani/kani-{version}`
34+
pub fn kani_path() -> String {
35+
use std::env::var;
36+
let path = if let Ok(path) = var("KANI_DIR") {
37+
path
38+
} else {
39+
let kani = std::process::Command::new("kani").arg("--version").output().unwrap();
40+
let kani_folder = std::str::from_utf8(&kani.stdout).unwrap().trim().replace(' ', "-");
41+
let home = var("KANI_HOME").or_else(|_| var("HOME")).unwrap();
42+
format!("{home}/.kani/{kani_folder}")
43+
};
44+
assert!(std::fs::exists(&path).unwrap());
45+
path
46+
}

src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extern crate rustc_span;
1010
extern crate rustc_stable_hash;
1111
extern crate stable_mir;
1212

13+
use distributed_verification::kani_path;
1314
// FIXME: this is a bug for rustc_smir, because rustc_interface is used by
1415
// run_with_tcx! without being imported inside.
1516
use rustc_smir::rustc_internal;
@@ -24,6 +25,8 @@ extern crate tracing;
2425
fn main() {
2526
logger::init();
2627
let cli = cli::parse();
28+
let kani_path = kani_path();
29+
info!(kani_path);
2730
let mut args = Vec::from(
2831
[
2932
// the first argument to rustc is unimportant
@@ -33,13 +36,13 @@ fn main() {
3336
"-Zcrate-attr=feature(register_tool)",
3437
"-Zcrate-attr=register_tool(kanitool)",
3538
"--sysroot",
36-
"/home/zjp/rust/kani/target/kani",
39+
&kani_path,
3740
"-L",
38-
"/home/zjp/rust/kani/target/kani/lib",
41+
&format!("{kani_path}/lib"),
3942
"--extern",
4043
"kani",
4144
"--extern",
42-
"noprelude:std=/home/zjp/rust/kani/target/kani/lib/libstd.rlib",
45+
&format!("noprelude:std={kani_path}/lib/libstd.rlib"),
4346
"-Zunstable-options",
4447
"-Zalways-encode-mir",
4548
"-Zmir-enable-passes=-RemoveStorageMarkers",

0 commit comments

Comments
 (0)