Inkwell(s)
It's a New Kind of Wrapper for Exposing LLVM (Safely)
Inkwell aims to help you pen your own programming languages by safely wrapping llvm-sys. It provides a more strongly typed interface than the underlying LLVM C API so that certain types of errors can be caught at compile time instead of at LLVM's runtime. This means we are trying to replicate LLVM IR's strong typing as closely as possible. The ultimate goal is to make LLVM safer from the rust end and a bit easier to learn (via documentation) and use.
Requirements
- Rust 1.56+ (Stable, Beta, or Nightly)
- LLVM 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, or 15.0
Usage
You'll need to point your Cargo.toml to an existing preview crate on crates.io or the master branch with a corresponding LLVM feature flag:
[]
= { = "llvm-plugin-inkwell", = "0.2", = ["llvm12-0"] }
Supported versions:
| LLVM Version | Cargo Feature Flag |
|---|---|
| 4.0.x | llvm4-0 |
| 5.0.x | llvm5-0 |
| 6.0.x | llvm6-0 |
| 7.0.x | llvm7-0 |
| 8.0.x | llvm8-0 |
| 9.0.x | llvm9-0 |
| 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 |
| 15.0.x | llvm15-0 |
Please be aware that we may make breaking changes on master from time to time since we are pre-v1.0.0, in compliance with semver. Please prefer a crates.io release whenever possible!
Examples
Tari's llvm-sys example written in safe code1 with Inkwell:
use OptimizationLevel;
use Builder;
use Context;
use ;
use Module;
use Error;
/// Convenience type alias for the `sum` function.
///
/// Calling this is innately `unsafe` because there's no guarantee it doesn't
/// do `unsafe` operations internally.
type SumFunc = unsafe extern "C" fn ;
1 There are two uses of unsafe in this example because the actual
act of compiling and executing code on the fly is innately unsafe. For one,
there is no way of verifying we are calling get_function() with the right function
signature. It is also unsafe to call the function we get because there's no
guarantee the code itself doesn't do unsafe things internally (the same reason
you need unsafe when calling into C).
LLVM's Kaleidoscope Tutorial
Can be found in the examples directory.
Alternative Crate(s)
Contributing
Check out our Contributing Guide