Skip to content

Commit

Permalink
make way more features optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Dec 21, 2023
1 parent 96c0d44 commit f4d7432
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 147 deletions.
29 changes: 19 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ crossbeam-channel = "0.5.9"
dashmap = {version = "5", features = ["serde"]}
ecow = {version = "0.2.0", features = ["serde"]}
enum-iterator = "1.4.1"
gif = "0.12.0"
hound = "3"
image = {version = "0.24.5", features = ["bmp", "gif", "ico", "jpeg", "png"]}
instant = "0.1.12"
num_cpus = "1.16.0"
once_cell = "1"
Expand Down Expand Up @@ -69,16 +66,21 @@ indexmap = {version = "2", optional = true, features = ["serde"]}
serde_tuple = "0.5.0"
serde_yaml = {version = "0.9.27", optional = true}

# Feature dependencies
gif = {version = "0.12.0", optional = true}
hound = {version = "3", optional = true}
image = {version = "0.24.5", optional = true, default-features = false, features = ["bmp", "gif", "ico", "jpeg", "png"]}

[features]
audio = ["hodaun", "lockfree"]
audio = ["hodaun", "lockfree", "audio_encode"]
audio_encode = ["hound"]
binary = [
"ctrlc",
"notify",
"clap",
"color-backtrace",
"lsp",
"rustyline",
"stand",
"native_sys",
]
bytes = []
debug = []
Expand All @@ -89,15 +91,22 @@ default = [
"https",
"invoke",
"trash",
"lsp",
"raw_mode",
"gif",
"stand",
"image",
"native_sys",
]
gif = ["dep:gif", "image"]
https = ["httparse", "rustls", "webpki-roots"]
invoke = ["open"]
lsp = ["tower-lsp", "tokio"]
lsp = ["tower-lsp", "tokio", "native_sys"]
native_sys = []
profile = ["serde_yaml", "indexmap"]
raw_mode = ["crossterm"]
stand = []
terminal_image = ["viuer"]
raw_mode = ["crossterm", "native_sys"]
stand = ["native_sys"]
terminal_image = ["viuer", "image"]

[[bin]]
name = "uiua"
Expand Down
11 changes: 8 additions & 3 deletions features.ua
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Test combinations of features

Command ← {"cargo" "c" "--lib" "--no-default-features"}
Features ← (
{"audio" "bytes" "https"}
⊂(
{"gif,image,terminal_image" "lsp,raw_mode"}
| {"audio_encode" "gif" "image" "terminal_image" "lsp" "native_sys" "raw_mode"}
) ∊□"all" &args
)

&p "Checking with no features"
⍤⊃⋅∘≍ 0 &runi Command

# Features to try
{"bytes" "lsp" "terminal_image" "raw_mode" "audio"}
↘1⋯⇡ⁿ:2⧻.
↘1⋯⇡ⁿ:2⧻. Features
≡(
⊐/$"_,_" ▽
&p $"Checking with features: _".
Expand Down
2 changes: 1 addition & 1 deletion site/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ leptos = "0.5.0"
leptos_meta = {version = "0.5.4", features = ["csr"]}
leptos_router = {version = "0.5.4", features = ["csr"]}
pathdiff = "0.2.1"
uiua = {path = "..", default-features = false, features = ["bytes"]}
uiua = {path = "..", default-features = false, features = ["bytes", "image", "gif", "audio_encode"]}
urlencoding = "2"
wasm-bindgen = "0.2.89"
wasm-bindgen-futures = "0.4.39"
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ mod run;
#[doc(hidden)]
pub mod stand;
mod sys;
#[cfg(feature = "native_sys")]
mod sys_native;
mod value;

Expand All @@ -141,10 +142,12 @@ pub use self::{
primitive::*,
run::*,
sys::*,
sys_native::*,
value::*,
};

#[cfg(feature = "native_sys")]
pub use self::sys_native::*;

pub use complex::*;
use ecow::EcoString;

Expand All @@ -156,9 +159,10 @@ pub type Ident = EcoString;

#[cfg(test)]
mod tests {
use super::*;
#[test]
#[cfg(feature = "native_sys")]
fn suite() {
use super::*;
for entry in std::fs::read_dir("tests").unwrap() {
let entry = entry.unwrap();
let path = entry.path();
Expand Down
4 changes: 2 additions & 2 deletions src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod server {
format::{format_str, FormatConfig},
lex::Loc,
primitive::{PrimClass, PrimDocFragment},
Assembly, BindingInfo, Compiler, NativeSys, PrimDocLine, Uiua,
Assembly, BindingInfo, Compiler, PrimDocLine, Uiua,
};

pub struct LspDoc {
Expand Down Expand Up @@ -465,7 +465,7 @@ mod server {
match format_str(
&doc.input,
&FormatConfig {
backend: Arc::new(NativeSys),
backend: Arc::new(crate::NativeSys),
..FormatConfig::find().unwrap_or_default()
},
) {
Expand Down
3 changes: 2 additions & 1 deletion src/primitive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1171,7 +1171,7 @@ impl PrimExample {
/// Get the example's output
pub fn output(&self) -> &Result<Vec<String>, String> {
self.output.get_or_init(|| {
let env = &mut Uiua::with_native_sys();
let mut env = Uiua::with_safe_sys();
match env.run_str(&self.input) {
Ok(_) => Ok(env.take_stack().into_iter().map(|val| val.show()).collect()),
Err(e) => Err(e
Expand Down Expand Up @@ -1333,6 +1333,7 @@ mod tests {
}

#[test]
#[cfg(feature = "native_sys")]
fn prim_docs() {
for prim in Primitive::non_deprecated() {
for line in &prim.doc().lines {
Expand Down
7 changes: 4 additions & 3 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use thread_local::ThreadLocal;

use crate::{
algorithm, array::Array, boxed::Boxed, check::instrs_temp_signatures, function::*, lex::Span,
value::Value, Assembly, Compiler, Complex, Global, Ident, Inputs, IntoSysBackend, NativeSys,
Primitive, SafeSys, SysBackend, SysOp, TraceFrame, UiuaError, UiuaResult,
value::Value, Assembly, Compiler, Complex, Global, Ident, Inputs, IntoSysBackend, Primitive,
SafeSys, SysBackend, SysOp, TraceFrame, UiuaError, UiuaResult,
};

/// The Uiua interpreter
Expand Down Expand Up @@ -209,8 +209,9 @@ impl Default for Runtime {

impl Uiua {
/// Create a new Uiua runtime with the standard IO backend
#[cfg(feature = "native_sys")]
pub fn with_native_sys() -> Self {
Self::with_backend(NativeSys)
Self::with_backend(crate::NativeSys)
}
/// Create a new Uiua runtime with no IO capabilities
pub fn with_safe_sys() -> Self {
Expand Down
Loading

0 comments on commit f4d7432

Please sign in to comment.