-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
preprocess default corpus and embed in binary
though this does increase binary size by ~40MB
- Loading branch information
1 parent
2536493
commit 18ae02a
Showing
5 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#[allow(dead_code)] | ||
mod corpus { | ||
include!("src/corpus.rs"); | ||
} | ||
|
||
fn main() { | ||
// load default corpus | ||
let default = corpus::load_corpus("cpu_rec_corpus/*.corpus").unwrap(); | ||
println!("cargo:rerun-if-changed=cpu_rec_corpus"); | ||
|
||
// serialize to bytes | ||
let bytes = postcard::to_stdvec(&default).unwrap(); | ||
|
||
// output path to target build folder | ||
let mut outfile = std::path::PathBuf::from(std::env::var("OUT_DIR").unwrap()); | ||
outfile.push("default.pc"); | ||
|
||
// write to file | ||
std::fs::write(outfile, bytes).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,7 +202,7 @@ fn main() -> Result<()> { | |
.propagate_version(true) | ||
.author("Raphaël Rigo <[email protected]>") | ||
.about("Identifies CPU architectures in binaries") | ||
.arg(arg!(--corpus <corpus_dir>).default_value("cpu_rec_corpus")) | ||
.arg(arg!(--corpus <corpus_dir>)) | ||
.arg(arg!(-d - -debug)) | ||
.arg(arg!(-v - -verbose)) | ||
.arg( | ||
|
@@ -223,17 +223,30 @@ fn main() -> Result<()> { | |
}; | ||
simple_logger::init_with_level(level)?; | ||
|
||
let corpus_dir = args.get_one::<String>("corpus").unwrap().to_owned(); | ||
if !Path::new(&corpus_dir).is_dir() { | ||
return Err(Error::msg(format!( | ||
"{} is not a valid directory", | ||
corpus_dir | ||
))); | ||
} | ||
let corpus_files: String = args.get_one::<String>("corpus").unwrap().to_owned() + "/*.corpus"; | ||
println!("Loading corpus from {}", corpus_files); | ||
let default_corpus: Vec<CorpusStats> = { | ||
// serialized bytes embedded from build.rs | ||
let bytes = include_bytes!(concat!(env!("OUT_DIR"), "/default.pc")); | ||
|
||
// deserialize | ||
postcard::from_bytes(bytes).unwrap() | ||
}; | ||
|
||
let corpus_stats = load_corpus(&corpus_files)?; | ||
let corpus_stats = match args.get_one::<&str>("corpus") { | ||
// if no arg given, use embedded corpus | ||
None => default_corpus, | ||
// attempt to load the given corpus folder | ||
Some(corpus_dir) => { | ||
if !Path::new(corpus_dir).is_dir() { | ||
return Err(Error::msg(format!( | ||
"{} is not a valid directory", | ||
corpus_dir | ||
))); | ||
} | ||
let corpus_files = format!("{corpus_dir}/*.corpus"); | ||
println!("Loading corpus from {}", corpus_files); | ||
load_corpus(&corpus_files)? | ||
} | ||
}; | ||
|
||
info!("Corpus size: {}", corpus_stats.len()); | ||
|
||
|