Skip to content

Commit a544b7d

Browse files
committed
Embed longPathAware manifest in the Windows executable
The Windows binary now embeds an application manifest declaring longPathAware, so the Win32 APIs handle paths longer than MAX_PATH and a path component exceeding the 255-char limit is reported as EINVAL instead of the whole path being rejected for length (ENOENT). The manifest is now compiled even when logo.ico is absent.
1 parent c49f3a8 commit a544b7d

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

build.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@ fn main() {
1212
"windows" => {
1313
println!("cargo:rerun-if-changed=logo.ico");
1414
let mut res = winresource::WindowsResource::new();
15+
// Opt into long path support so paths longer than MAX_PATH (260) are
16+
// handled by the Win32 APIs, and a path component over the 255-char
17+
// limit is reported as EINVAL rather than being rejected for length.
18+
res.set_manifest(WINDOWS_MANIFEST);
1519
if std::path::Path::new("logo.ico").exists() {
1620
res.set_icon("logo.ico");
1721
} else {
1822
println!("cargo:warning=logo.ico not found, skipping icon embedding");
19-
return;
2023
}
2124
res.compile()
2225
.map_err(|e| {
@@ -27,3 +30,21 @@ fn main() {
2730
_ => {}
2831
}
2932
}
33+
34+
/// Application manifest embedded into the Windows executable.
35+
const WINDOWS_MANIFEST: &str = r#"<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
36+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
37+
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
38+
<security>
39+
<requestedPrivileges>
40+
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
41+
</requestedPrivileges>
42+
</security>
43+
</trustInfo>
44+
<application xmlns="urn:schemas-microsoft-com:asm.v3">
45+
<windowsSettings>
46+
<longPathAware xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">true</longPathAware>
47+
</windowsSettings>
48+
</application>
49+
</assembly>
50+
"#;

0 commit comments

Comments
 (0)