Skip to content

Commit

Permalink
Search for nginx folder based on CARGO_MANIFEST_DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
gabioprisan committed Oct 25, 2023
1 parent af739c5 commit f5c2a86
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
apt install -y curl build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev libgd-dev libxml2 libxml2-dev uuid-dev clang
curl http://nginx.org/download/nginx-1.25.2.tar.gz | tar xz
ls -l
ls -l nginx-1.25.2
echo $PWD
cargo build --verbose
- name: Run tests
Expand Down
15 changes: 14 additions & 1 deletion nginx_module/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,18 @@ fn main() {

fn search_nginx_root_folder() -> String {
fn check_nginx_root(path: &Path) -> bool {
let mut debug = false;
if path.ends_with("nginx-1.25.2") {
println!("cargo:warning=Testing nginx folder");
debug = true;
}
INCLUDE_SUBDIRS.iter().all(|subdir| {
if debug {
let subdir_path = [path, Path::new(subdir)]
.iter()
.collect::<PathBuf>();
println!("cargo:warning={subdir} is dir: {}", subdir_path.is_dir())
}
[path, Path::new(subdir)]
.iter()
.collect::<PathBuf>()
Expand All @@ -96,15 +107,17 @@ fn search_nginx_root_folder() -> String {

// First, try to find the include folders in any of the parent folders of this folder,
// This is the case when this is a submodule of nginx
let manifest_dir = env!("CARGO_MANIFEST_DIR");
for base in base_locations {
let folder = base.to_string();
let folder = format!("{manifest_dir}/{base}");
if check_nginx_root(Path::new(&folder)) {
return folder;
}
}

// If we are not a nginx submodule, try to find the folder side by side
for base in base_locations {
let base = format!("{manifest_dir}/{base}");
for entry in std::fs::read_dir(base)
.expect("Cannot read directory")
.flatten()
Expand Down

0 comments on commit f5c2a86

Please sign in to comment.