Allow preconfiguring WASMER_DIR at build time

This commit is contained in:
Julius Michaelis
2021-02-22 13:27:00 +09:00
parent 8041f03bc4
commit 80ec06ffab
4 changed files with 22 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ license = "MIT"
readme = "README.md" readme = "README.md"
edition = "2018" edition = "2018"
default-run = "wasmer" default-run = "wasmer"
build = "build.rs"
[[bin]] [[bin]]
name = "wasmer" name = "wasmer"

4
lib/cli/build.rs Normal file
View File

@@ -0,0 +1,4 @@
pub fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=WASMER_INSTALL_PREFIX");
}

View File

@@ -45,10 +45,16 @@ impl Config {
} }
fn inner_execute(&self) -> Result<()> { fn inner_execute(&self) -> Result<()> {
let key = "WASMER_DIR"; let key = "WASMER_DIR";
let wasmer_dir = env::var(key).context(format!( let wasmer_dir = env::var(key)
"failed to retrieve the {} environment variables", .or_else(|e| {
key option_env!("WASMER_INSTALL_PREFIX")
))?; .map(str::to_string)
.ok_or(e)
})
.context(format!(
"failed to retrieve the {} environment variables",
key
))?;
let prefix = PathBuf::from(wasmer_dir); let prefix = PathBuf::from(wasmer_dir);

View File

@@ -155,7 +155,13 @@ fn generate_header(header_file_src: &[u8]) -> anyhow::Result<()> {
fn get_wasmer_dir() -> anyhow::Result<PathBuf> { fn get_wasmer_dir() -> anyhow::Result<PathBuf> {
Ok(PathBuf::from( Ok(PathBuf::from(
env::var("WASMER_DIR").context("Trying to read env var `WASMER_DIR`")?, env::var("WASMER_DIR")
.or_else(|e| {
option_env!("WASMER_INSTALL_PREFIX")
.map(str::to_string)
.ok_or(e)
})
.context("Trying to read env var `WASMER_DIR`")?,
)) ))
} }