Compare commits
2 Commits
4d34215aa5
...
c342d922a7
Author | SHA1 | Date | |
---|---|---|---|
|
c342d922a7 | ||
|
4a54846f47 |
11
README.md
11
README.md
@ -47,17 +47,6 @@ Si vous souhaitez lancer les composants séparément, les indications de lanceme
|
|||||||
- [app](crates/app/README.md)
|
- [app](crates/app/README.md)
|
||||||
- [sesam-vitale](crates/sesam-vitale/README.md)
|
- [sesam-vitale](crates/sesam-vitale/README.md)
|
||||||
|
|
||||||
## Rechargement automatique
|
|
||||||
|
|
||||||
Pour permettre de développer plus rapidement, il existe une librairie qui recompile automatiquement nos modifications en cours : [`cargo-watch`](https://github.com/watchexec/cargo-watch) permet de relancer une commande _Rust_ lorsqu'un fichier est modifié (example: `cargo run` --> `cargo watch -x run`).
|
|
||||||
|
|
||||||
La librairie ne fait pas partie des dépendances du projet, il faut donc l'installer avec la commande suivante :
|
|
||||||
```bash
|
|
||||||
cargo install cargo-watch
|
|
||||||
```
|
|
||||||
|
|
||||||
Le fichier [`.ignore`](./ignore) permet d'ignorer certains fichiers pour éviter de relancer la recompilation inutilement.
|
|
||||||
|
|
||||||
## Build
|
## Build
|
||||||
|
|
||||||
Packager le client desktop
|
Packager le client desktop
|
||||||
|
@ -13,3 +13,4 @@ serde = { version = "1.0.204", features = ["derive"] }
|
|||||||
tokio = { version = "1.39.1", features = ["macros", "rt-multi-thread"] }
|
tokio = { version = "1.39.1", features = ["macros", "rt-multi-thread"] }
|
||||||
tower-http = { version = "0.5.2", features = ["fs"] }
|
tower-http = { version = "0.5.2", features = ["fs"] }
|
||||||
tower-livereload = "0.9.3"
|
tower-livereload = "0.9.3"
|
||||||
|
|
||||||
|
@ -14,27 +14,16 @@
|
|||||||
cargo run --bin app
|
cargo run --bin app
|
||||||
```
|
```
|
||||||
|
|
||||||
## Rechargement automatique (_auto-reload_)
|
## L'auto-reload
|
||||||
|
|
||||||
Pour le projet `app`, nous utilisons en plus de `cargo-watch` ses librairies :
|
Pour permettre au projet de s'auto-recharger lors du développement, nous avons besoin de 2 librairies :
|
||||||
- [`systemfd`](https://github.com/mitsuhiko/systemfd) permet de redémarrer un serveur sans interrompre les connexions en cours, il transmet le descripteur de fichier du socket à une nouvelle instance du serveur (exemple: `cargo watch -x run` --> `systemfd --no-pid -s http::3000 -- cargo watch -x run`). Si le port est déjà pris il en prendra un autre.
|
|
||||||
- [`listenfd`](https://github.com/mitsuhiko/listenfd) permet, côté _Rust_, de démarrer un serveur en utilisant des connexions déjà ouvertes.
|
|
||||||
|
|
||||||
La librairie `systemfd` ne fait pas partie des dépendances du projet, il faut donc l'installer avec la commande suivante :
|
|
||||||
```bash
|
```bash
|
||||||
cargo install systemfd
|
cargo install cargo-watch systemfd
|
||||||
```
|
```
|
||||||
|
|
||||||
Pour notre application voici la commande à lancer :
|
Pour recompiler automatiquement le serveur lors de changement :
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
systemfd --no-pid -s http::3000 -- cargo watch -x 'run --bin app'
|
systemfd --no-pid -s http::3000 -- cargo watch -x 'run --bin app'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Chargement à chaud (_livereload_)
|
|
||||||
|
|
||||||
Pour que notre navigateur rafraîchisse automatique notre page lorsque le serveur a été recompilé, nous utilisons la librairie [`tower-livereload`](https://github.com/leotaku/tower-livereload).
|
|
||||||
|
|
||||||
A chaque changement, que ça soit sur du code en _Rust_, _HTML_, _CSS_ ou _JS_ alors le navigateur va recharger entièrement la page.
|
|
||||||
|
|
||||||
En Rust, il n'existe pas encore d'outil de _Hot Reload_ complet et intégré comme on en trouve dans d'autres environnements de développement web, comme pour _Node.js_.
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use ::app::get_router;
|
use ::app::get_router;
|
||||||
use axum::http::Request;
|
use axum::http::Request;
|
||||||
use listenfd::ListenFd;
|
|
||||||
use notify::Watcher;
|
use notify::Watcher;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use listenfd::ListenFd;
|
||||||
use tokio::net::TcpListener;
|
use tokio::net::TcpListener;
|
||||||
use tower_livereload::LiveReloadLayer;
|
use tower_livereload::LiveReloadLayer;
|
||||||
|
|
||||||
@ -20,13 +20,10 @@ async fn main() {
|
|||||||
let livereload = LiveReloadLayer::new();
|
let livereload = LiveReloadLayer::new();
|
||||||
let reloader = livereload.reloader();
|
let reloader = livereload.reloader();
|
||||||
|
|
||||||
let router =
|
let router = get_router(assets_path.as_path()).layer(livereload.request_predicate(not_htmx_predicate));
|
||||||
get_router(assets_path.as_path()).layer(livereload.request_predicate(not_htmx_predicate));
|
|
||||||
|
|
||||||
let mut watcher = notify::recommended_watcher(move |_| reloader.reload()).unwrap();
|
let mut watcher = notify::recommended_watcher(move |_| reloader.reload()).unwrap();
|
||||||
watcher
|
watcher.watch(&templates_path, notify::RecursiveMode::Recursive).unwrap();
|
||||||
.watch(&templates_path, notify::RecursiveMode::Recursive)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut listenfd = ListenFd::from_env();
|
let mut listenfd = ListenFd::from_env();
|
||||||
let listener = match listenfd.take_tcp_listener(0).unwrap() {
|
let listener = match listenfd.take_tcp_listener(0).unwrap() {
|
||||||
@ -42,7 +39,5 @@ async fn main() {
|
|||||||
println!("Listening on: http://{}", listener.local_addr().unwrap());
|
println!("Listening on: http://{}", listener.local_addr().unwrap());
|
||||||
|
|
||||||
// Run the server with the router
|
// Run the server with the router
|
||||||
axum::serve(listener, router.into_make_service())
|
axum::serve(listener, router.into_make_service()).await.unwrap();
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
@ -7,4 +7,4 @@ struct CpsResponse;
|
|||||||
|
|
||||||
pub async fn cps() -> impl IntoResponse {
|
pub async fn cps() -> impl IntoResponse {
|
||||||
CpsResponse.into_response()
|
CpsResponse.into_response()
|
||||||
}
|
}
|
@ -7,4 +7,4 @@ struct HomeResponse;
|
|||||||
|
|
||||||
pub async fn home() -> impl IntoResponse {
|
pub async fn home() -> impl IntoResponse {
|
||||||
HomeResponse.into_response()
|
HomeResponse.into_response()
|
||||||
}
|
}
|
@ -7,4 +7,4 @@ pub fn get_routes() -> Router {
|
|||||||
Router::new()
|
Router::new()
|
||||||
.route("/home", routing::get(home::home))
|
.route("/home", routing::get(home::home))
|
||||||
.route("/cps", routing::get(cps::cps))
|
.route("/cps", routing::get(cps::cps))
|
||||||
}
|
}
|
@ -11,10 +11,10 @@ struct HelloResponse {
|
|||||||
async fn hello() -> impl IntoResponse {
|
async fn hello() -> impl IntoResponse {
|
||||||
HelloResponse {
|
HelloResponse {
|
||||||
name: "Theo".to_string(),
|
name: "Theo".to_string(),
|
||||||
}
|
}.into_response()
|
||||||
.into_response()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_routes() -> Router {
|
pub fn get_routes() -> Router {
|
||||||
Router::new().route("/", routing::get(hello))
|
Router::new()
|
||||||
|
.route("/", routing::get(hello))
|
||||||
}
|
}
|
||||||
|
@ -25,9 +25,7 @@ impl MenuResponse {
|
|||||||
fn get_classes(&self, is_current_item: &bool) -> String {
|
fn get_classes(&self, is_current_item: &bool) -> String {
|
||||||
let common_classes = match self.mobile {
|
let common_classes = match self.mobile {
|
||||||
true => "block border-l-4 py-2 pl-3 pr-4 text-base font-medium".to_string(),
|
true => "block border-l-4 py-2 pl-3 pr-4 text-base font-medium".to_string(),
|
||||||
false => {
|
false => "inline-flex items-center border-b-2 px-1 pt-1 text-sm font-medium".to_string(),
|
||||||
"inline-flex items-center border-b-2 px-1 pt-1 text-sm font-medium".to_string()
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
match (self.mobile, is_current_item) {
|
match (self.mobile, is_current_item) {
|
||||||
(true, true) => common_classes + " border-indigo-500 bg-indigo-50 text-indigo-700",
|
(true, true) => common_classes + " border-indigo-500 bg-indigo-50 text-indigo-700",
|
||||||
@ -52,11 +50,11 @@ async fn menu(Query(params): Query<MenuParameters>) -> impl IntoResponse {
|
|||||||
href: "/pages/cps".to_string(),
|
href: "/pages/cps".to_string(),
|
||||||
current: false,
|
current: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}.into_response()
|
||||||
.into_response()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_routes() -> Router {
|
pub fn get_routes() -> Router {
|
||||||
Router::new().route("/menu", routing::get(menu))
|
Router::new()
|
||||||
|
.route("/menu", routing::get(menu))
|
||||||
}
|
}
|
||||||
|
@ -56,10 +56,10 @@ async fn menu(Query(params): Query<MenuParameters>) -> impl IntoResponse {
|
|||||||
current: false,
|
current: false,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}.into_response()
|
||||||
.into_response()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_routes() -> Router {
|
pub fn get_routes() -> Router {
|
||||||
Router::new().route("/menu", routing::get(menu))
|
Router::new()
|
||||||
}
|
.route("/menu", routing::get(menu))
|
||||||
|
}
|
@ -16,10 +16,7 @@ fn main() {
|
|||||||
|
|
||||||
// Add local lib directory to the linker search path (for def files and static libs)
|
// Add local lib directory to the linker search path (for def files and static libs)
|
||||||
let static_lib_path = manifest_path.join("lib");
|
let static_lib_path = manifest_path.join("lib");
|
||||||
println!(
|
println!("cargo::rustc-link-search=native={}", static_lib_path.display());
|
||||||
"cargo::rustc-link-search=native={}",
|
|
||||||
static_lib_path.display()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add the SESAM_FSV_LIB_PATH to the linker search path
|
// Add the SESAM_FSV_LIB_PATH to the linker search path
|
||||||
let fsv_lib_path = PathBuf::from(env::var("SESAM_FSV_LIB_PATH").unwrap());
|
let fsv_lib_path = PathBuf::from(env::var("SESAM_FSV_LIB_PATH").unwrap());
|
||||||
@ -34,9 +31,6 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Link the SESAM_FSV_SSVLIB dynamic library
|
// Link the SESAM_FSV_SSVLIB dynamic library
|
||||||
println!(
|
println!("cargo::rustc-link-lib=dylib={}", env::var("SESAM_FSV_SSVLIB").unwrap());
|
||||||
"cargo::rustc-link-lib=dylib={}",
|
|
||||||
env::var("SESAM_FSV_SSVLIB").unwrap()
|
|
||||||
);
|
|
||||||
// TODO : try `raw-dylib` instead of `dylib` on Windows to avoid the need of the `lib` headers compiled from the `def`
|
// TODO : try `raw-dylib` instead of `dylib` on Windows to avoid the need of the `lib` headers compiled from the `def`
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user