|
| 1 | +/// Example buildscript for an nginx module. |
| 2 | +/// |
| 3 | +/// Due to the limitations of cargo[1], this buildscript _requires_ adding `nginx-sys` to the |
| 4 | +/// direct dependencies of your crate. |
| 5 | +/// |
| 6 | +/// [1]: https://github.com/rust-lang/cargo/issues/3544 |
| 7 | +fn main() { |
| 8 | + // Generate `ngx_os` and `ngx_feature` cfg values |
| 9 | + |
| 10 | + // Specify acceptable values for `ngx_feature` |
| 11 | + println!("cargo::rerun-if-env-changed=DEP_NGINX_FEATURES_CHECK"); |
| 12 | + println!( |
| 13 | + "cargo::rustc-check-cfg=cfg(ngx_feature, values({}))", |
| 14 | + std::env::var("DEP_NGINX_FEATURES_CHECK").unwrap_or("any()".to_string()) |
| 15 | + ); |
| 16 | + // Read feature flags detected by nginx-sys and pass to the compiler. |
| 17 | + println!("cargo::rerun-if-env-changed=DEP_NGINX_FEATURES"); |
| 18 | + if let Ok(features) = std::env::var("DEP_NGINX_FEATURES") { |
| 19 | + for feature in features.split(',').map(str::trim) { |
| 20 | + println!("cargo::rustc-cfg=ngx_feature=\"{}\"", feature); |
| 21 | + } |
| 22 | + } |
| 23 | + |
| 24 | + // Specify acceptable values for `ngx_os` |
| 25 | + println!("cargo::rerun-if-env-changed=DEP_NGINX_OS_CHECK"); |
| 26 | + println!( |
| 27 | + "cargo::rustc-check-cfg=cfg(ngx_os, values({}))", |
| 28 | + std::env::var("DEP_NGINX_OS_CHECK").unwrap_or("any()".to_string()) |
| 29 | + ); |
| 30 | + // Read operating system detected by nginx-sys and pass to the compiler. |
| 31 | + println!("cargo::rerun-if-env-changed=DEP_NGINX_OS"); |
| 32 | + if let Ok(os) = std::env::var("DEP_NGINX_OS") { |
| 33 | + println!("cargo::rustc-cfg=ngx_os=\"{}\"", os); |
| 34 | + } |
| 35 | + |
| 36 | + // Generate cfg values for version checks |
| 37 | + // println!("cargo::rustc-check-cfg=cfg(nginx1_27_0)"); |
| 38 | + // println!("cargo::rerun-if-env-changed=DEP_NGINX_VERSION_NUMBER"); |
| 39 | + // if let Ok(version) = std::env::var("DEP_NGINX_VERSION_NUMBER") { |
| 40 | + // let version: u64 = version.parse().unwrap(); |
| 41 | + // |
| 42 | + // if version >= 1_027_000 { |
| 43 | + // println!("cargo::rustc-cfg=nginx1_27_0"); |
| 44 | + // } |
| 45 | + // } |
| 46 | +} |
0 commit comments