-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathbuild.rs
More file actions
67 lines (60 loc) · 2.57 KB
/
Copy pathbuild.rs
File metadata and controls
67 lines (60 loc) · 2.57 KB
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
/// Example buildscript for an nginx module.
///
/// Due to the limitations of cargo[1], this buildscript _requires_ adding `nginx-sys` to the
/// direct dependencies of your crate.
///
/// [1]: https://github.com/rust-lang/cargo/issues/3544
fn main() {
// Generate `ngx_os` and `ngx_feature` cfg values
// Specify acceptable values for `ngx_feature`
println!("cargo::rerun-if-env-changed=DEP_NGINX_FEATURES_CHECK");
println!(
"cargo::rustc-check-cfg=cfg(ngx_feature, values({}))",
std::env::var("DEP_NGINX_FEATURES_CHECK").unwrap_or("any()".to_string())
);
// Read feature flags detected by nginx-sys and pass to the compiler.
println!("cargo::rerun-if-env-changed=DEP_NGINX_FEATURES");
if let Ok(features) = std::env::var("DEP_NGINX_FEATURES") {
for feature in features.split(',').map(str::trim) {
println!("cargo::rustc-cfg=ngx_feature=\"{feature}\"");
}
}
// Specify acceptable values for `ngx_os`
println!("cargo::rerun-if-env-changed=DEP_NGINX_OS_CHECK");
println!(
"cargo::rustc-check-cfg=cfg(ngx_os, values({}))",
std::env::var("DEP_NGINX_OS_CHECK").unwrap_or("any()".to_string())
);
// Read operating system detected by nginx-sys and pass to the compiler.
println!("cargo::rerun-if-env-changed=DEP_NGINX_OS");
if let Ok(os) = std::env::var("DEP_NGINX_OS") {
println!("cargo::rustc-cfg=ngx_os=\"{os}\"");
}
// Generate cfg values for version checks
const VERSION_CHECKS: &[(u64, &str)] = &[
//
(1_021_001, "nginx1_21_1"),
(1_025_001, "nginx1_25_1"),
];
VERSION_CHECKS.iter().for_each(|check| println!("cargo::rustc-check-cfg=cfg({})", check.1));
println!("cargo::rerun-if-env-changed=DEP_NGINX_VERSION_NUMBER");
if let Ok(version) = std::env::var("DEP_NGINX_VERSION_NUMBER") {
let version: u64 = version.parse().unwrap();
for check in VERSION_CHECKS {
if version >= check.0 {
println!("cargo::rustc-cfg={}", check.1);
}
}
}
// Pass build directory to the tests
println!("cargo::rerun-if-env-changed=DEP_NGINX_BUILD_DIR");
if let Ok(build_dir) = std::env::var("DEP_NGINX_BUILD_DIR") {
println!("cargo::rustc-env=DEP_NGINX_BUILD_DIR={build_dir}");
}
// Generate required compiler flags
if cfg!(target_os = "macos") {
// https://stackoverflow.com/questions/28124221/error-linking-with-cc-failed-exit-code-1
println!("cargo::rustc-link-arg=-undefined");
println!("cargo::rustc-link-arg=dynamic_lookup");
}
}