simplify build.rs

This commit is contained in:
Lzu Tao 2020-04-24 21:16:36 +07:00 committed by David Peter
parent 5fe8a8342b
commit 56111aa20d
2 changed files with 6 additions and 13 deletions

View File

@ -79,7 +79,6 @@ assert_cmd = "1.0.1"
[build-dependencies] [build-dependencies]
clap = { version = "2.33", optional = true } clap = { version = "2.33", optional = true }
liquid = { version = "0.20", optional = true } liquid = { version = "0.20", optional = true }
lazy_static = { version = "1.4", optional = true }
[profile.release] [profile.release]
lto = true lto = true

View File

@ -12,16 +12,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
use std::fs; use std::fs;
use std::path::Path; use std::path::Path;
use lazy_static::lazy_static;
static PROJECT_VERSION: &str = env!("CARGO_PKG_VERSION");
// Read environment variables. // Read environment variables.
lazy_static! { let project_name = option_env!("PROJECT_NAME").unwrap_or("bat");
static ref PROJECT_NAME: &'static str = option_env!("PROJECT_NAME").unwrap_or("bat"); let executable_name = option_env!("PROJECT_EXECUTABLE").unwrap_or(project_name);
static ref EXECUTABLE_NAME: &'static str = static PROJECT_VERSION: &str = env!("CARGO_PKG_VERSION");
option_env!("PROJECT_EXECUTABLE").unwrap_or(*PROJECT_NAME);
}
/// Generates a file from a liquid template. /// Generates a file from a liquid template.
fn template( fn template(
@ -38,9 +32,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
let variables = liquid::object!({ let variables = liquid::object!({
"PROJECT_NAME": PROJECT_NAME.to_owned(), "PROJECT_NAME": project_name,
"PROJECT_EXECUTABLE": EXECUTABLE_NAME.to_owned(), "PROJECT_EXECUTABLE": executable_name,
"PROJECT_VERSION": PROJECT_VERSION.to_owned(), "PROJECT_VERSION": PROJECT_VERSION,
}); });
let out_dir_env = std::env::var_os("OUT_DIR").expect("OUT_DIR to be set in build.rs"); let out_dir_env = std::env::var_os("OUT_DIR").expect("OUT_DIR to be set in build.rs");