Skip to content

Conversation

@apoelstra
Copy link
Contributor

@apoelstra apoelstra commented Oct 15, 2018

I found that with the existing instructions I would get errors along the lines of "libstd not found", or "dependency was built against possibly newer libstd", and it was very difficult to tell what was going on because there are many moving parts and actually multiple things that can go wrong.

Update the README to hold the user's hand more and give troubleshooting help.

@apoelstra apoelstra force-pushed the 2018-10-readme branch 2 times, most recently from 0c83b2f to 8259670 Compare October 15, 2018 18:53
README.md Outdated
project through Miri.
Compile your project and its dependencies against a MIR-enabled libstd as described
above. The easiest way to do this is to copy `xargo/build.sh` and `xargo/Xargo.toml`
into your own project's root, and to re-run `build.sh`. This ensures that `libstd`
Copy link
Member

Choose a reason for hiding this comment

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

I am a bit surprised by this. build.sh installs the new libstd globally, so you can use MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri even without copying it. If you are using the same compiler, this locally built libstd should be compatible with the one shipped with rustc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah! If you run cargo clean first you are correct. But cargo will use cached dependency compilations even if you change MIRI_SYSROOT. (Maybe this is a bug in cargo?)

Copy link
Member

Choose a reason for hiding this comment

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

I don't see how your instructions can make any difference there. If you used xargo build later, that would take the new libstd into account, but cargo build for sure doesn't care about ~/.xargo/HOST.

Something doesn't add up here.

Copy link
Member

Choose a reason for hiding this comment

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

I think there are actually some bugs here, and I opened #486 to track that.

But none of that should require a copy of Xargo.toml, and I have yet to see a situation where that helps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my project (rust-bitcoin), if I run

cargo clean
MIRI_SYSROOT=~/.xargo/HOST cargo +nightly-2018-10-14 build
MIRI_SYSROOT=~/.xargo/HOST cargo +nightly-2018-10-14 miri  ## does not error, seems to do nothing
MIRI_SYSROOT=~/.xargo/HOST cargo +nightly-2018-10-14 miri test

I will reliably get the error

error[E0460]: found possibly newer version of crate `std` which `bitcoin_bech32` depends on                                                                                                                                                                                               

My fix was to bring Xargo.toml into the crate root and run the commands in build.sh there. But now I see that a more straightforward thing to do is to just run cargo clean before MIRI_SYSROOT=~/.xargo/HOST cargo miri test and it'll work.

This definitely seems like some sort of bug rather than something we should update the README for.

Copy link
Member

Choose a reason for hiding this comment

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

I think the following requirements are important to get cargo miri to work with a local libstd:

  • xargo/build.sh must be executed with the same toolchain as cargo miri.
  • MIRI_SYSROOT must be set when the project is built.

Can you write the instructions in a way that makes that as clear as possible?

README.md Outdated

1. Install Miri using `rustup run nightly-2018-10-15 cargo install --all-features --path .`,
with the date replaced as appropriate.
2. Edit `build.sh` to replace `xargo` with `rustup run nightly-2018-10-15 xargo`.
Copy link
Member

Choose a reason for hiding this comment

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

Instead, I think we can tell people to run rustup run nightly-2018-10-15 xargo/build.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, nice, I'll fix this.

@apoelstra apoelstra force-pushed the 2018-10-readme branch 2 times, most recently from 0241f1b to bcf4476 Compare October 16, 2018 18:04
README.md Outdated

1. Install Miri using `cargo +nightly-2018-10-15 install --all-features --path .`,
with the date replaced as appropriate.
2. Run `build.sh` as `rustup run nightly-2018-10-15 build.sh`.
Copy link
Member

Choose a reason for hiding this comment

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

Should be xargo/build.sh, shouldn't it?

@apoelstra
Copy link
Contributor Author

Rebased, addressed nits, and replaced the "copy build.sh" instructions with the much simpler "Run cargo clean before building your project".

README.md Outdated
1. Run `cargo clean` to eliminate any cached dependencies that were built against
the non-MIR `libstd`.
2. For a binary project, run `MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri` to
build and run your project; for a binary or library, use `MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri test`
Copy link
Member

Choose a reason for hiding this comment

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

I'd rearrange the sentence a bit here: The prat after the semicolon I'd start with what this is good for ("to run all tests"). Reading this I wondered "wait the first part is for a binary, the second part is for a binary or library, that's odd".

