emojos/build.rs

34 lines
896 B
Rust
Raw Normal View History

use std::fs::File;
use std::io;
use std::path::{Path, PathBuf};
use std::process::Command;
use zip::ZipWriter;
2023-04-06 20:31:05 -07:00
fn main() {
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
let output = Command::new("cargo")
.args(["package", "--list", "--allow-dirty"])
2023-04-06 20:31:05 -07:00
.output()
.unwrap();
if !output.status.success() {
panic!("cargo package failed");
}
2023-04-06 20:31:05 -07:00
let mut writer = ZipWriter::new(File::create(out_dir.join("source.zip")).unwrap());
for path in String::from_utf8(output.stdout).unwrap().lines() {
if path == "Cargo.toml.orig" {
continue;
}
2023-04-06 20:31:05 -07:00
writer.start_file(path, Default::default()).unwrap();
io::copy(
2023-04-06 20:31:05 -07:00
&mut File::open(Path::new(env!("CARGO_MANIFEST_DIR")).join(path)).unwrap(),
&mut writer,
2023-04-06 20:31:05 -07:00
)
.unwrap();
}
2023-04-06 20:31:05 -07:00
writer.finish().unwrap();
}