Skip to content

8 runtime adapter integration #1#25

Merged
lxsaah merged 65 commits intomainfrom
8-runtime-adapter-integration-#1
Oct 11, 2025
Merged

8 runtime adapter integration #1#25
lxsaah merged 65 commits intomainfrom
8-runtime-adapter-integration-#1

Conversation

@lxsaah
Copy link
Copy Markdown
Contributor

@lxsaah lxsaah commented Oct 3, 2025

Closes #8.

Changelog: Runtime Adapter Integration

Overview

This PR implements comprehensive runtime adapter integration for AimDB, enabling seamless async operations across both standard (Tokio) and embedded (Embassy) runtimes. This addresses issue #8 and establishes the foundation for AimDB's cross-platform async capabilities.

🎯 Major Features

1. Unified Runtime Abstraction Layer

  • Created aimdb-executor crate with runtime-agnostic traits:
    • RuntimeAdapter - Core runtime identification
    • Spawn - Dynamic task spawning capabilities
    • TimeOps - Unified time operations (now, duration, sleep)
    • Logger - Runtime-appropriate logging
    • Runtime - Composite trait combining all capabilities
  • Feature-gated compilation for std, tokio-runtime, and embassy-runtime

2. Tokio Runtime Integration (aimdb-tokio-adapter)

  • Full std runtime support with Tokio executor
  • Implements all executor traits:
    • Dynamic task spawning with tokio::spawn
    • Time operations using tokio::time
    • Logging via tracing crate
  • TokioDatabase with unified builder API
  • Comprehensive example in examples/tokio-runtime-demo

