Skip to content

Some C-Rust API diffsΒ #450

@Attacker23

Description

@Attacker23

Hi!
Your project is impressively complete and has clearly evolved a lot over time. Some folks think it’s dead already πŸ˜‚.I noticed the core implements a C-to-Rust FFI layer, so I pulled together a quick summary of API changes. Hopefully this helps with a review or gives users a heads-up!The full set of collected API changes is available in my repo: https://github.com/Attacker23/rust-ffis-changes.

Overview highlights

  • Return type unification and 64-bit adoption:
    • Several APIs move to wider or pointer returns (e.g., sqlite_int64, void*).
  • Naming normalization:
    • C and Rust functions consistently renamed to snake_case with a crsql_ prefix; many C vtab hooks moved from static int to exported int.
  • Parameter updates:
    • Added out-parameter for error messages, added context pointers (sqlite3, crsql_ExtData), module-qualified sqlite types on Rust side.

A) VTab: changes module (C and Rust)
Files

  • C: E:\rust_projects\c\cr-sqlite\core\src\changes-vtab.c
  • Rust FFI: E:\rust_projects\c\cr-sqlite\core\rs\core\src\changes_vtab.rs

Rename timelines and changes

  • Begin
    • C: xBegin β†’ crsql_changes_begin; 68cefa9 β†’ 20490c0
      • Return: static int β†’ int
    • Rust: begin β†’ crsql_changes_begin; 34e4462 β†’ 20490c0
  • BestIndex chain (C)
    • templatevtabBestIndex β†’ changesSinceBestIndex; fcbe5f9 β†’ 7e346aa
    • changesSinceBestIndex β†’ changesBestIndex; 7e346aa β†’ 0dc614a
    • changesBestIndex β†’ crsql_changes_best_index; ebb8726 β†’ c9673da
      • Return: static int β†’ int
  • Filter chain (C)
    • templatevtabFilter β†’ changesSinceFilter; fcbe5f9 β†’ 39fe149
    • changesSinceFilter β†’ changesFilter; 39fe149 β†’ 0dc614a
    • changesFilter β†’ crsql_changes_filter; ebb8726 β†’ d61a957
      • Return: static int β†’ int
  • Other vtab hooks (Rust)

B) Compact/alter helpers
Files

  • C: E:\rust_projects\c\cr-sqlite\core\src\crsqlite.c

Changes

  • crsql_compactPostAlter
    • Rename: crsql_compactPostAlter β†’ crsql_compact_post_alter; b6a6f6c β†’ 48f8da7

C) Bootstrap/schema and migration flows
Files

  • C header: E:\rust_projects\c\cr-sqlite\core\src\rust.h
  • Rust: E:\rust_projects\c\cr-sqlite\core\rs\core\src\bootstrap.rs

Changes

  • Rust: crsql_create_schema_table_if_not_exists
    • Return: c_int β†’ Result<ResultCode, ResultCode>; a727a64 β†’ d9baa59
  • Rust: init_peer_tracking_table β†’ crsql_init_peer_tracking_table
    • Rename; 7d44977 β†’ a727a64
    • Return: Result<ResultCode, ResultCode} β†’ c_int
  • Maybe-update DB chain
    • Rust: step β†’ maybe_update_db; 4511219 β†’ 7d44977
        • param 0: *mut sqlite3; return: β†’ Result<ResultCode, ResultCode>
    • Rust: maybe_update_db β†’ crsql_maybe_update_db; 7d44977 β†’ a727a64
      • Return: Result<ResultCode, ResultCode> β†’ c_int
    • C header: crsql_maybe_update_db
    • Rust: crsql_maybe_update_db

D) Table info utilities and types
Files

  • Rust: E:\rust_projects\c\cr-sqlite\core\rs\core\src\tableinfo.rs

Changes

  • into_raw_parts β†’ crsql_drop_table_info_vec; 518121e β†’ 4ee44bd
      • param 0: ext_data: *mut crsql_ExtData
  • crsql_ensure_table_infos_are_up_to_date
    • Param 0 type: *mut sqlite3 β†’ *mut sqlite::sqlite3; 6630ff0 β†’ b02f9f1

E) DB version utility
Files

  • C header: E:\rust_projects\c\cr-sqlite\core\src\rust.h

Changes

  • crsql_next_db_version

F) Bundle/init entrypoint
Files

  • C: E:\rust_projects\c\cr-sqlite\core\src\crsqlite.c
  • Rust: E:\rust_projects\c\cr-sqlite\core\rs\bundle\src\lib.rs

Changes (timeline)

  • Rust: sqlite3_crsqlrustbundle_init param rename: _err_msg β†’ err_msg; 50d64f2 β†’ cb9b2b4
  • Rust: sqlite3_crsqlrustbundle_init return: u32 β†’ c_int; cb9b2b4 β†’ e59866e
  • C/Rust: sqlite3_crsqlrustbundle_init return: int/c_int β†’ void*/c_void*

Note

Sorry to bother youβ€”I'm currently learning Rust, especially around calling Rust from C. If you don’t mind, could I ask a couple of quick questions?

  1. Do you think the data I collected is useful? If so, what kind of help is there?
  2. What led you to choose Rust for the core? Memory safety, concurrency, performanceβ€”or something else?
  3. Did you run into notable challenges when bridging Rust with other languages (FFI)? Any lessons learned or patterns you’d recommend?

If this issue is noisy or off-topic, feel free to delete it.

Thanks and have a great day!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions