From dff72850cecde141037de83c17b6e75a7a2f5850 Mon Sep 17 00:00:00 2001 From: Michael Zhang Date: Fri, 21 Jun 2024 18:04:53 -0500 Subject: [PATCH] add sdk crate --- Cargo.lock | 8 ++++++++ apps/journal/Cargo.toml | 1 + apps/journal/src/lib.rs | 16 +--------------- crates/panorama-app-sdk/Cargo.toml | 10 ++++++++++ crates/panorama-app-sdk/src/lib.rs | 15 +++++++++++++++ 5 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 crates/panorama-app-sdk/Cargo.toml create mode 100644 crates/panorama-app-sdk/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index a930b37..9a8d867 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2686,6 +2686,7 @@ dependencies = [ name = "journal" version = "0.1.0" dependencies = [ + "panorama-app-sdk", "wasm-bindgen", ] @@ -3469,6 +3470,13 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "panorama-app-sdk" +version = "0.1.0" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "panorama-core" version = "0.1.0" diff --git a/apps/journal/Cargo.toml b/apps/journal/Cargo.toml index b9801fb..ffbbc53 100644 --- a/apps/journal/Cargo.toml +++ b/apps/journal/Cargo.toml @@ -8,3 +8,4 @@ crate-type = ["cdylib", "rlib"] [dependencies] wasm-bindgen = "0.2.92" +panorama-app-sdk = { path = "../../crates/panorama-app-sdk" } diff --git a/apps/journal/src/lib.rs b/apps/journal/src/lib.rs index ba72875..4154c2f 100644 --- a/apps/journal/src/lib.rs +++ b/apps/journal/src/lib.rs @@ -2,22 +2,8 @@ use std::ffi::CString; use wasm_bindgen::prelude::wasm_bindgen; -mod sys { - use std::ffi::c_char; - - extern "C" { - pub fn register_endpoint(url: *const c_char); - } -} - -pub fn register_endpoint(url: impl AsRef) { - let url = CString::new(url.as_ref()).unwrap(); - let result = unsafe { sys::register_endpoint(url.into_raw()) }; - println!("Result: {:?}", result); -} - #[wasm_bindgen] pub fn install() -> i32 { - register_endpoint("/hello"); + panorama_app_sdk::register_endpoint("/hello"); 123 } diff --git a/crates/panorama-app-sdk/Cargo.toml b/crates/panorama-app-sdk/Cargo.toml new file mode 100644 index 0000000..81d2a9e --- /dev/null +++ b/crates/panorama-app-sdk/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "panorama-app-sdk" +version = "0.1.0" +edition = "2021" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +wasm-bindgen = "0.2.92" diff --git a/crates/panorama-app-sdk/src/lib.rs b/crates/panorama-app-sdk/src/lib.rs new file mode 100644 index 0000000..f0dc409 --- /dev/null +++ b/crates/panorama-app-sdk/src/lib.rs @@ -0,0 +1,15 @@ +use std::ffi::CString; + +pub mod sys { + use std::ffi::c_char; + + extern "C" { + pub fn register_endpoint(url: *const c_char); + } +} + +pub fn register_endpoint(url: impl AsRef) { + let url = CString::new(url.as_ref()).unwrap(); + let result = unsafe { sys::register_endpoint(url.into_raw()) }; + println!("Result: {:?}", result); +}