Giter Club home page Giter Club logo

rustbook's Introduction

Enzyme-Rust Book

This book is build using mdBook

It requires a working rustup installation. Install mdBook with

$ cargo install mdbook

Build and run this book afterwards locally with

$ mdbook serve --open

Running tests

This book contains many code fragments that are important to test.

Rust-Enzyme toolchain

We assume that you have a rustup toolchain called enzyme. This would have been created in your rust build directory by running something like:

$ rustup toolchain link enzyme $(pwd)/build/host/stage1

The above only needs to be run once. The enzyme toolchain will also need rustdoc support. Again, from the Rust build directory, you'll need to have run something like

$ x build --stage 1 library tools/rustdoc

This will need to be re-run each time you git pull.

Configuring an override

It's unlikely that you want enzyme as your default toolchain for all your rust activities. Instead, you probably use cargo +enzyme build when working with Rust-Enyzme. You can specify a directory override by running the following (once) in the Enzyme-rustbook directory:

$ rustup override set enzyme

Testing with Cargo

Code samples worth testing are being migrated to the samples crate. You can run all samples with a simple

$ cargo test

or, using cargo-nextest,

$ cargo nextest run

Testing with mdBook (deprecated)

Finally, you can run tests for all chapters using

$ mdbook test

or a specific chapter using that chapter's name, such as

$ mdbook test -c Usage

This testing mode is being phased out as we move testable code into the samples crate. When using this mode, you will need the following workaround:

mdBook and lto=fat (temporary workaround)

Rust's Enzyme support currently requires lto=fat, which is not part of the default profile for rustdoc (which is invoked by mdbook test). My temporary hack has been to patch mdbook by applying the following.

diff --git i/src/book/mod.rs w/src/book/mod.rs
index c0ab8a5..409482f 100644
--- i/src/book/mod.rs
+++ w/src/book/mod.rs
@@ -319,7 +319,11 @@ impl MDBook {
                 tmpf.write_all(ch.content.as_bytes())?;
 
                 let mut cmd = Command::new("rustdoc");
-                cmd.arg(&path).arg("--test").args(&library_args);
+                cmd.arg(&path)
+                    .arg("--test")
+                    .args(&library_args)
+                    .arg("-C")
+                    .arg("lto=fat");
 
                 if let Some(edition) = self.config.rust.edition {
                     match edition {

I'll find a better solution and make a pull request.

rustbook's People

Contributors

jedbrown avatar wsmoses avatar zusez4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

rustbook's Issues

Describe Compiler explorer usage

in src/Debugging.md

@wsmoses Do you have the flag at hand in the compiler explorer (opt-17) to analyze a specific function? I want to add it to the docs here and I couldn't find it in enzyme core docs. The flags from the test don't seem to have an effect in the explorer.
e.g. -passes="print-type-analysis" -type-analysis-func=asdf compiles fine even if asdf doesn't exist (and doesn't do anything if asdf exists either). I remember they were slightly different online, but I can't remember how.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.