chore: Make the build works on linux and windows (+ details in README.md)

This commit is contained in:
Florian Briand 2024-07-06 11:07:53 +02:00
parent 078523ebad
commit df53e8bd23
Signed by: florian_briand
GPG Key ID: CC981B9E6B98E70B
5 changed files with 58 additions and 42 deletions

View File

@ -4,9 +4,6 @@ version = "0.1.0"
edition = "2021" edition = "2021"
build = "build.rs" build = "build.rs"
[build]
rustflags = "-L ./lib"
[dependencies] [dependencies]
dotenv = "0.15" dotenv = "0.15"
libc = "0.2" libc = "0.2"

View File

@ -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 ## Setup
- Installer le [package FSV](https://industriels.sesam-vitale.fr/group/fournitures-sesam-vitale) - Créer et éditer un fichier `.env` en s'inspirant d'un des fichiers d'exemple (`.env.linux.example`, `.env.win.example`...)
- 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) ### Windows
- Fourni l'utilitaire "CPS Gestion" pour obtenir des informations sur le lecteur de carte, etc.
- Linux : `cpgeslux`
- 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 : Pour compiler les fichiers de librairie :
- Windows : `.\build.bat` - Windows : `.\make.bat`
- Linux : `make` - Linux : `make`
Pour nettoyer le dossier `./lib` : Pour nettoyer le dossier `./lib` :
- Windows : `.\build.bat /clean` - Windows : `.\make.bat /clean`
- Linux : `make 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`)

View File

@ -1,32 +1,17 @@
// use std::env; use std::env;
// use std::path::PathBuf; use std::path::PathBuf;
fn main() { 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") { if cfg!(target_os = "windows") {
println!("cargo:rustc-link-lib=dylib=ssvw64"); println!("cargo::rustc-link-lib=static=p4pillondebuglib");
println!("cargo::rustc-link-lib=dylib=ssvw64");
} else if cfg!(target_os = "linux") { } 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");
} }
} }

Binary file not shown.

View File