windows-bindgen: containing root namespace in package generation target causes panic
Author: paring-chanCreated Sep 17, 2026Updated Sep 18, 2026
Labelsquestion
Summary
root namespace such as Windows cause panic on Option::None
temporary fix at https://github.com/paring-chan/windows-rs/commit/2f384c296514e8172e5b018fe35404fc3eb6701e
Crate manifest
windows-bindgen = { path = "https://github.com/microsoft/windows-rs" }Crate code
use std::{io::Write, path::PathBuf};
use serde::Deserialize;
#[derive(Deserialize)]
#[serde(rename_all = "PascalCase")]
struct VersionInfo {
release: Release,
runtime: Runtime,
}
#[derive(Deserialize)]
#[serde(rename_all = "PascalCase")]
struct ReleaseMajorMinor {
#[serde(rename = "HexUInt32")]
hex_u32: String,
}
#[derive(Deserialize)]
#[serde(rename_all = "PascalCase")]
struct Release {
major_minor: ReleaseMajorMinor,
version_tag: String,
}
#[derive(Deserialize)]
struct RuntimeVersion {
#[serde(rename = "HexUInt16")]
hex_u64: String,
}
#[derive(Deserialize)]
#[serde(rename_all = "PascalCase")]
struct Runtime {
version: RuntimeVersion,
}
fn main() {
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let root = manifest_dir.join("../..");
let winrt = root.join("vendor/nuget/microsoft.windowsappsdk.runtime.2.5.1");
let version_info_str =
std::fs::read_to_string(winrt.join("WindowsAppSDK-VersionInfo.json")).unwrap();
let version_info = serde_json::from_str::<VersionInfo>(
version_info_str
.strip_prefix('\\\u{feff}')
.unwrap_or(&version_info_str),
)
.unwrap();
std::fs::File::create("crates/windows-app-binding/src/version.rs")
.unwrap()
.write_all(
format!(
r#"pub const WINDOWSAPPSDK_RELEASE_MAJORMINOR: u32 = {};
pub const WINDOWSAPPSDK_RELEASE_VERSION_TAG: windows_core::PCWSTR = windows_core::w!({:?});
pub const WINDOWSAPPSDK_RUNTIME_VERSION_UINT64: u64 = {};
"#,
version_info.release.major_minor.hex_u32,
version_info.release.version_tag,
version_info.runtime.version.hex_u64
)
.as_bytes(),
)
.unwrap();
windows_bindgen::bindgen([
"--etc",
"crates/windows-app-bindgen/bindings.txt",
"--package",
"--out",
"crates/windows-app-binding",
]);
}bindings.txt
--in
default
vendor/winappsdk/win10-x64/Microsoft.WindowsAppRuntime.2
vendor/nuget/microsoft.web.webview2.1.0.4255-prerelease/lib
--implement
--filter
Microsoft.UI.Xaml.Application
Microsoft.UI.Xaml.Application.Start
Microsoft.UI.Windowing.AppWindow
Microsoft.UI.Xaml.ApplicationInitializationCallback
Microsoft.UI.Xaml.Window
Microsoft.UI.Composition.SystemBackdrops.MicaControllerAddding Microsoft.UI.Composition.SystemBackdrops.MicaController causes the panic
Source: microsoft/windows-rs