The example, build.rs, is also able to be used as the build file for a cargo crate build.
102 lines
1.9 KiB
Rust
102 lines
1.9 KiB
Rust
#[macro_use]
|
|
extern crate scribe;
|
|
|
|
extern crate mason;
|
|
|
|
|
|
|
|
use std::env;
|
|
use std::path::PathBuf;
|
|
|
|
use mason::Processor;
|
|
|
|
|
|
|
|
pub const RESOURCES_DIR: &'static str = "resources";
|
|
pub const MANIFEST_FILENAME: &'static str = "resources.msnr";
|
|
|
|
|
|
|
|
pub fn main()
|
|
{
|
|
let task_count: u64;
|
|
let output_dir: PathBuf;
|
|
let mut resources_dir: PathBuf;
|
|
let mut processor: Processor;
|
|
|
|
// Get the cargo manifest directory and then append the
|
|
// resource directory name to it.
|
|
match option_env!("CARGO_MANIFEST_DIR")
|
|
{
|
|
Some(dir) =>
|
|
{
|
|
resources_dir = PathBuf::from(dir);
|
|
}
|
|
|
|
None =>
|
|
{
|
|
resources_dir = PathBuf::new();
|
|
}
|
|
}
|
|
resources_dir.push(RESOURCES_DIR);
|
|
|
|
// Get the output directory for the build.
|
|
match option_env!("OUT_DIR")
|
|
{
|
|
Some(dir) =>
|
|
{
|
|
output_dir = PathBuf::from(dir);
|
|
}
|
|
|
|
None =>
|
|
{
|
|
// Try to just get the current directory.
|
|
match env::current_dir()
|
|
{
|
|
Ok(dir) =>
|
|
{
|
|
output_dir = PathBuf::from(dir);
|
|
}
|
|
|
|
Err(error) =>
|
|
{
|
|
// Then just default to "".
|
|
warn!("{}", error);
|
|
output_dir = PathBuf::new();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Get how many compile tasks should be run at one time.
|
|
match option_env!("NUM_JOBS")
|
|
{
|
|
Some(count) =>
|
|
{
|
|
match count.parse::<u64>()
|
|
{
|
|
Ok(val) =>
|
|
{
|
|
task_count = val;
|
|
}
|
|
|
|
Err(error) =>
|
|
{
|
|
error!("{}", error);
|
|
}
|
|
}
|
|
}
|
|
|
|
None =>
|
|
{
|
|
task_count = 1u64;
|
|
}
|
|
}
|
|
|
|
processor = Processor::new();
|
|
processor.set_resources_dir(resources_dir.as_path());
|
|
processor.set_output_dir(output_dir.as_path());
|
|
processor.set_task_count(task_count);
|
|
processor.process_manifest_file();
|
|
}
|