Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Rust wrapper #3181

Draft
wants to merge 26 commits into
base: main
Choose a base branch
from
Draft

WIP: Rust wrapper #3181

wants to merge 26 commits into from

Conversation

nyurik
Copy link
Member

@nyurik nyurik commented Jan 27, 2025

TODO/Goals

  • Include core header files
  • Generate/write a tiny C++ wrapper that Rust can communicate with
  • Compile core with cmake, possibly including the tiny C++ generated code - resulting in a statically-linkable (from Rust) lib
  • Use proper Rust strings instead of &CStr and CString where it is not performance critical.
    • PROs: consistency with the Rust ecosystem, proper utf-8 validated strings going in and out of the crate.
    • CONs: requires extra allocation and validation. On invalid string will panic, or we must introduce Result<String> for proper error reporting.

Implementation ideas

Current thinking is to get cmake to produce a static library. All steps must be initiated by the platform/rust-cxx/build.rs:

  • cxx bridge generates a header file out of the #[cxx::bridge] mod ffi { ... } in platform/rust-cxx/src/main.rs
  • cmake crate executes cmake with special flags to pick up that header file, plus any other CC and H files in the rust-cxx dirs, plus the rest of the core and produces static lib
  • main.rs links to it and calls get_version or some other basic thing

@nyurik nyurik marked this pull request as draft January 27, 2025 18:07
@nyurik nyurik changed the title Rust wrapper WIP: Rust wrapper Jan 27, 2025
@nyurik nyurik force-pushed the rust-wrapper branch 2 times, most recently from 611176c to d2ef4df Compare January 27, 2025 19:44
Copy link

github-actions bot commented Jan 29, 2025

Bloaty Results 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [ = ]       0  [ = ]       0    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-3181-compared-to-main.txt

Compared to d387090 (legacy)

    FILE SIZE        VM SIZE    
 --------------  -------------- 
   +31% +36.1Mi  +438% +26.2Mi    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results/pr-3181-compared-to-legacy.txt

Copy link

github-actions bot commented Jan 29, 2025

Benchmark Results ⚡

Benchmark                                                     Time             CPU      Time Old      Time New       CPU Old       CPU New
------------------------------------------------------------------------------------------------------------------------------------------
OVERALL_GEOMEAN                                            -0.0071         -0.0074             0             0             0             0

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/benchmark-results/pr-3181-compared-to-main.txt

platform/rust/Cargo.toml Outdated Show resolved Hide resolved
return std::make_unique<TileServerOptions>();
}
std::unique_ptr<TileServerOptions> TileServerOptions_mapbox() {
return std::make_unique<TileServerOptions>(TileServerOptions::MapLibreConfiguration());
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are pending deprecation and removal.

Copy link
Member Author

Choose a reason for hiding this comment

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

For now these are good for testing, but I agree that we should remove these

Copy link

github-actions bot commented Feb 5, 2025

Bloaty Results (iOS) 🐋

Compared to main

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [ = ]       0  [ = ]       0    TOTAL

Full report: https://maplibre-native.s3.eu-central-1.amazonaws.com/bloaty-results-ios/pr-3181-compared-to-main.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants