6 releases
new 0.1.5 | Dec 19, 2024 |
---|---|
0.1.4 | Dec 18, 2024 |
0.1.1 | Jun 22, 2023 |
#109 in Build Utils
383 downloads per month
110KB
2.5K
SLoC
Whole Program LLVM in Rust (rllvm)
rllvm
is a Rust port of gllvm
and provides compiler wrappers to build whole-program LLVM bitcode files for projects with source codes.
For more details, please refer to gllvm
or wllvm
.
Installation
cargo install rllvm
Get Started
# Compile the source file. `--` is needed. Arguments after it will be
# passed to the wrapped compiler
rllvm-cxx -- -o hello tests/data/hello.cc
# Extract the bitcode file `hello.bc`
rllvm-get-bc hello
# Obtain readable `hello.ll` file
llvm-dis hello.bc
Configuration
Users can specify the configuration file by setting the environment variable RLLVM_CONFIG
.
export RLLVM_CONFIG=/absolute/path/to/config/file.toml
Otherwise, the default configuration file ~/.rllvm/config.toml
will be used. The configuration file will be automatically created, if it does not exist, with the following entries:
Configuration Key | Required? | Notes |
---|---|---|
llvm_config_filepath |
Yes | The absolute filepath of llvm-config |
clang_filepath |
Yes | The absolute filepath of clang |
clangxx_filepath |
Yes | The absolute filepath of clang++ |
llvm_ar_filepath |
Yes | The absolute filepath of llvm-ar |
llvm_link_filepath |
Yes | The absolute filepath of llvm-link |
llvm_objcopy_filepath |
Yes | The absolute filepath of llvm-objcopy |
bitcode_store_path |
No | The absolute path of the directory that stores intermediate bitcode files |
llvm_link_flags |
No | Extra user-provided linking flags for llvm-link |
lto_ldflags |
No | Extra user-provided linking flags for link time optimization |
bitcode_generation_flags |
No | Extra user-provided flags for bitcode generation, e.g., "-flto -fwhole-program-vtables" |
is_configure_only |
No | The configure only mode, which skips the bitcode generation (Default: false) |
log_level |
No | Log level (0: nothing, 1: error, 2: warn, 3: info, 4: debug, 5: trace) |
Here is an example of the configuration file:
llvm_config_filepath = '/usr/local/Cellar/llvm/16.0.4/bin/llvm-config'
clang_filepath = '/usr/local/Cellar/llvm/16.0.4/bin/clang'
clangxx_filepath = '/usr/local/Cellar/llvm/16.0.4/bin/clang++'
llvm_ar_filepath = '/usr/local/Cellar/llvm/16.0.4/bin/llvm-ar'
llvm_link_filepath = '/usr/local/Cellar/llvm/16.0.4/bin/llvm-link'
llvm_objcopy_filepath = '/usr/local/Cellar/llvm/16.0.4/bin/llvm-objcopy'
bitcode_store_path = '/tmp/bitcode_store'
log_level = 3
Furthermore, we can override configurations by providing extra arguments before --
.
Currently, we only support override the compiler path and the log level, which is useful to sepcify relative paths while working with Bazel.
# Override the wrapped compiler path and show all logs
rllvm-cxx -c /path/to/compiler -vvvvv -- -o hello tests/data/hello.cc
Dependencies
~6–17MB
~239K SLoC