Skip to content

Commit 5e7dd9e

Browse files
committedFeb 8, 2025
fix(sys): work around missing UNC path support in MSVC
`std::fs::canonicalize` always converts paths to UNC on Windows. However, a plenty of software lacks support for this naming convention, notably Microsoft's C/C++ Compiler. `dunce::canonicalize` is a commonly used solution that picks the most compatible path representation on Windows and calls `fs::canonicalize` on any other platform.
1 parent a542225 commit 5e7dd9e

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed
 

‎Cargo.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎nginx-sys/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ rust-version.workspace = true
2020
bindgen = "0.71"
2121
cc = "1.2.0"
2222
duct = { version = "0.13.7", optional = true }
23+
dunce = "1.0.5"
2324
flate2 = { version = "1.0.28", optional = true }
2425
# Disable non-ASCII domain names support in ureq. We don't need it for any
2526
# of the 4 domains the buildscript interacts with.

‎nginx-sys/build/main.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const NGX_CONF_OS: &[&str] = &[
6060
/// NGINX in a subdirectory with the project.
6161
fn main() -> Result<(), Box<dyn StdError>> {
6262
let nginx_build_dir = match std::env::var("NGX_OBJS") {
63-
Ok(v) => PathBuf::from(v).canonicalize()?,
63+
Ok(v) => dunce::canonicalize(v)?,
6464
#[cfg(feature = "vendored")]
6565
Err(_) => vendored::build()?,
6666
#[cfg(not(feature = "vendored"))]
@@ -170,10 +170,7 @@ fn parse_includes_from_makefile(nginx_autoconf_makefile_path: &PathBuf) -> Vec<P
170170
.parent()
171171
.expect("makefile path has no parent")
172172
.parent()
173-
.expect("objs dir has no parent")
174-
.to_path_buf()
175-
.canonicalize()
176-
.expect("Unable to canonicalize makefile path");
173+
.expect("objs dir has no parent");
177174

178175
includes
179176
.into_iter()
@@ -185,7 +182,9 @@ fn parse_includes_from_makefile(nginx_autoconf_makefile_path: &PathBuf) -> Vec<P
185182
makefile_dir.join(path)
186183
}
187184
})
188-
.collect()
185+
.map(dunce::canonicalize)
186+
.collect::<Result<Vec<_>, _>>()
187+
.expect("canonicalize include paths")
189188
}
190189

191190
/// Collect info about the nginx configuration and expose it to the dependents via

0 commit comments

Comments
 (0)
Failed to load comments.