init
This commit is contained in:
15
crates/vpnshare-ffi/Cargo.toml
Normal file
15
crates/vpnshare-ffi/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "vpnshare-ffi"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
rust-version.workspace = true
|
||||
version.workspace = true
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
vpnshare-core = { path = "../vpnshare-core" }
|
||||
vpnshare-proto = { path = "../vpnshare-proto" }
|
||||
28
crates/vpnshare-ffi/src/lib.rs
Normal file
28
crates/vpnshare-ffi/src/lib.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
//! C ABI surface for Android and future desktop bindings.
|
||||
|
||||
use std::os::raw::c_char;
|
||||
|
||||
static VERSION: &[u8] = b"0.1.0\0";
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn vpnshare_core_version() -> *const c_char {
|
||||
VERSION.as_ptr().cast()
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn vpnshare_protocol_version() -> u8 {
|
||||
vpnshare_proto::PROTOCOL_VERSION
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::ffi::CStr;
|
||||
|
||||
#[test]
|
||||
fn exposes_version() {
|
||||
let raw = vpnshare_core_version();
|
||||
let version = unsafe { CStr::from_ptr(raw) };
|
||||
assert_eq!(version.to_str().unwrap(), "0.1.0");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user