4 Commits

17 changed files with 140 additions and 16 deletions

3
.env.build.linux.example Normal file
View File

@ -0,0 +1,3 @@
SESAM_FSV_VERSION=1.40.13
SESAM_FSV_LIB_PATH=/opt/santesocial/fsv/${SESAM_FSV_VERSION}/lib
SESAM_FSV_SSVLIB=ssvlux64

3
.env.build.win.example Normal file
View File

@ -0,0 +1,3 @@
SESAM_FSV_VERSION=1.40.13
SESAM_FSV_LIB_PATH="C:/Program Files/santesocial/fsv/${SESAM_FSV_VERSION}/lib"
SESAM_FSV_SSVLIB=ssvw64

2
.env.linux.example Normal file
View File

@ -0,0 +1,2 @@
SESAM_FSV_VERSION=1.40.13
SESAM_INI_PATH=/etc/opt/santesocial/fsv/${SESAM_FSV_VERSION}/conf/sesam.ini

2
.env.win.example Normal file
View File

@ -0,0 +1,2 @@
SESAM_FSV_VERSION=1.40.13
SESAM_INI_PATH=${ALLUSERSPROFILE}\\santesocial\\fsv\\${SESAM_FSV_VERSION}\\conf\\sesam.ini

5
.gitignore vendored
View File

@ -1 +1,6 @@
# Ignore Rust target directory
/target /target
# Ignore .env files
.env
.env.build

7
Cargo.lock generated
View File

@ -2,6 +2,12 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]] [[package]]
name = "libc" name = "libc"
version = "0.2.155" version = "0.2.155"
@ -12,5 +18,6 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
name = "utils-debug-c-lib" name = "utils-debug-c-lib"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"dotenv",
"libc", "libc",
] ]

View File

@ -5,4 +5,8 @@ edition = "2021"
build = "build.rs" build = "build.rs"
[dependencies] [dependencies]
dotenv = "0.15"
libc = "0.2" libc = "0.2"
[build-dependencies]
dotenv = "0.15"

View File

