Skip to content

Commit ecfd561

Browse files
committed
refactor: use build metadata to test
1 parent b8377d0 commit ecfd561

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

nginx-sys/build.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,19 @@ fn main() -> Result<(), Box<dyn StdError>> {
132132
}
133133
println!("Verified GPG permissions");
134134
// Configure and Compile NGINX
135-
let (_nginx_install_dir, nginx_src_dir) = compile_nginx(&cache_dir)?;
135+
let (nginx_install_dir, nginx_src_dir) = compile_nginx(&cache_dir)?;
136136
// Hint cargo to rebuild if any of the these environment variables values change
137137
// because they will trigger a recompilation of NGINX with different parameters
138138
for var in ENV_VARS_TRIGGERING_RECOMPILE {
139-
println!("cargo:rerun-if-env-changed={var}");
139+
println!("cargo::rerun-if-env-changed={var}");
140140
}
141-
println!("cargo:rerun-if-changed=build.rs");
142-
println!("cargo:rerun-if-changed=wrapper.h");
141+
println!("cargo::rerun-if-changed=build.rs");
142+
println!("cargo::rerun-if-changed=wrapper.h");
143+
// Provide build metadata for integration tests
144+
println!(
145+
"cargo::rustc-env=NGINX_SYS_NGINX_INSTALL_DIR={}",
146+
nginx_install_dir.display()
147+
);
143148
// Read autoconf generated makefile for NGINX and generate Rust bindings based on its includes
144149
generate_binding(nginx_src_dir);
145150
Ok(())

nginx-sys/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,3 +206,9 @@ pub unsafe fn add_to_ngx_table(
206206
table.lowcase_key = str_to_uchar(pool, String::from(key).to_ascii_lowercase().as_str());
207207
})
208208
}
209+
210+
/// Provide build metadatas.
211+
pub mod metadata {
212+
/// The path to the Nginx directory used to generate bindings. This constants is aimed at integration tests.
213+
pub const NGINX_INSTALL_DIR: &str = env!("NGINX_SYS_NGINX_INSTALL_DIR");
214+
}

tests/build.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/log_test.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
use std::env;
21
use std::fs;
32
use std::io::Result;
43
use std::process::Command;
54
use std::process::Output;
65

7-
const NGX_DEFAULT_VERSION: &str = "1.24.0";
86
const NGINX_BIN: &str = "sbin/nginx";
97
const NGINX_CONFIG: &str = "conf/nginx.conf";
108

@@ -16,12 +14,9 @@ pub struct Nginx {
1614
impl Default for Nginx {
1715
/// create nginx with default
1816
fn default() -> Nginx {
19-
let path = env::current_dir().unwrap();
20-
let version = env::var("NGX_VERSION").unwrap_or(NGX_DEFAULT_VERSION.into());
21-
let platform = target_triple::TARGET;
22-
let ngx_path = format!(".cache/nginx/{}/{}", version, platform);
23-
let install_path = format!("{}/{}", path.display(), ngx_path);
24-
Nginx { install_path }
17+
Nginx {
18+
install_path: nginx_sys::metadata::NGINX_INSTALL_DIR.into(),
19+
}
2520
}
2621
}
2722

0 commit comments

Comments
 (0)