From c437b388df948d67acd6b5f595f795bce6cf982c Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 12 Sep 2023 22:26:14 +0300 Subject: [PATCH] chore(cli): Use runtime SILE_PATH if set, then fall back to buildtime one --- src/lib.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b9c0477bc..673d458a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ use mlua::chunk; use mlua::prelude::*; -use std::path::PathBuf; +use std::{env, path::PathBuf}; #[cfg(feature = "cli")] pub mod cli; @@ -8,7 +8,11 @@ pub type Result = anyhow::Result; pub fn version() -> crate::Result { let lua = unsafe { Lua::unsafe_new() }; - let sile_path: LuaString = lua.create_string(env!("SILE_PATH"))?; + let sile_path = match env::var("SILE_PATH") { + Ok(val) => val, + Err(_) => env!("SILE_PATH").to_string(), + }; + let sile_path: LuaString = lua.create_string(&sile_path)?; let sile: LuaTable = lua .load(chunk! { local status = pcall(dofile, $sile_path .. "/core/pathsetup.lua") @@ -43,7 +47,11 @@ pub fn run( traceback: bool, ) -> crate::Result<()> { let lua = unsafe { Lua::unsafe_new() }; - let sile_path: LuaString = lua.create_string(env!("SILE_PATH"))?; + let sile_path = match env::var("SILE_PATH") { + Ok(val) => val, + Err(_) => env!("SILE_PATH").to_string(), + }; + let sile_path: LuaString = lua.create_string(&sile_path)?; let sile: LuaTable = lua .load(chunk! { local status = pcall(dofile, $sile_path .. "/core/pathsetup.lua")