Compare commits

..

4 Commits

Author SHA1 Message Date
1a292c6316
feat: improve the fsv-sys README, and add a PROGESS.md for implementation tracking 2024-10-01 22:22:27 +02:00
e4ff89fee9
feat: Gestion des versions multiples de FSV dans le wrapper exposant les fonctions de la librairie 2024-10-01 22:22:27 +02:00
e03a107d83
feat: handle multi-version bindings generation 2024-10-01 22:22:27 +02:00
c549f7def5
feat: Première implémentation de bindings pour FSV SESAM-Vitale
- Création de la crates/fsv-sys
- Ajout des headers de la FSV 1.40.14.13 dans crates/fsv-sys/vendor
- Génération des bindings depuis ces headers avec bindgen
- Implémentation d'une structure de loading de la librairie au runtime
- Implémentation d'une macro permettant de générer facilement la couche d'accès aux fonctions de la librairie
2024-10-01 22:22:27 +02:00
3 changed files with 30 additions and 24 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
Cargo.lock -merge linguist-generated=false

View File

@ -0,0 +1,12 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(unused)]
pub mod BINDINGS_V1_40_14 {
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.14.rs"));
}
pub mod BINDINGS_V1_40_13 {
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.13.rs"));
}

View File

@ -1,16 +1,17 @@
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)] #![allow(non_snake_case)]
use std::marker::PhantomData; use std::marker::PhantomData;
mod bindings;
use bindings::*;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum SUPPORTED_FSV_VERSIONS { pub enum SupportedFsvVersion {
V1_40_14, // 1.40.14 V1_40_14, // 1.40.14
V1_40_13, // 1.40.13 V1_40_13, // 1.40.13
} }
impl SUPPORTED_FSV_VERSIONS { impl SupportedFsvVersion {
fn as_str(&self) -> &'static str { fn as_str(&self) -> &'static str {
match self { match self {
Self::V1_40_14 => "1.40.14", Self::V1_40_14 => "1.40.14",
@ -19,14 +20,6 @@ impl SUPPORTED_FSV_VERSIONS {
} }
} }
mod BINDINGS_V1_40_14 {
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.14.rs"));
}
mod BINDINGS_V1_40_13 {
include!(concat!(env!("OUT_DIR"), "/bindings_1.40.13.rs"));
}
#[derive(thiserror::Error, Debug)] #[derive(thiserror::Error, Debug)]
pub enum Error { pub enum Error {
#[error(transparent)] #[error(transparent)]
@ -66,26 +59,26 @@ mod sealed { pub trait Sealed {}}
/// Wrapper around the SESAM-VITALE library /// Wrapper around the SESAM-VITALE library
/// This struct is responsible for loading the library and providing an interface to call its functions. /// This struct is responsible for loading the library and providing an interface to call its functions.
/// The library is loaded at creation and kept in memory until the struct is dropped. /// The library is loaded at creation and kept in memory until the struct is dropped.
pub trait SSVLibrary_Common { pub trait SSVLibraryCommon {
fn new(path: &str) -> Result<Self, Error> where Self: Sized; fn new(path: &str) -> Result<Self, Error> where Self: Sized;
} }
pub trait SSVLibrary_Version: sealed::Sealed {} pub trait SSVLibraryVersion: sealed::Sealed {}
pub struct V1_40_13 {} pub struct V1_40_13 {}
impl sealed::Sealed for V1_40_13 {} impl sealed::Sealed for V1_40_13 {}
impl SSVLibrary_Version for V1_40_13 {} impl SSVLibraryVersion for V1_40_13 {}
pub struct V1_40_14 {} pub struct V1_40_14 {}
impl sealed::Sealed for V1_40_14 {} impl sealed::Sealed for V1_40_14 {}
impl SSVLibrary_Version for V1_40_14 {} impl SSVLibraryVersion for V1_40_14 {}
pub struct SSVLibrary<Version: SSVLibrary_Version> { pub struct SSVLibrary<Version: SSVLibraryVersion> {
_version: PhantomData<Version>, _version: PhantomData<Version>,
library: libloading::Library, library: libloading::Library,
} }
impl<Version: SSVLibrary_Version> SSVLibrary_Common for SSVLibrary<Version> { impl<Version: SSVLibraryVersion> SSVLibraryCommon for SSVLibrary<Version> {
fn new(path: &str) -> Result<Self, Error> { fn new(path: &str) -> Result<Self, Error> {
let library = unsafe { libloading::Library::new(path)?}; let library = unsafe { libloading::Library::new(path)?};
Ok(Self { Ok(Self {
@ -137,14 +130,14 @@ impl SSVLibrary<V1_40_13> {
}); });
} }
pub fn get_library_path(version: &SUPPORTED_FSV_VERSIONS) -> String { pub fn get_library_path(version: &SupportedFsvVersion) -> String {
let root_path = get_library_root_path(); let root_path = get_library_root_path();
let library_name = get_library_name(); let library_name = get_library_name();
let version = version.as_str(); let version = version.as_str();
format!("{root_path}/{version}/lib/{library_name}") format!("{root_path}/{version}/lib/{library_name}")
} }
pub fn sesam_ini_path(version: &SUPPORTED_FSV_VERSIONS) -> String { pub fn sesam_ini_path(version: &SupportedFsvVersion) -> String {
let root_path = get_sesam_ini_root_path(); let root_path = get_sesam_ini_root_path();
let version = version.as_str(); let version = version.as_str();
format!("{root_path}/{version}/conf/sesam.ini") format!("{root_path}/{version}/conf/sesam.ini")
@ -171,22 +164,22 @@ mod test {
#[test] #[test]
fn test_initlib2() { fn test_initlib2() {
let lib_path = &get_library_path(&SUPPORTED_FSV_VERSIONS::V1_40_13); let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
let ssv_library = SSVLibrary::<V1_40_13>::new(lib_path).expect("SSVLibrary::new failed"); let ssv_library = SSVLibrary::<V1_40_13>::new(lib_path).expect("SSVLibrary::new failed");
let sesam_ini_str = let sesam_ini_str =
CString::new(sesam_ini_path(&SUPPORTED_FSV_VERSIONS::V1_40_13)).expect("CString::new failed"); CString::new(sesam_ini_path(&SupportedFsvVersion::V1_40_13)).expect("CString::new failed");
let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap(); let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap();
assert_eq!(result, 0); assert_eq!(result, 0);
} }
#[test] #[test]
fn test_lire_config_and_carte_ps() { fn test_lire_config_and_carte_ps() {
let lib_path = &get_library_path(&SUPPORTED_FSV_VERSIONS::V1_40_13); let lib_path = &get_library_path(&SupportedFsvVersion::V1_40_13);
let ssv_library = SSVLibrary::<V1_40_13>::new(lib_path).expect("SSVLibrary::new failed"); let ssv_library = SSVLibrary::<V1_40_13>::new(lib_path).expect("SSVLibrary::new failed");
let sesam_ini_str = let sesam_ini_str =
CString::new(sesam_ini_path(&SUPPORTED_FSV_VERSIONS::V1_40_13)).expect("CString::new failed"); CString::new(sesam_ini_path(&SupportedFsvVersion::V1_40_13)).expect("CString::new failed");
let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap(); let result = unsafe { ssv_library.ssv_init_lib2(sesam_ini_str.as_ptr()) }.unwrap();
assert_eq!(result, 0); assert_eq!(result, 0);