From 851e2ecb8d687f0e0a17626221e66d012d232eea Mon Sep 17 00:00:00 2001 From: Tim Fennis Date: Mon, 2 Mar 2026 21:29:06 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Make=20serde,=20rand,=20and=20regex?= =?UTF-8?q?=20optional=20stdlib=20features?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/rust.yml | 4 ++-- ndc_stdlib/Cargo.toml | 13 +++++++++---- ndc_stdlib/src/lib.rs | 12 +++++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7dc4c9ad..c24e583a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -20,5 +20,5 @@ jobs: run: cargo build --verbose - name: Run tests run: cargo test --verbose - - name: Run no default - run: cargo test --verbose --no-default-features + - name: Build no default + run: cargo build --verbose --no-default-features diff --git a/ndc_stdlib/Cargo.toml b/ndc_stdlib/Cargo.toml index fe7bf513..84884144 100644 --- a/ndc_stdlib/Cargo.toml +++ b/ndc_stdlib/Cargo.toml @@ -11,15 +11,20 @@ ndc_lib = { workspace = true } ndc_macros.workspace = true num.workspace = true once_cell.workspace = true -rand.workspace = true -regex.workspace = true -serde_json = { workspace = true } tap.workspace = true +# Optional +rand = { workspace = true, optional = true } +regex = { workspace = true, optional = true } +serde_json = { workspace = true, optional = true } + # Crypto md5 = { version = "0.8.0", optional = true } sha1 = { version = "0.10.6", optional = true } [features] -default = ["crypto"] +default = ["crypto", "rand", "regex", "serde"] crypto = ["dep:md5", "dep:sha1"] +rand = ["dep:rand"] +regex = ["dep:regex"] +serde = ["dep:serde_json"] diff --git a/ndc_stdlib/src/lib.rs b/ndc_stdlib/src/lib.rs index 41270177..b1acc2c2 100644 --- a/ndc_stdlib/src/lib.rs +++ b/ndc_stdlib/src/lib.rs @@ -9,15 +9,18 @@ pub mod hash_map; pub mod heap; pub mod list; pub mod math; -pub mod rand; -pub mod regex; pub mod sequence; -pub mod serde; pub mod string; pub mod value; #[cfg(feature = "crypto")] pub mod crypto; +#[cfg(feature = "rand")] +pub mod rand; +#[cfg(feature = "regex")] +pub mod regex; +#[cfg(feature = "serde")] +pub mod serde; pub fn register(env: &mut Environment) { aoc::register(env); @@ -32,10 +35,13 @@ pub fn register(env: &mut Environment) { list::register(env); math::f64::register(env); math::register(env); + #[cfg(feature = "rand")] rand::register(env); + #[cfg(feature = "regex")] regex::register(env); sequence::extra::register(env); sequence::register(env); + #[cfg(feature = "serde")] serde::register(env); string::register(env); value::register(env);