cognitive-engineering-lab / aquascope

Interactive visualizations of Rust at compile-time and run-time
https://cognitive-engineering-lab.github.io/aquascope/
MIT License
1.93k stars 44 forks source link

Aquascope Preprocessor Failure on mdbook Build #97

Open jpnws opened 1 year ago

jpnws commented 1 year ago

Hello 😄 I tried going through the steps to use aquascope, but I was getting an error.

❯ mdbook build
2023-07-27 06:12:15 [INFO] (mdbook::book): Book building has started
Aquascope failed for program:
fn main() {
let mut s = String::from("hello ");
s.push_str("world");
}
with error:

2023-07-27 06:12:15 [ERROR] (mdbook::utils): Error: The "aquascope" preprocessor exited unsuccessfully with exit code: 1 status

This is how I have my files set up:

image

Here are the initial steps I took to install Aquascope, in order as shown on README:

I attempted cargo install mdbook-aquascope, but it failed due to the Rust nightly requirement.

Following that, I executed the remaining steps, including rustup toolchain install nightly ..., cargo +nightly-2023-04-12 install --git ..., and cargo +nightly-2023-04-12 miri setup. I was then able to install mdbook-aquascope.

Next, I ran mdbook init, added rust-toolchain.toml to override the toolchain for the project, and appended [preprocessor.aquascope] to book.toml. I also added a sample Rust code snippet in chapter_1.md.

After these steps, mdbook build began to fail, displaying the error message I described earlier.

willcrichton commented 1 year ago

Well that's not a very helpful error message. Try this: can you make a new Cargo binary that contains the given main function, then run:

MIRI_SYSROOT=$(cargo +nightly-2023-04-12 miri setup --print-sysroot) \
  cargo +nightly-2023-04-12 aquascope interpreter

Does that work? It should print out:

{"Ok":{"steps":[{"stack":{"frames":[{"name":"main","body_span":{"start":0,"end":42,"filename":{"private":0}},"location":{"start":0,"end":9,"filename":{"private":0}},"locals":[]}]},"heap":{"locations":[]}},{"stack":{"frames":[{"name":"main","body_span":{"start":0,"end":42,"filename":{"private":0}},"location":{"start":14,"end":39,"filename":{"private":0}},"locals":[]}]},"heap":{"locations":[]}}],"result":{"type":"Success"}}}
jpnws commented 1 year ago

The issue happened on my home computer but couldn't try out your suggestion yet.

However, I did try reproduing the issue on my work computer.

Strangely, it seems to work fine even with the same installation steps.

My work computer is Windows 11 which the same as my home computer.

I'll circle back to you when I get to try out your suggestion.

It just occurred to me, there was one subtle difference in the installation steps.

First, here are the steps - numbered:

  1. cargo install mdbook-aquascope
  2. rustup toolchain install nightly-2023-04-12 -c rust-src rustc-dev llvm-tools-preview miri
  3. cargo +nightly-2023-04-12 install --git https://github.com/cognitive-engineering-lab/aquascope aquascope_front
  4. cargo +nightly-2023-04-12 miri setup

On my home computer, the steps were: 2 -> set default rust to nightly -> 3 -> 4 -> 1.

On my work computer, the steps were: 2 -> 3 -> 4 -> 1 -> set default rust to nightly.

Regardless of whether it may have had anything to do with the issue ..

.. it's just something that was different about the two that stood out.

jpnws commented 1 year ago

So, I was trying things out on my work computer.

I have this here:

image

With the following code (without the slashes "//"):

// ```aquascope,interpreter
struct Color(i32, i32, i32);
struct Point(i32, i32, i32);

fn main() {
    let black = Color(0, 0, 0);
    let origin = Point(0, 0, 0);
}
// ```

Is there a way to show the stack, heap, and permission diagrams?

willcrichton commented 1 year ago

The stack and heap diagrams should show given what you've written. Can you open the Javascript console and see if there's an error being reported?

jpnws commented 1 year ago

Looks like I'm seeing some TypeErrors.

image

willcrichton commented 1 year ago

Ah, it seems like there's a bug in the published version of mdbook-aquascope. Sorry about that. You can either:

  1. Try following the "From Source" instructions, or
  2. Wait a few days and we will publish a patch
jpnws commented 1 year ago

Awesome, thanks, I'll try the source.

jpnws commented 1 year ago

I was following the source, but had some issues on Windows.

So, tried it with WSL Ubuntu 22.04.

Cloned the repo, got to curling the install.sh script.

But faced an issue when running cargo make init-bindings.

uname@usys:~/projects/aquascope$ cargo make init-bindings
error: no such command: `make`

        Did you mean `add`?

        View all installed commands with `cargo --list`

Found out I needed to install cargo-make, so I tried:

cargo install --force cargo-make

But got the following error:

error: linker `cc` not found
  |
  = note: No such file or directory (os error 2)

Looks like I had to do:

sudo apt-get update
sudo apt-get install build-essential

Then, cargo-make installation worked, and in turn, cargo make init-bindings worked as well.

However, was getting an error with depot build.

So figured, maybe it was depot from https://depot.dev/docs/cli/installation.

So, I install it, and tried it again.

image

Not knowing what depot really is, but did find out that I would have to execute:

depot build .

but at which point I got:

uname@usys:~/projects/aquascope/frontend$ depot build .
Error: missing API token, please run `depot login`

I think I'm stuck here.

I'm thinking I'll have to get the API token from https:://depot.dev.

willcrichton commented 1 year ago

@jpnws can you try the updated "From Source" instructions on the home page?

Also Depot is referring to our JS build tool: https://github.com/cognitive-engineering-lab/depot/