README.md Outdated

If you forget to set `MIRI_SYSROOT`, be sure to run `cargo clean` again before
correcting it. Otherwise you are likely to get "dependency was built against possibly
newer std" errors.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a remark here saying if this throws strange errors about crate mismatches, probably the xargo sysroot was built with a different nightly than the current project and one should run rustup run nightly xargo/build.sh.

README.md Outdated

You may prefer to do this rather than depending on the rustup default toolchain,
if you routinely update the default, since **it is essential that `xargo/build.sh`
is run with the same toolchain as `cargo miri`.**
Copy link
Member

Choose a reason for hiding this comment

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

I find this somewhat redundant. If we make the original instructions specify a toolchain everywhere, it seems clear that we can replace nightly by another toolchain name, doesn't it? It may be worth stating that explicitly, but I am not a fan of repeating instructions.

@apoelstra apoelstra force-pushed the 2018-10-readme branch 2 times, most recently from 8f8d65a to e22edfb Compare October 20, 2018 16:31
rust-toolchain Outdated
@@ -1 +0,0 @@
nightly-2018-10-14
Copy link
Member

Choose a reason for hiding this comment

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

Could you instead just replace it with nightly so that people don't have to switch to nightly manually, while at the same time not pinning to a specific nightly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They will still have to switch to nightly manually when doing the other steps; this override only controls compilation of Miri. This will be especially confusing if they have their default compiler set to a specific nightly, which is common for people using unstable compiler tools.

README.md Outdated
To target a specific nightly, modify the above instructions as follows.
To target a specific nightly, modify the above instructions as follows. It is recommended
to use the nightly specified in the `rust-version` file in this repo, since that is the
most recent nightly supported by Miri.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I should bold this? It's pretty far down. Or maybe I should move it to the top of the README?

Copy link
Member

Choose a reason for hiding this comment

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

I would get rid of this entire section, and instead write "Building Miri" and the following sections in a way that explicitly specifies nightly in every step (we have to, with rust-toolchain gone!). Then I think we can avoid repeating these instructions here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good.

@RalfJung
Copy link
Member

Most of the README, starting at "Building Miri", now needs to be adjusted to add the +nightly. It should also explain that if that doesn't work, one can find a toolchain that does work in the rust-version file.

README.md Outdated

### Common Problems

When modifying the above instructions, you may encounter a number of confusing compiler
Copy link
Member

Choose a reason for hiding this comment

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

Why "modifying"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was trying to politely say "you typed the instructions wrong".

Copy link
Member

Choose a reason for hiding this comment

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

lol, that subtlety was lost on me.^^ Maybe just say "When using" or "when working with"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heh, yeah, I guess that's even more polite :)

have `MIRI_SYSROOT` set. Run `cargo clean` before switching from non-Miri to Miri
builds and vice-versa.

#### "found crate `std` compiled by an incompatible version of rustc"
Copy link
Member

Choose a reason for hiding this comment

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

I do not understand how/why this is different from the one right before. Seems to me both are caused by "sysroot confusion", and both are solved the same way. Why should we give different advise for these two?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand. They have different causes and different solutions.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, the difference is "deps were built without MIRI_SYSROOT vs MIRI_SYSROOT was built with the wrong toolchain, I see. Makes sense.

I think what threw me off was specifically mentioning cargo miri test. The same applies to cargo miri, right? So maybe just say cargo miri then.

README.md Outdated

Install Miri as a cargo subcommand with `cargo install --all-features`, and install
a full libstd as described above.
Install Miri as a cargo subcommand with `cargo install --all-features --path .`.
Copy link
Member

Choose a reason for hiding this comment

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

This and everything above it in the README still lacks a +nightly. The instructions as they are now just don't work.

@apoelstra
Copy link
Contributor Author

Rebased; added a commit which

  1. deletes the "installing Miri with a specific nightly" instructions and instead uses +nightly throughout
  2. replaces cargo miri test with cargo miri in the troubleshooting cases where the distinction doesn't matter

@RalfJung
Copy link
Member

I like it. :) Still have some tweaks I want to do but I will just make a PR of my own then and ask you for feedback.

Cycling PR because the Travis state is stuck.

@RalfJung RalfJung closed this Oct 24, 2018
@RalfJung RalfJung reopened this Oct 24, 2018
@RalfJung RalfJung merged commit 1cbed5c into rust-lang:master Oct 24, 2018
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.

3 participants