@ -1,12 +1,46 @@
## À explorer ## Requirements
- Générer des bindings RUST depuis des .h : https://jvns.ca/blog/2017/12/21/bindgen-is-awesome/ - Installer le [package FSV](https://industriels.sesam-vitale.fr/group/fournitures-sesam-vitale)
- Les librairies dynamiques (.lib, .dll, ...) fournies ne sont pas installés dans les emplacements standard du système, il faudra donc configurer leur chemin d'installation dans le fichier de configuration `.env.build` (voir ci-dessous)
- Le détail des chemins d'installation est donné dans la documentation du package FSV `fsv-mi-004_pack-FSV1.40.14_V2.3.pdf`
- Linux - par défaut : `/opt/santesocial/fsv/1.40.13/lib`
- Windows - par défaut : `C:\Program Files\santesocial\santesocial\fsv\1.40.14\lib` (ou dans Program Files (x86) si c'est le package 32bits qui a été installé)
- Installer la [CryptolibCPS](https://industriels.sesam-vitale.fr/group/galss-cryptolib-cps)
- Ce package fourni également l'utilitaire "CPS Gestion" pour obtenir des informations sur le lecteur de carte, etc.
- Linux : `cpgeslux`
- Windows : `...`
## Setup ## Setup
- Installer le [package FSV](https://industriels.sesam-vitale.fr/group/fournitures-sesam-vitale) - Créer et éditer le fichier de configuration de build `.env.build` en s'inspirant d'un des fichiers d'exemple (`.env.build.linux.example`, `.env.build.win.example`...)
- Ajouter le path des librairies FSV à `LD_LIBRARY_PATH` : `export LD_LIBRARY_PATH=/path/to/your/library:$LD_LIBRARY_PATH` - Ce fichier est nécessaire pour le build du package Rust
- Créer et éditer le fichier de configuration de l'exécution `.env` en s'inspirant d'un des fichiers d'exemple (`.env.linux.example`, `.env.win.example`...)
- Ce fichier est nécessaire pour l'exécution du package Rust compilé, et doit donc être présent aux côtés de l'exécutable généré, le cas échéant
- Installer la [CryptolibCPS](https://industriels.sesam-vitale.fr/group/galss-cryptolib-cps) ## Build
- Fourni l'utilitaire "CPS Gestion" pour obtenir des informations sur le lecteur de carte, etc.
- Linux : `cpgeslux` ### Compilation C
Ce package s'appuie sur deux librairies :
- Une librairie statique, compilée à partir des sources (`*.c`, `*.h`) fournies dans le dossier `./src`
- Une librairie dynamique, fournie par le package FSV
- Windows : on fournit les headers, non présents dans la `.dll` en compilant les fichiers `src/*.def` en leur version binaire `lib/*.lib`
Pour compiler les fichiers de librairie :
- Windows : `.\make.bat`
- Linux : `make`
Pour nettoyer le dossier `./lib` :
- Windows : `.\make.bat /clean`
- Linux : `make clean`
### Compilation Rust
`cargo build`
## Run
`cargo run`

View File

@ -1,9 +1,26 @@
fn main() { extern crate dotenv;
println!("cargo:rustc-link-search=native=./lib");
println!("cargo:rustc-link-lib=static=p4pillondebuglib");
println!("cargo:rerun-if-changed=lib/libp4pillondebuglib.a");
println!("cargo:rustc-link-search=native=/opt/santesocial/fsv/1.40.13/lib"); use std::env;
println!("cargo:rustc-link-lib=dylib=ssvlux64"); use std::path::PathBuf;
println!("cargo:rerun-if-changed=/opt/santesocial/fsv/1.40.13/lib/libssvlux64.so");
fn main() {
dotenv::from_filename(".env.build").ok();
println!("cargo::rerun-if-changed=.env.build");
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let static_lib_path = PathBuf::from(manifest_dir).join("lib");
println!("cargo::rustc-link-search=native={}", static_lib_path.display());
println!("cargo::rustc-link-lib=static=p4pillondebuglib");
let fsv_lib_path = PathBuf::from(env::var("SESAM_FSV_LIB_PATH").unwrap());
println!("cargo::rustc-link-search=native={}", fsv_lib_path.display());
println!("cargo::rustc-link-lib=dylib={}", env::var("SESAM_FSV_SSVLIB").unwrap());
if cfg!(target_os = "windows") {
let path = env::var("PATH").unwrap_or(String::new());
println!("cargo:rustc-env=PATH={};{}", fsv_lib_path.display(), path);
} else if cfg!(target_os = "linux") {
println!("cargo:rustc-env=LD_LIBRARY_PATH={}", fsv_lib_path.display());
}
} }

Binary file not shown.

BIN
lib/p4pillondebuglib.lib Normal file

Binary file not shown.

BIN
lib/p4pillondebuglib.obj Normal file

Binary file not shown.

BIN
lib/ssvw64.exp Normal file

Binary file not shown.

BIN
lib/ssvw64.lib Normal file

Binary file not shown.

36
make.bat Normal file
View File

@ -0,0 +1,36 @@
@echo off
rem Set variables
set SRC_DIR=src
set LIB_DIR=lib
rem Create the %LIB_DIR% directory if it does not exist
if not exist %LIB_DIR% mkdir %LIB_DIR%
if "%1"=="/clean" (
goto clean
)
rem Configure the environment for Visual Studio
call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
rem Build %SRC_DIR%\*.c files
cl /c /Fd:%LIB_DIR%\ /Fo:%LIB_DIR%\ /Iinclude\ /I%SRC_DIR%\ %SRC_DIR%\*.c
rem Link the object files into a static library
lib %LIB_DIR%\*.obj
rem Create a ssvw64.lib file from a ssvw64.def file
lib /def:%SRC_DIR%\ssvw64.def /out:%LIB_DIR%\ssvw64.lib /machine:x64
rem Build complete
pause
exit /b 0
:clean
del %LIB_DIR%\*.obj
del %LIB_DIR%\*.lib
del %LIB_DIR%\*.exp
rem Clean complete
pause
exit /b 0

View File

@ -1,10 +1,13 @@
extern crate libc; extern crate libc;
extern crate dotenv;
use libc::{ c_char, c_void, c_ushort, size_t }; use libc::{ c_char, c_void, c_ushort, size_t };
use std::ffi::CString; use std::ffi::CString;
use std::ptr; use std::ptr;
#[link(name = "ssvlux64")] use dotenv::dotenv;
use std::env;
extern "C" { extern "C" {
fn SSV_InitLIB2(pcRepSesamIni: *const c_char) -> c_ushort; fn SSV_InitLIB2(pcRepSesamIni: *const c_char) -> c_ushort;
fn SSV_LireCartePS(NomRessourcePS: *const c_char, NomRessourceLecteur: *const c_char, CodePorteurPS: *const c_char, ZDonneesSortie: *mut *mut c_void, TTailleDonneesSortie: *mut size_t) -> c_ushort; fn SSV_LireCartePS(NomRessourcePS: *const c_char, NomRessourceLecteur: *const c_char, CodePorteurPS: *const c_char, ZDonneesSortie: *mut *mut c_void, TTailleDonneesSortie: *mut size_t) -> c_ushort;
@ -12,7 +15,8 @@ extern "C" {
} }
fn ssv_init_lib_2() { fn ssv_init_lib_2() {
let ini = CString::new("/etc/opt/santesocial/fsv/1.40.13/conf/sesam.ini").expect("CString::new failed"); let ini_str = env::var("SESAM_INI_PATH").expect("SESAM_INI_PATH must be set");
let ini = CString::new(ini_str).expect("CString::new failed");
unsafe { unsafe {
let result = SSV_InitLIB2(ini.as_ptr()); let result = SSV_InitLIB2(ini.as_ptr());
println!("SSV_InitLIB2 result: {}", result); println!("SSV_InitLIB2 result: {}", result);
@ -68,6 +72,8 @@ fn ssv_lire_config() {
} }
pub fn demo() { pub fn demo() {
dotenv().ok();
println!("------- Demo for the SSV library --------"); println!("------- Demo for the SSV library --------");
ssv_init_lib_2(); ssv_init_lib_2();

5
src/ssvw64.def Normal file
View File

@ -0,0 +1,5 @@
LIBRARY "ssvw64"
EXPORTS
SSV_InitLIB2
SSV_LireCartePS
SSV_LireConfig