Skip to content

Pass config from cargo-kani to kani-compiler#999

Merged
tedinski merged 3 commits intomodel-checking:mainfrom
tedinski:fixup-state
Apr 1, 2022
Merged

Pass config from cargo-kani to kani-compiler#999
tedinski merged 3 commits intomodel-checking:mainfrom
tedinski:fixup-state

Conversation

@tedinski
Copy link
Contributor

Description of changes:

This change is a bit of a mash-up of things I need to start making things releasable, mostly centering around how we find certain environment/config info in kani-compiler.

In roughly github diff display order you will see:

  1. Addition of the home crate to compute RUSTUP_HOME the same way rustup does.
  2. The addition of passing --sysroot and --kani-lib arguments to kani-compiler from cargo-kani
  3. (To keep things accurate, this required switching that function to accumulating a list of OsString now, instead of String, now that' we're including Paths.)
  4. A smattering of clippy warnings that I fixed.
  5. Fixing how we construct a lot of PathBufs to get cleaner code.
  6. The addition of a new RPATH for kani-compiler, corresponding to where it should search for the rustc libraries in a release bundle. (Basically: next to bin/kani-compiler will be a symlink toolchain to the rustup-installed toolchain we require. Hence, ../toolchain/lib)
  7. I removed the /deps path being provided to the linker with -L. This was how it used to work, but this directory didn't exist anymore.
  8. SYSROOT accidentally didn't take an argument!

Call-outs:

  1. There is no clean way currently to figure out where the kani libraries are being built, so I'm unfortunately not passing that down in development builds. The path is currently something like /home/ubuntu/rmc/target/debug/build/kani-compiler-b8c35844f7600bbf/out/lib and I wish we could change that outdir to something more predicable, so we could make this unconditional, but I couldn't figure out how.
  2. Since we aren't yet using the RPATH for a release build, I manually verified that the executable ends up with the correct config:
RUNPATH              /home/ubuntu/.rustup/toolchains/nightly-2022-03-09-x86_64-unknown-linux-gnu/lib:$ORIGIN/../toolchain/lib

Testing:

  • How is this change tested? existing suite

  • Is this a refactor change? not quite

Checklist

  • Each commit message has a non-empty body, explaining why the change was made
  • Methods or procedures are documented
  • Regression or unit tests are included, or existing tests cover the modified code
  • My PR is restricted to a single feature or bugfix

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@tedinski tedinski requested a review from a team as a code owner March 30, 2022 22:11
Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, but I think we should be able to just use relative paths everywhere. When we run cargo build, cargo will put all workspace artifacts in the same directory, doesn't it? So for dev builds you should be able to use executable directory.

I think we are building the libraries twice right now, which isn't ideal.


// rustup also seems to set some environment variables, but this is not clearly documented.
// https://github.com/rust-lang/rustup/blob/master/src/toolchain.rs (search for RUSTUP_HOME)
// We make use of RUSTUP_TOOLCHAIN in this crate, to avoid needing to otherwise repeat this information
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment seems a bit out of place. Can you please move that to where you implement this logic?

pub fn rust_toolchain(&self) -> Result<PathBuf> {
// This is a compile-time constant, not a dynamic lookup at runtime,
// so we get the toolchain we're built with (i.e. that from rust_toolchain.toml)
let toolchain = env!("RUSTUP_TOOLCHAIN");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a tricky one, eh? We should be careful with custom toolchain override and users setting up this variable in the first place. That said, as long as we automate our releases to not do that, we should be OK.

.arg(
Arg::with_name(SYSROOT)
.long("--sysroot")
.takes_value(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops. :)

@tedinski
Copy link
Contributor Author

It looks good, but I think we should be able to just use relative paths everywhere. When we run cargo build, cargo will put all workspace artifacts in the same directory, doesn't it? So for dev builds you should be able to use executable directory.

I think we are building the libraries twice right now, which isn't ideal.

Are you just talking about --kani-lib? (I think I forgot to write this up as part of the callout, oops)

I agree it's not ideal. I avoided changing anything in this PR because I wasn't sure what to do. The issue with using the regular build directory is that it has a lot of other stuff in the directory (other dependencies, etc), whereas using the lib outputs we currently use we end up with just the 3 files only: the 2 rlib and the 1 so. (kani, std, and kani_macros, respectively.)

If we use the regular output directory I was slightly worried we might end up with those other dependencies mattering, somehow. On the other hand, this only matters for development builds, since release will distribute only the relevant 3 files. If you think it's probably fine, I'll switch over to doing that.

@tedinski
Copy link
Contributor Author

Ah, actually the bigger problem is that they aren't built with --cfg=kani and so don't behave correctly when we build them "normally"

@celinval
Copy link
Contributor

Ah, actually the bigger problem is that they aren't built with --cfg=kani and so don't behave correctly when we build them "normally"

What about adding a cargo config file that passes --cfg=kani to the build? That said, I'm OK doing that in a separate PR.

Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am OK to push further improvements to a separate PR. Can you please move the comment out of src/cargo-kani/build.rs before pushing the change though?

@tedinski tedinski merged commit dfe6481 into model-checking:main Apr 1, 2022
@tedinski tedinski deleted the fixup-state branch April 1, 2022 18:14
tedinski added a commit to tedinski/rmc that referenced this pull request Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants