From e5f14a7c7df75d7844a1801aba122cca08b04577 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Tue, 9 Sep 2025 14:18:09 -0700 Subject: [PATCH 1/2] fix(src): create CACHE_DIR on demand Also, move default location to the OUT_DIR of nginx-sys. This should fix the build with read-only source directory. Fixes #85. --- nginx-src/src/download.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/nginx-src/src/download.rs b/nginx-src/src/download.rs index a63986e5..017d37ee 100644 --- a/nginx-src/src/download.rs +++ b/nginx-src/src/download.rs @@ -116,22 +116,26 @@ static VERIFIER: LazyLock> = LazyLock::new(|| { .ok() }); -fn make_cache_dir() -> io::Result { - let base_dir = env::var("CARGO_MANIFEST_DIR") +static CACHE_DIR: LazyLock = LazyLock::new(|| { + let base_dir = env::var("OUT_DIR") .map(PathBuf::from) .unwrap_or_else(|_| env::current_dir().expect("Failed to get current directory")); - // Choose `.cache` relative to the manifest directory (nginx-src) as the default cache directory + // Choose `.cache` relative to the OUT_DIR of the caller (nginx-sys) as the default cache directory // Environment variable `CACHE_DIR` overrides this // Recommendation: set env "CACHE_DIR = { value = ".cache", relative = true }" in // `.cargo/config.toml` in your project let cache_dir = env::var("CACHE_DIR") .map(PathBuf::from) .unwrap_or(base_dir.join(".cache")); + if !cache_dir.exists() { - fs::create_dir_all(&cache_dir)?; + fs::create_dir_all(&cache_dir) + .map_err(|err| format!("Failed to create {cache_dir:?}: {err}")) + .unwrap(); } - Ok(cache_dir) -} + + cache_dir +}); /// Downloads a tarball from the specified URL into the `.cache` directory. fn download(cache_dir: &Path, url: &str) -> Result> { @@ -228,12 +232,11 @@ pub fn prepare(source_dir: &Path, build_dir: &Path) -> io::Result<(PathBuf, Vec< fs::create_dir_all(&extract_output_base_dir)?; } - let cache_dir = make_cache_dir()?; let mut options = vec![]; // Download NGINX only if NGX_VERSION is set. let source_dir = if let Ok(version) = env::var(NGINX_SOURCE.variable) { - let archive_path = get_archive(&cache_dir, &NGINX_SOURCE, version.as_str())?; + let archive_path = get_archive(&CACHE_DIR, &NGINX_SOURCE, version.as_str())?; let output_base_dir: PathBuf = env::var("OUT_DIR").unwrap().into(); extract_archive(&archive_path, &output_base_dir)? } else { @@ -246,7 +249,7 @@ pub fn prepare(source_dir: &Path, build_dir: &Path) -> io::Result<(PathBuf, Vec< continue; }; - let archive_path = get_archive(&cache_dir, source, &requested)?; + let archive_path = get_archive(&CACHE_DIR, source, &requested)?; let output_dir = extract_archive(&archive_path, &extract_output_base_dir)?; let output_dir = output_dir.to_string_lossy(); options.push(format!("--with-{name}={output_dir}")); From c2cc9c87c1ad15d57404613e4d639f0c27838b65 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Tue, 9 Sep 2025 15:29:28 -0700 Subject: [PATCH 2/2] release: nginx-src 1.28.1+1.28.0 --- Cargo.lock | 2 +- nginx-src/Cargo.toml | 2 +- nginx-sys/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 98c34967..a8c77aff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -569,7 +569,7 @@ dependencies = [ [[package]] name = "nginx-src" -version = "1.28.0+1.28.0" +version = "1.28.1+1.28.0" dependencies = [ "duct", "flate2", diff --git a/nginx-src/Cargo.toml b/nginx-src/Cargo.toml index 4ac31046..1b9d33fe 100644 --- a/nginx-src/Cargo.toml +++ b/nginx-src/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "nginx-src" # Version format: ..+ -version = "1.28.0+1.28.0" +version = "1.28.1+1.28.0" # Crate sources are licensed under Apache-2.0, with exception of the # NGINX submodlue that is redistributed under BSD-2-Clause. license = "Apache-2.0 AND BSD-2-Clause" diff --git a/nginx-sys/Cargo.toml b/nginx-sys/Cargo.toml index 4c2ce3ed..73e7cae9 100644 --- a/nginx-sys/Cargo.toml +++ b/nginx-sys/Cargo.toml @@ -29,7 +29,7 @@ bindgen = "0.72" cc = "1.2.0" dunce = "1.0.5" regex = "1.11.1" -nginx-src = { version = "~1.28.0", optional = true, path = "../nginx-src" } +nginx-src = { version = "~1.28.1", optional = true, path = "../nginx-src" } shlex = "1.3" [features]