Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
llvm-plugin-rs
This crate gives the ability to safely implement passes for the new LLVM pass manager, by leveraging the strongly typed interface provided by Inkwell.
If you have never developed LLVM passes before, perhaps you should take a look at this LLVM guide before carrying on. It will give you a simple overview of the C++ API wrapped by this crate.
If you want a deeper understanding of the many concepts surrounding the new LLVM pass manager, you should read the official LLVM documentation.
Usage
Out-of-tree LLVM passes are plugins implemented as dynamically-linked libraries loaded by the opt tool. Therefore,
you must add the following line in your Cargo.toml
:
[]
= ["cdylib"]
When importing this crate in your Cargo.toml
, you will need to specify the LLVM version to use with a corresponding feature flag:
[]
= { = "0.1", = ["llvm10-0"] }
Supported versions:
LLVM Version | Cargo Feature Flag | Linux | Windows | MacOS |
---|---|---|---|---|
10.0.x | llvm10-0 | ✓ | ✗ | ✓ |
11.0.x | llvm11-0 | ✓ | ✓ | ✓ |
12.0.x | llvm12-0 | ✓ | ✓ | ✓ |
13.0.x | llvm13-0 | ✓ | ✓ | ✓ |
14.0.x | llvm14-0 | ✓ | ✓ | ✓ |
Example
A simple LLVM plugin which defines two passes, one being a transformation pass that queries the result of a second pass, an analysis one:
// Define an LLVM plugin (a name and a version is required). Only cdylib crates
// should define plugins, and only one definition should be done per crate.
Once you compiled your custom plugin, you can use it during the compilation of C/C++ with the opt
tool:
To learn more about how to sequentially apply more than one pass, read this opt guide.
Linux & MacOS Requirements
Your LLVM toolchain should dynamically link the LLVM library. Fortunately, this is the case for toolchains
distributed on apt
and homebrew
registeries.
If you are not in this case, you have to compile LLVM from sources by specifying the LLVM_LINK_LLVM_DYLIB=ON
cmake flag.
Windows Requirements
You have to compile LLVM from sources in any case, because you need to apply some patches to the LLVM
code base before compiling. Then, you need to specify the LLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON
cmake flag
while leaving the LLVM_TARGETS_TO_BUILD
flag to its default value.
Here are the detailed steps (replace llvm-XX
with the one matching your LLVM version):
| &&
Make sure you updated your $PATH
environment variable with <YOUR_INSTALL_PATH>/bin