Skip to content

Instantly share code, notes, and snippets.

@jaredly
Created November 18, 2014 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredly/089b60e0649c4bda3cd9 to your computer and use it in GitHub Desktop.
Save jaredly/089b60e0649c4bda3cd9 to your computer and use it in GitHub Desktop.
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