Skip to content

Commit 16da8a4

Browse files
committed
feat(sys): make deps required for building Nginx optional
These dependencies are not necessary when using a prebuilt Nginx tree.
1 parent 39383ad commit 16da8a4

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ keywords = ["nginx", "module", "sys"]
2121
[dependencies]
2222
nginx-sys = { path = "nginx-sys", version = "0.5.0"}
2323

24+
[features]
25+
default = ["nginx-sys/vendored"]
26+
2427
[badges]
2528
maintenance = { status = "experimental" }
2629

nginx-sys/Cargo.toml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ crate-type = ["staticlib", "rlib"]
1717

1818
[build-dependencies]
1919
bindgen = "0.69.4"
20-
which = "6.0.0"
21-
duct = "0.13.7"
22-
ureq = { version = "2.9.6", features = ["tls"] }
23-
flate2 = "1.0.28"
24-
tar = "0.4.40"
20+
duct = { version = "0.13.7", optional = true }
21+
flate2 = { version = "1.0.28", optional = true }
22+
tar = { version = "0.4.40", optional = true }
23+
ureq = { version = "2.9.6", features = ["tls"], optional = true }
24+
which = { version = "6.0.0", optional = true }
25+
26+
[features]
27+
vendored = ["dep:which", "dep:duct", "dep:ureq", "dep:flate2", "dep:tar"]

nginx-sys/build/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::error::Error as StdError;
55
use std::fs::read_to_string;
66
use std::path::PathBuf;
77

8+
#[cfg(feature = "vendored")]
89
mod vendored;
910

1011
const ENV_VARS_TRIGGERING_RECOMPILE: [&str; 2] = ["OUT_DIR", "NGX_OBJS"];
@@ -14,10 +15,12 @@ const ENV_VARS_TRIGGERING_RECOMPILE: [&str; 2] = ["OUT_DIR", "NGX_OBJS"];
1415
/// extract them, execute autoconf `configure` for NGINX, compile NGINX and finally install
1516
/// NGINX in a subdirectory with the project.
1617
fn main() -> Result<(), Box<dyn StdError>> {
17-
let nginx_build_dir = if let Ok(v) = env::var("NGX_OBJS") {
18-
PathBuf::from(v).canonicalize()?
19-
} else {
20-
vendored::build()?
18+
let nginx_build_dir = match std::env::var("NGX_OBJS") {
19+
Ok(v) => PathBuf::from(v).canonicalize()?,
20+
#[cfg(feature = "vendored")]
21+
Err(_) => vendored::build()?,
22+
#[cfg(not(feature = "vendored"))]
23+
Err(_) => panic!("\"nginx-sys/vendored\" feature is disabled and NGX_OBJS is not specified"),
2124
};
2225
// Hint cargo to rebuild if any of the these environment variables values change
2326
// because they will trigger a recompilation of NGINX with different parameters

0 commit comments

Comments
 (0)