3. Embassy Runtime Integration (aimdb-embassy-adapter)

  • no_std embedded runtime support
  • Implements executor traits for Embassy:
    • Static task spawning (via #[embassy_executor::task])
    • Time operations using embassy_time
    • Logging via defmt
  • EmbassyDatabase with spawner-aware builder
  • Complete example in examples/embassy-runtime-demo (STM32H563ZI target)

4. Enhanced Core Database (aimdb-core)

  • New RuntimeContext for unified runtime access
  • Emitter pattern for cross-record communication
  • Typed record storage using TypeId for type safety
  • Metrics tracking with tracked_fn macro
  • Producer-consumer pattern with self-registering records
  • Generic Database<A> over any runtime adapter
  • Builder pattern API for ergonomic database construction

5. Shared Examples Infrastructure

  • Created aimdb-examples-shared crate with reusable service implementations
  • data_processor_service - Demonstrates async data processing
  • monitoring_service - Shows metrics collection
  • Services work across both Tokio and Embassy runtimes via RuntimeContext

🔧 Technical Improvements

Error Handling

  • Enhanced DbError with runtime-specific variants
  • ExecutorError for runtime operation failures
  • Proper error propagation with tracing context preservation
  • Conversion traits between error types

Time Operations

  • Runtime-agnostic duration methods (millis, secs, micros)
  • Unified sleep interface across runtimes
  • TimeSource trait with instant comparisons

Logging

  • Abstracted logging via Logger trait
  • tracing for std environments
  • defmt for embedded targets
  • Runtime context provides convenient logging accessors

Build System

  • Updated Makefile with:
    • examples target for building all examples
    • Improved all command includes examples
    • Feature validation tests
  • CI enhancements:
    • Submodule support for Embassy dependency
    • Documentation generation
    • Multiple target testing

📦 New Crates & Modules

New Crates

  1. aimdb-executor - Runtime trait definitions
  2. aimdb-tokio-adapter - Tokio runtime implementation
  3. aimdb-embassy-adapter - Embassy runtime implementation (refactored)
  4. aimdb-examples-shared - Shared service code

New Modules in aimdb-core

  • runtime.rs - Runtime context and base traits
  • emitter.rs - Cross-record communication
  • metrics.rs - Performance tracking
  • producer_consumer.rs - Producer-consumer pattern
  • tracked_fn.rs - Async function tracking
  • typed_record.rs - Type-safe record storage

🧪 Examples & Demos

Producer-Consumer Demo (examples/producer-consumer-demo)

  • Demonstrates typed record usage
  • Shows producer-consumer pattern
  • Metrics tracking with tracked_fn
  • Emitter-based communication

Tokio Runtime Demo (examples/tokio-runtime-demo)

  • Full Tokio integration
  • Service spawning with RuntimeContext
  • Standard Rust async/await patterns

Embassy Runtime Demo (examples/embassy-runtime-demo)

  • STM32H563ZI target (Cortex-M33)
  • Embedded async with Embassy executor
  • LED feedback for visual status
  • StaticCell for safe static initialization

lxsaah added 3 commits October 3, 2025 20:23
- Introduced `TokioAdapter` for async task spawning and execution.
- Implemented time-related capabilities including timestamps and sleep.
- Updated feature flags in `Cargo.toml` for tracing and optional dependencies.
@lxsaah lxsaah requested a review from Copilot October 3, 2025 20:27
@lxsaah lxsaah self-assigned this Oct 3, 2025
@lxsaah lxsaah added the 🏗️ core Core engine work label Oct 3, 2025
@lxsaah lxsaah linked an issue Oct 3, 2025 that may be closed by this pull request
4 tasks
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements runtime adapter integration for AimDB, establishing the foundation for async task execution across different runtime environments (Tokio and Embassy). The implementation includes core traits for runtime and time operations, along with concrete adapters for both std and no_std environments.

Key changes:

  • Core runtime and time traits defining the adapter interface
  • Tokio adapter for std environments with full async runtime support
  • Embassy adapter for embedded/no_std environments with Embassy executor integration

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
aimdb-core/src/lib.rs Exports new runtime and time traits
aimdb-core/src/runtime.rs Defines core RuntimeAdapter and DelayCapableAdapter traits
aimdb-core/src/time.rs Implements TimestampProvider and SleepCapable traits with utilities
aimdb-core/Cargo.toml Adds tokio dev dependency for async testing
aimdb-tokio-adapter/src/lib.rs Updates module structure and documentation for runtime integration
aimdb-tokio-adapter/src/runtime.rs Implements TokioAdapter with RuntimeAdapter and DelayCapableAdapter
aimdb-tokio-adapter/src/time.rs Provides Tokio-specific time implementations
aimdb-tokio-adapter/Cargo.toml Adds tracing and futures dependencies
aimdb-embassy-adapter/src/lib.rs Exports new runtime and time modules
aimdb-embassy-adapter/src/runtime.rs Implements EmbassyAdapter for embedded environments
aimdb-embassy-adapter/src/time.rs Provides Embassy-specific time implementations
aimdb-embassy-adapter/Cargo.toml Adds tracing and testing dependencies

Comment thread aimdb-embassy-adapter/src/lib.rs Outdated
Comment thread aimdb-embassy-adapter/src/runtime.rs Outdated
Comment thread aimdb-tokio-adapter/src/runtime.rs Outdated
Comment thread aimdb-embassy-adapter/src/runtime.rs Outdated
@lxsaah lxsaah marked this pull request as draft October 4, 2025 14:13
lxsaah added 20 commits October 4, 2025 14:46
…ate service macro for automatic context injection
…eplacing 'embedded' with 'no_std minimal' and adjusting feature validation tests for clarity.
…arify no_std requirements for aimdb-core and aimdb-embassy-adapter
… and error handling, including new executor traits and improved feature definitions.
…handling, updating AimDbService implementation for better integration with Tokio and Embassy runtimes.
…s, updating service spawning methods and error handling for improved runtime integration.
…dating dependencies and error handling for better compatibility with async tasks.
lxsaah added 21 commits October 7, 2025 20:22
…log and time accessors for improved code clarity and efficiency
Enhance core library structure and exports
Introduce metrics tracking for producer-consumer patterns
Implement producer-consumer pattern with self-registering records
Add tracked async function wrapper for automatic call tracking
Develop type-safe record storage using TypeId
@lxsaah lxsaah marked this pull request as ready for review October 10, 2025 20:36
@lxsaah lxsaah requested a review from Copilot October 10, 2025 20:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 56 out of 57 changed files in this pull request and generated 6 comments.

Comment thread aimdb-core/src/lib.rs
Comment thread aimdb-core/src/error.rs Outdated
Comment thread aimdb-embassy-adapter/src/runtime.rs
Comment thread examples/embassy-runtime-demo/src/main.rs
Comment thread aimdb-embassy-adapter/src/runtime.rs Outdated
Comment thread aimdb-core/src/database.rs Outdated
lxsaah and others added 3 commits October 10, 2025 22:56
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Remove global static adapter initialization and related methods for cleaner API
@lxsaah lxsaah merged commit f1dae03 into main Oct 11, 2025
13 checks passed
@lxsaah lxsaah deleted the 8-runtime-adapter-integration-#1 branch October 11, 2025 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🏗️ core Core engine work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate Embassy and Tokio runtimes into AimDB (aimdb-core): unified task spawning + #[service] macro Runtime Adapter Integration

2 participants