rust-lang / mdBook

Create book from markdown files. Like Gitbook but implemented in Rust
https://rust-lang.github.io/mdBook/
Mozilla Public License 2.0
17.75k stars 1.61k forks source link

How to run code snippets locally/offline? #1768

Closed micouy closed 2 years ago

micouy commented 2 years ago

Sometimes I get a timeout error when running Rust code. I'm currently preparing a Rust course with editable examples and I expect my students to re-run their code a lot. Is there a way to use the local installation of Rust to do it? I'd be willing to add a custom preprocessor and I'm open to hacky solutions.

ehuss commented 2 years ago

I don't think it is possible for a web page to launch executables on the local system without using an extension or something like that. Also, mdbook is currently hard-coded to only use play.rust-lang.org (#350).

I might recommend checking out something like evcxr for interactive evaluation of Rust. That still requires running jupyter locally, though.

I think no matter what approach you take, you'll either need the user to install something on their system, or hosting your own server that provides a playground-like experience.

micouy commented 2 years ago

Okay, thanks.

mgeisler commented 2 years ago

Is there a way to use the local installation of Rust to do it?

As @ehuss said, you cannot directly use a Rust installation.

However, you can run the Playground locally (or on a server you control): https://github.com/integer32llc/rust-playground#development. Then override the play.rust-lang.org URLs in book.js for your course. You get the book.js file by running mdbook init --theme.

mgeisler commented 2 years ago

@micouy Perhaps leave this feature request open since it isn't really resolved yet? Or do you consider it a duplicate of #350?