add filter-exports command to automatically remove unused exports

this removes the need for a manual step in the rust example
This commit is contained in:
2022-01-01 19:02:58 +01:00
parent 6a75988489
commit 26206a312a
8 changed files with 184 additions and 9 deletions

View File

@@ -19,16 +19,18 @@ fn main() -> Result<()> {
match args.subcommand()?.as_ref().map(|s| s.as_str()) {
Some("run") => run(args),
Some("pack") => pack(args),
Some(other) => {
eprintln!("Unknown command '{}'", other);
process::exit(1);
}
None => {
Some("filter-exports") => filter_exports(args),
Some("help") | None => {
println!("Usage:");
println!(" uw8 run [-w/--watch] [-p/--pack] [-u/--uncompressed] [-l/--level] [-o/--output <out-file>] <file>");
println!(" uw8 pack [-u/--uncompressed] [-l/--level] <in-file> <out-file>");
println!(" uw8 filter-exports <in-wasm> <out-wasm>");
Ok(())
}
Some(other) => {
eprintln!("Unknown command '{}'", other);
process::exit(1);
}
}
}
@@ -153,3 +155,12 @@ fn pack(mut args: Arguments) -> Result<()> {
Ok(())
}
fn filter_exports(mut args: Arguments) -> Result<()> {
let in_file = args.free_from_os_str::<PathBuf, bool>(|s| Ok(s.into()))?;
let out_file = args.free_from_os_str::<PathBuf, bool>(|s| Ok(s.into()))?;
uw8_tool::filter_exports(&in_file, &out_file)?;
Ok(())
}