1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
From c9d0a4df3dbad5ed6cf1dd6d70e70f926cf42bb0 Mon Sep 17 00:00:00 2001
From: stuebinm <stuebinm@disroot.org>
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
|