Skip to content

meta-introspector/librustc

Repository files navigation

librustc

Universal dynamic rustc loader - no static linking required.

Features

  • Load librustc_driver-{hash}.so from any Rust version
  • Call rustc_driver_main to compile files
  • No static linking to rustc internals
  • Works in CLI tools, compiler plugins, servers
  • C FFI for GCC/LLVM plugins
  • Nix-friendly

Usage

Compile a file

use librustc::RustcHandle;

fn main() {
    let rustc = RustcHandle::load_from_env().unwrap();
    let result = rustc.compile_file("hello.rs").unwrap();
    println!("Compilation result: {}", result);
}

List symbols

let symbols = rustc.list_common_symbols();

Custom args

let result = rustc.compile(&["rustc", "file.rs", "--emit=mir"]).unwrap();

Environment

export RUSTC_DRIVER_SO=$(find $(rustc --print sysroot)/lib -name "librustc_driver-*.so")

Build

nix develop
cargo build
cargo run --example simple tests/test.rs
cargo run --example compile tests/test.rs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published