-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Advise on using Kani for non-cargo projects #3046
Comments
Hi @rodionov, you should be able to use standalone Kani to do that, even though we don't currently support that use case. To compile the dependencies, you can set RUSTFLAGS env variables with the flags you pass to rustc and invoke Kani with the following flags: |
@celinval has kindly provided me with more detailed steps to follow for this case, and I've put together an example to demonstrate them. In the example we consider two separate Rust files defined as: target.rs extern crate dependency;
#[kani::proof]
fn main() {
let x = dependency::add(1, 2);
assert_eq!(x, 3);
} dependency.rs pub fn add(left: usize, right: usize) -> usize {
left + right
} First, you need to compile each dependency with standalone Kani (i.e., Then, you need to call standalone Kani again on the main file, passing the
Please let us know if these instructions don't work for you for any reason. I might add them to our documentation later in the week in case they're useful to other people 😄 |
Many thanks, @celinval and @adpaco-aws for the prompt responses! This perfectly answers my original question! While trying these instruction above I'm running into other issues related to The project I'm attempting to verify is built using a custom Thank you! |
Hey Rodinov, I suspect this is won't be possible. The reason is that Kani is itself basically rustc. Now the way it actually works is that rustc compiles to a shared library The other option would be to use an older version of Kani that is compatible with the rustc that your custom compiler is forked off of. You would want to use such an older version even when building from source, because the rustc internal interfaces that Kani uses change all the time and so a modern Kani would likely need adjustment to compile against your rustc version. |
Many thanks, @JustusAdam! Understood! I guess with all the help in this thread I consider my original question answered :) Thanks a lot! |
BTW, if the occurrences of these features are sporadic, you can write conditional code using the |
@celinval @adpaco-aws while trying to follow solution described above (run kani directly on crates) I run into some problems due to dependencies. It seems that kani driver determines the value of Here is a small example reproducing the issue. Assuming we are in /tmp/a/src/lib.rs:
/tmp/b/src/lib.rs:
/tmp/c/src/lib.rs:
Running the following commands shows the problem with finding crate
Renaming the source file names fixes the issue (e.g. a/src/lib.rs -> a/src/a.rs). Thus, this hinting that the value of @celinval @adpaco-aws what do you think? Or could this be some other problem? Many thanks! |
Hi @rodionov, yes, this is something that we could address on our side. We could add |
I've drafted #3054 but I'm seeing this error when following the same steps:
I'd like to try a few more things, but this may indicate that adding the |
Hello,
Is there any guidance on how to perform verification of a Rust project with Kani which is built without using Cargo? In other words, there is no
Cargo.toml
file, bothrustc
& linker are directly invoked via Makefile where dependencies are provided via--extern
argument torustc
.Thank you!
The text was updated successfully, but these errors were encountered: