From 27d63f467c9f3781b230551e865f1c6318f0fcfb Mon Sep 17 00:00:00 2001 From: Florian Briand Date: Sat, 6 Jul 2024 11:07:53 +0200 Subject: [PATCH] chore: Make the build works on linux and windows (+ details in README.md) --- Cargo.toml | 3 -- README.md | 60 +++++++++++++++++++++++++++++--------- build.rs | 40 +++++++++---------------- lib/libp4pillondebuglib.a | Bin 3474 -> 3474 bytes lib/p4pillondebuglib.lib | Bin 5656 -> 5656 bytes lib/p4pillondebuglib.obj | Bin 4896 -> 4896 bytes lib/ssvw64.exp | Bin 1149 -> 1149 bytes lib/ssvw64.lib | Bin 2104 -> 2104 bytes build.bat => make.bat | 0 9 files changed, 61 insertions(+), 42 deletions(-) rename build.bat => make.bat (100%) diff --git a/Cargo.toml b/Cargo.toml index 87392b0..58903ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,9 +4,6 @@ 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 91ec9d6..c5057f5 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,61 @@ -## À 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, à la compilation et à l'exécution, fournir le chemin d'installation de ces librairies + - 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 -- Installer le [package FSV](https://industriels.sesam-vitale.fr/group/fournitures-sesam-vitale) - - 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 +- Créer et éditer un fichier `.env` en s'inspirant d'un des fichiers d'exemple (`.env.linux.example`, `.env.win.example`...) -- 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` +### Windows -- Créer un fichier `.env` en s'inspirant d'un des fichiers d'exemple (`.env.linux.example`, `.env.win.example`...) +- Ajouter le chemin d'installation des librairies dynamiques fournies par le package FSV dans le `PATH` -## C Compilation +## Build + +### 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 : `.\build.bat` +- Windows : `.\make.bat` - Linux : `make` Pour nettoyer le dossier `./lib` : -- Windows : `.\build.bat /clean` -- Linux : `make clean` \ No newline at end of file +- Windows : `.\make.bat /clean` +- Linux : `make clean` + +### Compilation Rust + +`cargo build` + +Comme précisé précédemment, il peut être nécessaire de fournir le chemin d'installation des librairies dynamiques fournies par le package FSV à la compilation, en utilisant la variable d'environnement `RUSTFLAGS`. + +- Par exemple + - Linux :`RUSTFLAGS="-L /opt/santesocial/fsv/1.40.13/lib" cargo build` + - Windows : `cargo build` (pas besoin de `RUSTFLAGS` à condition que le chemin d'installation des librairies dynamiques soit dans le `PATH`) + +## Run + +`cargo run` + +Comme précisé précédemment, il peut être nécessaire de fournir le chemin d'installation des librairies dynamiques fournies par le package FSV à l'exécution. + +La commande `cargo run` provoquant également un build, il faudra également fournir la variable d'environnement `RUSTFLAGS` le cas échéant. + +- Par exemple + - Linux : `RUSTFLAGS="-L /opt/santesocial/fsv/1.40.13/lib" LD_LIBRARY_PATH="/opt/santesocial/fsv/1.40.13/lib" cargo run` + - Windows : `cargo run` (pas besoin de `RUSTFLAGS` ni de `PATH` à condition que le chemin d'installation des librairies dynamiques soit dans le `PATH`) diff --git a/build.rs b/build.rs index 2f26f67..f466ec9 100644 --- a/build.rs +++ b/build.rs @@ -1,32 +1,20 @@ -// use std::env; -// use std::path::PathBuf; +use std::env; +use std::path::PathBuf; 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"); + 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::rustc-link-lib=dylib=ssvw64"); } else if cfg!(target_os = "linux") { - println!("cargo:rustc-link-lib=dylib=ssvlux64"); + 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"); + + // let dynamic_lib_path = PathBuf::from("/opt/santesocial/fsv/1.40.13/lib"); + // println!("cargo::rustc-link-search=native={}", dynamic_lib_path.display()); + println!("cargo::rustc-link-lib=dylib=ssvlux64"); } } diff --git a/lib/libp4pillondebuglib.a b/lib/libp4pillondebuglib.a index e31fd853b1950f9a4c83e17bdf36bbd863f3ad49..e6b1046892ebf011194b8fff930631dd1c965ae9 100644 GIT binary patch delta 28 ecmbOvJxO|k44aXmse!rWM5P~4)@B99A|3#7(FcG4 delta 28 ecmbOvJxO|k44a{mp{0e`cp7`cMMlJ+55GrwvNsT#)t8?>zCP`rc7l9D1 delta 64 zcmbQCGec*BEUTf3p^3%h1}2G(R?>`cp7`cMMlJ+55GrwvNsYNBsblkhCP`rc8yOKQ diff --git a/lib/p4pillondebuglib.obj b/lib/p4pillondebuglib.obj index 6af47c74faf2a13257da48f2647ba992a0d0d490..5fe2c844344aae30edb381f7eedce36b96edb8cb 100644 GIT binary patch delta 16 XcmZ3Wwm^+NrA>$-iK}xXyQDAxDk}tO delta 16 XcmZ3Wwm^+NrA>&TC8=X0yQDAxEhGfu diff --git a/lib/ssvw64.exp b/lib/ssvw64.exp index 6276f9d30cbb7e31405cbe3389e51e4d4ce345a4..7a356d912b60a5ee12d4e2e5f86b16d74a8530d3 100644 GIT binary patch delta 23 dcmey%@t1==rHz>(iK}xWdnYrH+Bo?YGXP;F2tEJ+ delta 23 dcmey%@t1==rHz@PC8=W~dnYrH+Bo?YGXQF42`~Tv diff --git a/lib/ssvw64.lib b/lib/ssvw64.lib index 87b44b5c1b4aa4d5bf947ee09865939971392a36..f1dd03c7799391e719f0701a5ff9ec183f88f5f8 100644 GIT binary patch delta 186 zcmdlXutQ*iEUT%xp^?$#1SYYG7XJ~P%|VQujBu_Ra}rnQ=1!&`2qCe_b65nx!s}T$ zkc35zEKC$2Ab~5TjhO+cGwsggjV$t$S20OXR%CkzH&uMHHoGv$h{=xZW=Nuwp`t6< Nt&l|jLq$b7lmW5vFd+Z{ delta 186 zcmdlXutQ*iEUTf3p^3%h1SYYG7XJ~P%|VQujBu_Rb4yak=1!&`2qCe_b65nx!s}T$ zkc35zEKC$2Ab~5TjhO+cGwsggjV$t$S20OXR%CkzH&uMHHoGv$h{=xZW=Nuwp`t6< Nt&l|jLq$b7lmUH9GXDSo diff --git a/build.bat b/make.bat similarity index 100% rename from build.bat rename to make.bat