O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building a compiler plugin via Cargo

To compile the previous example with Cargo, we'll just need to include the crate containing the compiler plugin in Cargo.toml and define it as a plugin. Cargo will handle the rest. Modifying the preceding example into a Cargo project, we get this directory structure:

We'll still need to tell Cargo about the plugin. The lib section of Cargo.toml would look as follows:

// compiler-plugin/Cargo.toml [lib] name="simplest_compiler_plugin" plugin=true 

After this change, building with Cargo works and we can see the plugin in glorious action:

Now that we are able to build a simple compiler plugin, let's try ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required