fail build if we can't build source.zip
This commit is contained in:
parent
0a3de049b4
commit
0005b3bd56
11
build.rs
11
build.rs
|
@ -1,20 +1,13 @@
|
|||
use anyhow::{ensure, Result};
|
||||
use std::fs::File;
|
||||
use std::io::{self, Write};
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use zip::ZipWriter;
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<()> {
|
||||
let out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
|
||||
let mut rs_file = File::create(out_dir.join("zip.rs")).unwrap();
|
||||
match attempt(&out_dir) {
|
||||
Ok(()) => writeln!(rs_file, r#"Some(include_bytes!("source.zip"))"#).unwrap(),
|
||||
Err(_) => writeln!(rs_file, "None").unwrap(),
|
||||
}
|
||||
}
|
||||
|
||||
fn attempt(out_dir: &Path) -> Result<()> {
|
||||
let output = Command::new("cargo")
|
||||
.args(["package", "--list", "--allow-dirty"])
|
||||
.output()?;
|
||||
|
|
|
@ -144,16 +144,17 @@ struct Code {
|
|||
}
|
||||
|
||||
#[get("/code")]
|
||||
fn code() -> Option<Code> {
|
||||
let zip = include!(concat!(env!("OUT_DIR"), "/zip.rs"))?;
|
||||
Some(Code {
|
||||
fn code() -> Code {
|
||||
let zip = include_bytes!(concat!(env!("OUT_DIR"), "/source.zip"));
|
||||
|
||||
Code {
|
||||
zip,
|
||||
content_type: ContentType::ZIP,
|
||||
disposition: Header::new(
|
||||
"content-disposition",
|
||||
r#"attachment; filename="emojos.in.zip""#,
|
||||
),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[get("/static/site.css")]
|
||||
|
|
Loading…
Reference in New Issue