Skip to content

Commit

Permalink
make daemon support optional behind a cargo feature (#197)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
stuebinm authored May 6, 2024
1 parent f50bee8 commit a7237ae
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 8 deletions.
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 15 additions & 3 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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(())
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod custom_rules;
#[cfg(feature = "daemon")]
pub mod daemon;
pub mod issues;
pub mod metadatas;
Expand Down

0 comments on commit a7237ae

Please sign in to comment.