Runtime: Feature flags for optional stdlib modules #252

Closed
opened 2026-01-12 02:39:55 +00:00 by navicore · 1 comment
navicore commented 2026-01-12 02:39:55 +00:00 (Migrated from github.com)

Summary

Implement Cargo feature flags to allow opt-in compilation of stdlib modules. This keeps the core runtime small while allowing full batteries for apps that need them.

Proposed Feature Structure

# Cargo.toml for seq-runtime
[features]
default = ["core"]
core = []                           # Stack ops, I/O, channels - always on
full = ["http", "crypto", "regex"]  # Everything

# Opt-in capabilities
http = ["dep:ureq", "dep:rustls"]   # HTTP client, adds ~1-2MB
crypto = ["dep:sha2", "dep:aes-gcm", "dep:ed25519-dalek"]  # ~500KB
regex = ["dep:regex"]               # ~1MB
compression = ["dep:flate2"]        # ~200KB

Binary Size Targets

Configuration Approx Size Use Case
core only ~2-3MB Embedded, CLI tools, scripts
core + http ~4-5MB API clients, web scrapers
core + crypto ~3-4MB Security tools, auth services
full ~6-8MB Full web applications

Implementation

  1. Add feature flags to runtime Cargo.toml
  2. Gate builtin functions with #[cfg(feature = "...")]
  3. Provide stub functions that panic with helpful message when feature disabled
  4. Update build scripts to pass features through

Deliverables Checklist

  • Feature flag structure in crates/runtime/Cargo.toml
  • Gated compilation for each optional module
  • Helpful panic messages for disabled features
  • Documentation in README for feature usage
  • Test builds with different feature combinations
  • Update docs/BATTERIES_INCLUDED.md with final binary sizes

Compiler Integration (Future)

Eventually the compiler could:

  • Detect which features a program needs
  • Error at compile time if required feature not enabled
  • Auto-suggest: "Enable --features crypto for crypto.sha256"

References

  • See docs/BATTERIES_INCLUDED.md Feature Flags & Binary Size section
## Summary Implement Cargo feature flags to allow opt-in compilation of stdlib modules. This keeps the core runtime small while allowing full batteries for apps that need them. ## Proposed Feature Structure ```toml # Cargo.toml for seq-runtime [features] default = ["core"] core = [] # Stack ops, I/O, channels - always on full = ["http", "crypto", "regex"] # Everything # Opt-in capabilities http = ["dep:ureq", "dep:rustls"] # HTTP client, adds ~1-2MB crypto = ["dep:sha2", "dep:aes-gcm", "dep:ed25519-dalek"] # ~500KB regex = ["dep:regex"] # ~1MB compression = ["dep:flate2"] # ~200KB ``` ## Binary Size Targets | Configuration | Approx Size | Use Case | |---------------|-------------|----------| | `core` only | ~2-3MB | Embedded, CLI tools, scripts | | `core` + `http` | ~4-5MB | API clients, web scrapers | | `core` + `crypto` | ~3-4MB | Security tools, auth services | | `full` | ~6-8MB | Full web applications | ## Implementation 1. Add feature flags to runtime Cargo.toml 2. Gate builtin functions with `#[cfg(feature = "...")]` 3. Provide stub functions that panic with helpful message when feature disabled 4. Update build scripts to pass features through ## Deliverables Checklist - [ ] Feature flag structure in `crates/runtime/Cargo.toml` - [ ] Gated compilation for each optional module - [ ] Helpful panic messages for disabled features - [ ] Documentation in README for feature usage - [ ] Test builds with different feature combinations - [ ] Update `docs/BATTERIES_INCLUDED.md` with final binary sizes ## Compiler Integration (Future) Eventually the compiler could: - Detect which features a program needs - Error at compile time if required feature not enabled - Auto-suggest: "Enable --features crypto for crypto.sha256" ## References - See `docs/BATTERIES_INCLUDED.md` Feature Flags & Binary Size section
navicore commented 2026-01-14 22:10:37 +00:00 (Migrated from github.com)
https://github.com/navicore/patch-seq/pull/262
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
navicore/patch-seq#252
No description provided.