From 175583e335db9de1fa9828bf2c3e61163411d8d4 Mon Sep 17 00:00:00 2001 From: edef Date: Thu, 26 Mar 2015 22:48:51 -0400 Subject: [PATCH] simplify build script --- Cargo.toml | 3 +++ build.rs | 46 ++-------------------------------------------- 2 files changed, 5 insertions(+), 44 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 541f85d..bd3d56f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,3 +3,6 @@ name = "lwkt" version = "0.0.1" authors = ["edef "] build = "build.rs" + +[build-dependencies] +gcc = "0.3.3" diff --git a/build.rs b/build.rs index e677080..366c091 100644 --- a/build.rs +++ b/build.rs @@ -1,47 +1,5 @@ -#![feature(old_io, old_path)] -use std::old_io::Command; -use std::old_io::fs::PathExtensions; -use std::old_io::fs; -use std::env; +extern crate gcc; fn main() { - let out_dir = env::var("OUT_DIR").unwrap(); - let mut objects = Vec::new(); - - let files = fs::readdir(&Path::new("src")).unwrap(); - let files = files.iter().filter(|p| p.is_file()); - - for file in files { - if let Some(filename) = file.filename_str() { - let filepath = format!("src/{}", filename); - let outpath; - - if let Some(basename) = eat_extension(filename, ".c") { - outpath = format!("{}/{}.o", out_dir, basename); - - Command::new("cc").args(&[&*filepath, "-c", "-fPIC", "-o"]) - .arg(outpath.clone()) - .status().unwrap(); - } - else { continue } - - objects.push(outpath); - } - } - - Command::new("ar").args(&["crus", "libcontext.a"]) - .args(&*objects) - .cwd(&Path::new(&out_dir)) - .status().unwrap(); - - println!("cargo:rustc-flags=-L {} -l context:static", out_dir); -} - -fn eat_extension<'a>(s: &'a str, ext: &str) -> Option<&'a str> { - if s.ends_with(ext) { - Some(&s[..s.len() - ext.len()]) - } - else { - None - } + gcc::compile_library("libcontext.a", &["src/platform.c"]); }