From d963c46ec1626f1992a30edc2105502a79ad2099 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Mon, 15 Apr 2024 21:23:07 +0200 Subject: package transport-validator this is the rust tool used by the french ministry for transport (deployed at https://transport.data.gouv.fr/validation), patched to not include the server mode it usually has (i don't want to constantly compile another copy of actix-web) --- .../transport-validator-without-daemon.patch | 123 +++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 pkgs/patches/transport-validator-without-daemon.patch (limited to 'pkgs/patches/transport-validator-without-daemon.patch') diff --git a/pkgs/patches/transport-validator-without-daemon.patch b/pkgs/patches/transport-validator-without-daemon.patch new file mode 100644 index 0000000..1703cbe --- /dev/null +++ b/pkgs/patches/transport-validator-without-daemon.patch @@ -0,0 +1,123 @@ +From c9d0a4df3dbad5ed6cf1dd6d70e70f926cf42bb0 Mon Sep 17 00:00:00 2001 +From: stuebinm +Date: Mon, 15 Apr 2024 21:01:27 +0200 +Subject: [PATCH] make daemon support optional behind a cargo feature + +This greatly saves on compile times and binary size +(282 vs. 181 crates, and 141 MiB vs 47 MiB for debug builds, +8 MiB vs 3.2 MiB for release builds) +--- + Cargo.toml | 15 ++++++++++----- + readme.md | 6 ++++++ + src/bin/main.rs | 18 +++++++++++++++--- + src/lib.rs | 1 + + 4 files changed, 32 insertions(+), 8 deletions(-) + +diff --git a/Cargo.toml b/Cargo.toml +index df15b04..94c9e19 100644 +--- a/Cargo.toml ++++ b/Cargo.toml +@@ -9,14 +9,19 @@ lto = true # Enable Link Time Optimization + codegen-units = 1 # Reduce number of codegen units to increase optimizations. + panic = 'abort' # Abort on panic + ++[features] ++default = ["daemon"] ++daemon = ["actix-web", "actix-rt", "futures", "read-url", "env_logger"] ++read-url = ["gtfs-structures/read-url"] ++ + [dependencies] + chrono = { version = "0.4", features = ["serde"] } + chrono-tz = "0.8" +-env_logger = "0.10" ++env_logger = { version = "0.10", optional = true } + anyhow = "1" +-futures = "0.3" ++futures = { version = "0.3", optional = true } + geo = "0.27" +-gtfs-structures = "0.40" ++gtfs-structures = { version = "0.40", default-features = false } + iso4217 = "0.3" + isolang = "2.1" + itertools = "0.12" +@@ -26,8 +31,8 @@ serde_json = "1.0" + serde_yaml = "0.9" + structopt = "0.3" + url = "2" +-actix-web = "4.0" +-actix-rt = "2" ++actix-web = { version = "4.0", optional = true } ++actix-rt = { version = "2", optional = true } + geojson = "0.24" + rgb = "0.8" + +diff --git a/readme.md b/readme.md +index 667a2f1..f8e175b 100644 +--- a/readme.md ++++ b/readme.md +@@ -317,6 +317,12 @@ cargo run --release -- -i some_gtfs.zip + cargo run --release -- -i https://example.com/network.gfts + ``` + ++If you do not intend to run the validator as a dæmon, it can be compiled without dæmon support, saving on compile time and binary size: ++ ++``` ++cargo run --release --no-default-features -- -i some_gtfs.zip ++``` ++ + ### Run as a dæmon + + The validator can run as a HTTP dæmon to validate any file from a url. +diff --git a/src/bin/main.rs b/src/bin/main.rs +index 52d93a9..e9bd7f2 100644 +--- a/src/bin/main.rs ++++ b/src/bin/main.rs +@@ -1,4 +1,6 @@ +-use validator::{custom_rules, daemon, validate}; ++#[cfg(feature = "daemon")] ++use validator::daemon; ++use validator::{custom_rules, validate}; + + use structopt::clap::arg_enum; + use structopt::StructOpt; +@@ -45,6 +47,7 @@ struct Opt { + } + + fn main() -> Result<(), anyhow::Error> { ++ #[cfg(feature = "daemon")] + env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init(); + + let opt = Opt::from_args(); +@@ -59,8 +62,17 @@ fn main() -> Result<(), anyhow::Error> { + }; + println!("{}", serialized); + } else { +- log::info!("Starting the validator as a dæmon"); +- daemon::run_server()?; ++ #[cfg(feature = "daemon")] ++ { ++ log::info!("Starting the validator as a dæmon"); ++ daemon::run_server()?; ++ } ++ #[cfg(not(feature = "daemon"))] ++ { ++ eprintln!("transport-validator was compiled without support for running as daemon."); ++ eprintln!("use -i to supply a local file to test instead."); ++ std::process::exit(1); ++ } + } + Ok(()) + } +diff --git a/src/lib.rs b/src/lib.rs +index d0e76f9..c4e8188 100644 +--- a/src/lib.rs ++++ b/src/lib.rs +@@ -1,4 +1,5 @@ + pub mod custom_rules; ++#[cfg(feature = "daemon")] + pub mod daemon; + pub mod issues; + pub mod metadatas; +-- +2.42.0 + -- cgit v1.2.3