/
render.rs
44 lines (35 loc) · 1.08 KB
/
render.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::fs;
use std::path::PathBuf;
use anyhow::{anyhow, Context};
use argh::FromArgs;
const TEMPLATE: &str = include_str!("docker/Dockerfile");
/// Renders a Dockerfile at `docker/Docker.<target>`.
#[derive(Debug, FromArgs)]
struct Opts {
/// the target triple.
#[argh(option)]
target: String,
/// the OpenSSL install args.
#[argh(option)]
install_openssl_args: String,
}
fn main() -> anyhow::Result<()> {
let opts: Opts = argh::from_env();
let data = upon::value! {
target: &opts.target,
is_musl: &opts.target.contains("musl"),
install_openssl_args: opts.install_openssl_args,
};
let rendered = upon::Engine::new()
.compile(TEMPLATE)
.map_err(|err| anyhow!("{:?}", err))?
.render(data)?;
let path: PathBuf = ["docker", &format!("Dockerfile.{}", opts.target)]
.iter()
.collect();
fs::write(&path, &rendered)
.with_context(|| format!("failed to write to `{}`", path.display()))?;
eprintln!("Rendered `{}`\n", path.display());
println!("{}", rendered);
Ok(())
}