diff --git a/crates/lune-std/src/library.rs b/crates/lune-std/src/library.rs index dfede4f..9a301f5 100644 --- a/crates/lune-std/src/library.rs +++ b/crates/lune-std/src/library.rs @@ -71,7 +71,7 @@ impl LuneStandardLibrary { #[rustfmt::skip] #[allow(unreachable_patterns)] pub fn module<'lua>(&self, lua: &'lua Lua) -> LuaResult> { - let res = match self { + let res: LuaResult = match self { #[cfg(feature = "datetime")] Self::DateTime => lune_std_datetime::module(lua), #[cfg(feature = "fs")] Self::Fs => lune_std_fs::module(lua), #[cfg(feature = "luau")] Self::Luau => lune_std_luau::module(lua), diff --git a/crates/lune/Cargo.toml b/crates/lune/Cargo.toml index d268832..177d1a6 100644 --- a/crates/lune/Cargo.toml +++ b/crates/lune/Cargo.toml @@ -45,7 +45,6 @@ std = [ ] cli = [ - "dep:anyhow", "dep:env_logger", "dep:clap", "dep:include_dir", @@ -60,6 +59,7 @@ workspace = true mlua = { version = "0.9.7", features = ["luau"] } mlua-luau-scheduler = "0.0.1" +anyhow = "1.0" console = "0.15" dialoguer = "0.11" directories = "5.0" @@ -82,7 +82,6 @@ lune-utils = { version = "0.1.0", path = "../lune-utils" } ### CLI -anyhow = { optional = true, version = "1.0" } env_logger = { optional = true, version = "0.11" } clap = { optional = true, version = "4.1", features = ["derive"] } include_dir = { optional = true, version = "0.7", features = ["glob"] } diff --git a/crates/lune/src/cli/build/target.rs b/crates/lune/src/cli/build/target.rs index 7ed9dd1..b7a3218 100644 --- a/crates/lune/src/cli/build/target.rs +++ b/crates/lune/src/cli/build/target.rs @@ -3,14 +3,14 @@ use std::{env::consts::ARCH, fmt, path::PathBuf, str::FromStr}; use directories::BaseDirs; use once_cell::sync::Lazy; -const HOME_DIR: Lazy = Lazy::new(|| { +static HOME_DIR: Lazy = Lazy::new(|| { BaseDirs::new() .expect("could not find home directory") .home_dir() .to_path_buf() }); -pub const CACHE_DIR: Lazy = Lazy::new(|| HOME_DIR.join(".lune").join("target")); +pub static CACHE_DIR: Lazy = Lazy::new(|| HOME_DIR.join(".lune").join("target")); /** A target operating system supported by Lune diff --git a/crates/lune/src/main.rs b/crates/lune/src/main.rs index cc8f20c..5d04a63 100644 --- a/crates/lune/src/main.rs +++ b/crates/lune/src/main.rs @@ -1,21 +1,11 @@ -#![deny(clippy::all)] -#![warn(clippy::cargo, clippy::pedantic)] -#![allow( - clippy::cargo_common_metadata, - clippy::match_bool, - clippy::module_name_repetitions, - clippy::multiple_crate_versions, - clippy::needless_pass_by_value, - clippy::declare_interior_mutable_const, - clippy::borrow_interior_mutable_const -)] +#![allow(clippy::cargo_common_metadata)] use std::process::ExitCode; +#[cfg(feature = "cli")] pub(crate) mod cli; -pub(crate) mod standalone; -use cli::Cli; +pub(crate) mod standalone; use lune_utils::fmt::Label; @@ -33,11 +23,20 @@ async fn main() -> ExitCode { return standalone::run(bin).await.unwrap(); } - match Cli::new().run().await { - Ok(code) => code, - Err(err) => { - eprintln!("{}\n{err:?}", Label::Error); - ExitCode::FAILURE + #[cfg(feature = "cli")] + { + match cli::Cli::new().run().await { + Ok(code) => code, + Err(err) => { + eprintln!("{}\n{err:?}", Label::Error); + ExitCode::FAILURE + } } } + + #[cfg(not(feature = "cli"))] + { + eprintln!("{}\nCLI feature is disabled", Label::Error); + ExitCode::FAILURE + } } diff --git a/crates/lune/src/rt/runtime.rs b/crates/lune/src/rt/runtime.rs index 61b64dd..a5501c6 100644 --- a/crates/lune/src/rt/runtime.rs +++ b/crates/lune/src/rt/runtime.rs @@ -12,8 +12,6 @@ use std::{ use mlua::Lua; use mlua_luau_scheduler::Scheduler; -use lune_std::inject_globals; - use super::{RuntimeError, RuntimeResult}; #[derive(Debug)] @@ -25,6 +23,8 @@ pub struct Runtime { impl Runtime { /** Creates a new Lune runtime, with a new Luau VM. + + Injects standard globals and libraries if any of the `std` features are enabled. */ #[must_use] #[allow(clippy::new_without_default)] @@ -34,7 +34,21 @@ impl Runtime { lua.set_app_data(Rc::downgrade(&lua)); lua.set_app_data(Vec::::new()); - inject_globals(&lua).expect("Failed to inject globals"); + #[cfg(any( + feature = "std-datetime", + feature = "std-fs", + feature = "std-luau", + feature = "std-net", + feature = "std-process", + feature = "std-regex", + feature = "std-roblox", + feature = "std-serde", + feature = "std-stdio", + feature = "std-task", + ))] + { + lune_std::inject_globals(&lua).expect("Failed to inject globals"); + } Self { lua, diff --git a/crates/lune/src/standalone/metadata.rs b/crates/lune/src/standalone/metadata.rs index f2ddfd9..e625d47 100644 --- a/crates/lune/src/standalone/metadata.rs +++ b/crates/lune/src/standalone/metadata.rs @@ -5,7 +5,7 @@ use mlua::Compiler as LuaCompiler; use once_cell::sync::Lazy; use tokio::fs; -pub const CURRENT_EXE: Lazy = +pub static CURRENT_EXE: Lazy = Lazy::new(|| env::current_exe().expect("failed to get current exe")); const MAGIC: &[u8; 8] = b"cr3sc3nt"; diff --git a/crates/lune/src/tests.rs b/crates/lune/src/tests.rs index 60947c2..fa1514a 100644 --- a/crates/lune/src/tests.rs +++ b/crates/lune/src/tests.rs @@ -55,7 +55,7 @@ macro_rules! create_tests { feature = "std-roblox", feature = "std-serde", feature = "std-stdio", - feature = "std-task" + feature = "std-task", ))] create_tests! { require_aliases: "require/tests/aliases",