diff --git a/.env.linux.example b/.env.linux.example new file mode 100644 index 0000000..c8d84aa --- /dev/null +++ b/.env.linux.example @@ -0,0 +1,2 @@ +SESAM_FSV_VERSION=1.40.13 +SESAM_INI_PATH=/etc/opt/santesocial/fsv/${SESAM_FSV_VERSION}/conf/sesam.ini diff --git a/.env.win.example b/.env.win.example new file mode 100644 index 0000000..bcd5177 --- /dev/null +++ b/.env.win.example @@ -0,0 +1,2 @@ +SESAM_FSV_VERSION=1.40.13 +SESAM_INI_PATH=${ALLUSERSPROFILE}\\santesocial\\fsv\\${SESAM_FSV_VERSION}\\conf\\sesam.ini diff --git a/.gitignore b/.gitignore index ea8c4bf..e6bb1c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ +# Ignore Rust target directory /target + +# Ignore .env file +.env diff --git a/Cargo.lock b/Cargo.lock index 72980c3..4d677ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "libc" version = "0.2.155" @@ -12,5 +18,6 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" name = "utils-debug-c-lib" version = "0.1.0" dependencies = [ + "dotenv", "libc", ] diff --git a/Cargo.toml b/Cargo.toml index 837c7be..87392b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,9 @@ version = "0.1.0" edition = "2021" build = "build.rs" +[build] +rustflags = "-L ./lib" + [dependencies] +dotenv = "0.15" libc = "0.2" diff --git a/README.md b/README.md index 16fff43..91ec9d6 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,23 @@ ## Setup - Installer le [package FSV](https://industriels.sesam-vitale.fr/group/fournitures-sesam-vitale) -- Ajouter le path des librairies FSV à `LD_LIBRARY_PATH` : `export LD_LIBRARY_PATH=/path/to/your/library:$LD_LIBRARY_PATH` + - Linux : ajouter le path des librairies FSV à la variable d'environnement `LD_LIBRARY_PATH` avant execution + - Windows : ajouter le path des librairies FSV à la variable d'environnement `PATH` avant execution - Installer la [CryptolibCPS](https://industriels.sesam-vitale.fr/group/galss-cryptolib-cps) - Fourni l'utilitaire "CPS Gestion" pour obtenir des informations sur le lecteur de carte, etc. - - Linux : `cpgeslux` \ No newline at end of file + - Linux : `cpgeslux` + +- Créer un fichier `.env` en s'inspirant d'un des fichiers d'exemple (`.env.linux.example`, `.env.win.example`...) + +## C Compilation + +Pour compiler les fichiers de librairie : + +- Windows : `.\build.bat` +- Linux : `make` + +Pour nettoyer le dossier `./lib` : + +- Windows : `.\build.bat /clean` +- Linux : `make clean` \ No newline at end of file diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..aecec45 --- /dev/null +++ b/build.bat @@ -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 diff --git a/build.rs b/build.rs index eb6d53f..2f26f67 100644 --- a/build.rs +++ b/build.rs @@ -1,9 +1,32 @@ -fn main() { - println!("cargo:rustc-link-search=native=./lib"); - println!("cargo:rustc-link-lib=static=p4pillondebuglib"); - println!("cargo:rerun-if-changed=lib/libp4pillondebuglib.a"); +// use std::env; +// use std::path::PathBuf; - println!("cargo:rustc-link-search=native=/opt/santesocial/fsv/1.40.13/lib"); - println!("cargo:rustc-link-lib=dylib=ssvlux64"); - println!("cargo:rerun-if-changed=/opt/santesocial/fsv/1.40.13/lib/libssvlux64.so"); +fn main() { + // --- OLD VERSION --- + // In fact, the commented code is not necessary + // Indeed, the static library is automatically found + // when the directory is provided by rustflags in Cargo.toml + // The dynamic library is found in the PATH or LD_LIBRARY_PATH + + // let static_lib_path = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("lib"); + // println!("cargo:rustc-link-search=native={}", static_lib_path.display()); + // println!("cargo:rustc-link-lib=static=p4pillondebuglib"); + // println!("cargo:rerun-if-changed={}", static_lib_path.join("libp4pillondebuglib.lib").display()); + + // let dynamic_lib_path = PathBuf::from("C:/Program Files/santesocial/fsv/1.40.13/lib"); + // println!("cargo:rustc-link-search=native={}", dynamic_lib_path.display()); + // println!("cargo:rustc-link-lib=dylib=ssvw64"); + // println!("cargo:rerun-if-changed={}", dynamic_lib_path.join("ssvw64.dll").display()); + + // --- NEW VERSION --- + + // Cross-platform libraries + println!("cargo:rustc-link-lib=static=p4pillondebuglib"); + + // Target-specific libraries + if cfg!(target_os = "windows") { + println!("cargo:rustc-link-lib=dylib=ssvw64"); + } else if cfg!(target_os = "linux") { + println!("cargo:rustc-link-lib=dylib=ssvlux64"); + } } diff --git a/lib/p4pillondebuglib.lib b/lib/p4pillondebuglib.lib new file mode 100644 index 0000000..f14f1b0 Binary files /dev/null and b/lib/p4pillondebuglib.lib differ diff --git a/lib/p4pillondebuglib.obj b/lib/p4pillondebuglib.obj new file mode 100644 index 0000000..6af47c7 Binary files /dev/null and b/lib/p4pillondebuglib.obj differ diff --git a/lib/ssvw64.exp b/lib/ssvw64.exp new file mode 100644 index 0000000..6276f9d Binary files /dev/null and b/lib/ssvw64.exp differ diff --git a/lib/ssvw64.lib b/lib/ssvw64.lib new file mode 100644 index 0000000..87b44b5 Binary files /dev/null and b/lib/ssvw64.lib differ diff --git a/src/ssvlib_demo.rs b/src/ssvlib_demo.rs index cccee0c..9dd6f3e 100644 --- a/src/ssvlib_demo.rs +++ b/src/ssvlib_demo.rs @@ -1,10 +1,13 @@ extern crate libc; +extern crate dotenv; use libc::{ c_char, c_void, c_ushort, size_t }; use std::ffi::CString; use std::ptr; -#[link(name = "ssvlux64")] +use dotenv::dotenv; +use std::env; + extern "C" { 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; @@ -12,7 +15,8 @@ extern "C" { } 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 { let result = SSV_InitLIB2(ini.as_ptr()); println!("SSV_InitLIB2 result: {}", result); @@ -68,6 +72,8 @@ fn ssv_lire_config() { } pub fn demo() { + dotenv().ok(); + println!("------- Demo for the SSV library --------"); ssv_init_lib_2(); diff --git a/src/ssvw64.def b/src/ssvw64.def new file mode 100644 index 0000000..4d66637 --- /dev/null +++ b/src/ssvw64.def @@ -0,0 +1,5 @@ +LIBRARY "ssvw64" +EXPORTS + SSV_InitLIB2 + SSV_LireCartePS + SSV_LireConfig