Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
simple example of compiling rust
extern crate rustc;
extern crate syntax;
use rustc::driver::config::{basic_options, build_configuration};
use rustc::driver::session::{build_session};
use rustc::driver::driver::{StrInput, compile_input};
use syntax::diagnostics;
fn main() {
let src = "fn main() {println!(\"Awesome\");}";
let opts = basic_options();
let inp = StrInput(src.to_string());
let descriptions = diagnostics::registry::Registry::new(rustc::DIAGNOSTICS);
let sess = build_session(opts, None, descriptions);
let cfg = build_configuration(&sess);
compile_input(sess, cfg, &inp, &None, &None, None);
println!("Hello, world!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment