From 5a7de6fb90120c0c1668bc2992cabc2fc284b83b Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Fri, 24 Jan 2025 00:15:34 -0500 Subject: [PATCH] wip --- platform/rust-autocxx/Cargo.toml | 2 +- platform/rust-cmake/Cargo.toml | 2 +- platform/rust-cxx/Cargo.toml | 10 ++++++++++ platform/rust-cxx/build.rs | 10 ++++++++++ platform/rust-cxx/src/main.rs | 12 ++++++++++++ 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 platform/rust-cxx/Cargo.toml create mode 100644 platform/rust-cxx/build.rs create mode 100644 platform/rust-cxx/src/main.rs diff --git a/platform/rust-autocxx/Cargo.toml b/platform/rust-autocxx/Cargo.toml index 2c4e5cd9eb1..ad14e60f868 100644 --- a/platform/rust-autocxx/Cargo.toml +++ b/platform/rust-autocxx/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rustlib" +name = "maplibre-native-autocxx" version = "0.1.0" authors = ["Yuri Astrakhan ", "MapLibre contributors"] description = "MapLibre Native Rust library" diff --git a/platform/rust-cmake/Cargo.toml b/platform/rust-cmake/Cargo.toml index a00fb5f44ef..15a4283e75e 100644 --- a/platform/rust-cmake/Cargo.toml +++ b/platform/rust-cmake/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "maplibre-native" +name = "maplibre-native-cmake" version = "0.1.0" edition = "2021" diff --git a/platform/rust-cxx/Cargo.toml b/platform/rust-cxx/Cargo.toml new file mode 100644 index 00000000000..e6530b9f4c7 --- /dev/null +++ b/platform/rust-cxx/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "maplibre-native-cxx" +version = "0.1.0" +edition = "2021" + +[dependencies] +cxx = "1.0" + +[build-dependencies] +cxx-build = "1.0" diff --git a/platform/rust-cxx/build.rs b/platform/rust-cxx/build.rs new file mode 100644 index 00000000000..7492b77f2e1 --- /dev/null +++ b/platform/rust-cxx/build.rs @@ -0,0 +1,10 @@ +fn main() { + cxx_build::bridge("src/main.rs") + .file("src/blobstore.cc") + .std("c++20") + .compile("cxxbridge-demo"); + + println!("cargo:rerun-if-changed=src/main.rs"); + println!("cargo:rerun-if-changed=src/blobstore.cc"); + println!("cargo:rerun-if-changed=include/blobstore.h"); +} diff --git a/platform/rust-cxx/src/main.rs b/platform/rust-cxx/src/main.rs new file mode 100644 index 00000000000..42c9f14c1f4 --- /dev/null +++ b/platform/rust-cxx/src/main.rs @@ -0,0 +1,12 @@ +// cxx wrapper for maplibre-native +#[cxx::bridge] +mod ffi { + unsafe extern "C++" { + include!("maplibre-native/include/maplibre-native.h"); + + type MaplibreNative; + + fn new_maplibre_native() -> UniquePtr; + fn render(&self, style: &str, width: u32, height: u32) -> Vec; + } +}