Current section
Files
Jump to
Current section
Files
native/dala_beam/CONVERSION_SUMMARY.md
# C to Rust Conversion Summary
## Overview
Successfully converted the following C files to Rust:
| Original C File | Rust File | Status |
|----------------|-----------|---------|
| `android/jni/dala_beam.c` | `native/dala_beam/src/lib.rs` | ✅ Converted (stubs for some functions) |
| `android/jni/dala_beam.h` | `native/dala_beam/src/header.rs` | ✅ Converted |
| `android/jni/driver_tab_android.c` | `native/dala_beam/src/driver_tab_android.rs` | ✅ Converted |
| `ios/driver_tab_ios.c` | `native/dala_beam/src/driver_tab_ios.rs` | ✅ Converted |
## Architecture
### Crate Structure
```
dala/native/dala_beam/
├── Cargo.toml # Package config with features
├── build.rs # Conditional compilation
├── README.md # Usage documentation
├── CONVERSION_SUMMARY.md # This file
└── src/
├── lib.rs # Main BEAM launcher + JNI functions
├── header.rs # Public API (mirrors dala_beam.h)
├── driver_tab_android.rs # Android static NIF table
└── driver_tab_ios.rs # iOS static NIF table
```
### Key Differences from C
1. **Memory Safety**: Rust's ownership system prevents the memory issues common in C
2. **Feature Flags**: Conditional compilation via Cargo features instead of `#define`
3. **JNI Handling**: Using `jni` crate for safer JNI interactions
4. **Static Tables**: Same C-compatible layout with `#[repr(C)]` and `#[no_mangle]`
## Features Supported
| Feature Flag | Description | Equivalent C Define |
|--------------|-------------|-------------------|
| `no_beam` | Skip BEAM launch | `NO_BEAM` |
| `beam_untuned` | No BEAM tuning | `BEAM_UNTUNED` |
| `beam_sbwt_only` | Only SBWT tuning | `BEAM_SBWT_ONLY` |
| `beam_full_nerves` | Full Nerves tuning (default) | `BEAM_FULL_NERVES` |
| `beam_use_custom_flags` | Use custom flags | `BEAM_USE_CUSTOM_FLAGS` |
| `dala_static_sqlite_nif` | Statically link sqlite3 | `dala_STATIC_SQLITE_NIF` |
## Functions Converted
### JNI Functions (from `dala_beam.c`)
- ✅ `Java_com_example_dala_dalaBridge_nativeUiCacheClass`
- ✅ `Java_com_example_dala_dalaBridge_nativeInitBridge`
- ✅ `Java_com_example_dala_dalaBridge_nativeStartBeam`
### Event Senders (stubs - from `dala_beam.h`)
- ⚠️ `dala_send_tap`
- ⚠️ `dala_send_change_str`, `dala_send_change_bool`, `dala_send_change_float`
- ⚠️ `dala_send_focus`, `dala_send_blur`, `dala_send_submit`
- ⚠️ `dala_send_select`, `dala_send_compose`
- ⚠️ `dala_send_long_press`, `dala_send_double_tap`, swipe variants
- ⚠️ `dala_send_scroll`, `dala_send_drag`, `dala_send_pinch`, `dala_send_rotate`
- ⚠️ `dala_send_pointer_move`
- ⚠️ `dala_send_scroll_began/ended/settled/top_reached/scrolled_past`
### Device Capability Delivery (stubs)
- ⚠️ `dala_deliver_atom2`, `dala_deliver_atom3`
- ⚠️ `dala_deliver_location`, `dala_deliver_motion`
- ⚠️ `dala_deliver_file_result`, `dala_deliver_push_token`
- ⚠️ `dala_deliver_notification`, `dala_set_launch_notification`
- ⚠️ `dala_deliver_alert_action`
- ⚠️ `dala_send_component_event`, `dala_send_color_scheme_changed`
### Static Tables
- ✅ `driver_tab` (Android & iOS)
- ✅ `erts_static_nif_tab` (Android & iOS)
- ✅ `erts_init_static_drivers`
## What Still Needs Implementation
### High Priority
1. **JNI Bridge Cache**: Implement `_dala_ui_cache_class_impl` and `_dala_bridge_init_activity` calls
2. **Cold-start Fix**: Complete the `wait_for_window_focus()` function with proper JNI polling
3. **BEAM Startup**: Properly call `erl_start()` with FFI
4. **Event Senders**: Implement all `dala_send_*` functions to communicate with BEAM
### Medium Priority
5. **SQLite3 Symlinks**: Implement the exqlite NIF symlink logic
6. **Startup Phase**: Implement `set_startup_phase()` and `set_startup_error()` via JNI
7. **JVM Management**: Properly store and manage `g_jvm` and `g_activity` global state
## Build Commands
```bash
# Add to workspace
cd dala
cargo build -p dala_beam --target aarch64-linux-android # Android
cargo build -p dala_beam --target aarch64-apple-ios # iOS device
cargo build -p dala_beam --target x86_64-apple-ios # iOS simulator
```
## Testing
The converted code maintains API compatibility with the original C code. The static tables export the same symbols (`driver_tab`, `erts_static_nif_tab`) with C linkage via `#[no_mangle]`.
## Notes
- The `dala_nif` crate (separate) handles the actual NIF implementations using Rustler
- This `dala_beam` crate handles BEAM startup and JNI bridge initialization
- The static tables reference `dala_nif_nif_init` which is exported by the `dala_nif` crate
- All event sender functions are currently stubs that need to be connected to the actual BEAM message passing