Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion nginx-src/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "nginx-src"
# Version format: <NGINX major>.<NGINX minor>.<crate patch>+<NGINX version>
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"
Expand Down
21 changes: 12 additions & 9 deletions nginx-src/src/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,26 @@ static VERIFIER: LazyLock<Option<SignatureVerifier>> = LazyLock::new(|| {
.ok()
});

fn make_cache_dir() -> io::Result<PathBuf> {
let base_dir = env::var("CARGO_MANIFEST_DIR")
static CACHE_DIR: LazyLock<PathBuf> = 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<PathBuf, Box<dyn StdError + Send + Sync>> {
Expand Down Expand Up @@ -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 {
Expand All @@ -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}"));
Expand Down
2 changes: 1 addition & 1 deletion nginx-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading