Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows-bindgen should generate no_std bindings by default #3366

Merged
merged 5 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 1 addition & 4 deletions crates/libs/bindgen/src/types/cpp_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,20 +369,17 @@ impl CppInterface {
}
}
}
#[cfg(feature = "std")]
#cfg
struct #implvtbl_ident<T: #impl_name> (core::marker::PhantomData<T>);
#[cfg(feature = "std")]
#cfg
impl<T: #impl_name> #implvtbl_ident<T> {
const VTABLE: #vtbl_name = #vtbl_name::new::<T>();
}
#[cfg(feature = "std")]
#cfg
impl #name {
pub fn new<'a, T: #impl_name>(this: &'a T) -> windows_core::ScopedInterface<'a, Self> {
let this = windows_core::ScopedHeap { vtable: &#implvtbl_ident::<T>::VTABLE as *const _ as *const _, this: this as *const _ as *const _ };
let this = core::mem::ManuallyDrop::new(Box::new(this));
let this = core::mem::ManuallyDrop::new(windows_core::imp::Box::new(this));
unsafe { windows_core::ScopedInterface::new(core::mem::transmute(&this.vtable)) }
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/libs/bindgen/src/types/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl Delegate {
invoke,
};
unsafe {
core::mem::transmute(Box::new(com))
core::mem::transmute(windows_core::imp::Box::new(com))
}
}
#invoke
Expand Down Expand Up @@ -158,7 +158,7 @@ impl Delegate {
let remaining = (*this).count.release();

if remaining == 0 {
let _ = Box::from_raw(this);
let _ = windows_core::imp::Box::from_raw(this);
}

remaining
Expand Down
5 changes: 4 additions & 1 deletion crates/libs/windows/src/extensions/Foundation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#[cfg(feature = "std")]
pub mod Async;
#[cfg(feature = "std")]
pub mod AsyncReady;
#[cfg(feature = "std")]
pub mod AsyncSpawn;
#[cfg(feature = "Foundation_Collections")]
#[cfg(all(feature = "std", feature = "Foundation_Collections"))]
pub mod Collections;
kennykerr marked this conversation as resolved.
Show resolved Hide resolved
#[cfg(feature = "Foundation_Numerics")]
pub mod Numerics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ impl Vector2 {
pub fn length_squared(&self) -> f32 {
self.dot(self)
}
#[cfg(feature = "std")]
kennykerr marked this conversation as resolved.
Show resolved Hide resolved
pub fn length(&self) -> f32 {
self.length_squared().sqrt()
}
#[cfg(feature = "std")]
pub fn distance(&self, value: &Self) -> f32 {
(self - value).length()
}
pub fn distance_squared(&self, value: &Self) -> f32 {
(self - value).length_squared()
}
#[cfg(feature = "std")]
pub fn normalize(&self) -> Self {
self / self.length()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ impl Vector3 {
pub fn length_squared(&self) -> f32 {
self.dot(self)
}
#[cfg(feature = "std")]
pub fn length(&self) -> f32 {
self.length_squared().sqrt()
}
#[cfg(feature = "std")]
pub fn distance(&self, value: &Self) -> f32 {
(self - value).length()
}
pub fn distance_squared(&self, value: &Self) -> f32 {
(self - value).length_squared()
}
#[cfg(feature = "std")]
pub fn normalize(&self) -> Self {
self / self.length()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,18 @@ impl Vector4 {
pub fn length_squared(&self) -> f32 {
self.dot(self)
}
#[cfg(feature = "std")]
pub fn length(&self) -> f32 {
self.length_squared().sqrt()
}
#[cfg(feature = "std")]
pub fn distance(&self, value: &Self) -> f32 {
(self - value).length()
}
pub fn distance_squared(&self, value: &Self) -> f32 {
(self - value).length_squared()
}
#[cfg(feature = "std")]
pub fn normalize(&self) -> Self {
self / self.length()
}
Expand Down
4 changes: 4 additions & 0 deletions crates/tests/misc/no_std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ default-features = false
[dependencies.windows]
path = "../../../libs/windows"
default-features = false
features = [
"Foundation_Collections",
"Win32_Graphics_Direct3D",
]
kennykerr marked this conversation as resolved.
Show resolved Hide resolved

[lints]
workspace = true