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

Remove "implement" feature #3333

Merged
merged 4 commits into from
Oct 30, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 0 additions & 5 deletions crates/libs/bindgen/src/rust/extensions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,3 @@ pub fn gen_mod(_writer: &Writer, namespace: &str) -> TokenStream {
_ => quote!(),
}
}

/// Generates extension code that is subject to the `implement` feature for a specific namespace
pub fn gen_impl(_namespace: &str) -> TokenStream {
TokenStream::new()
}
7 changes: 5 additions & 2 deletions crates/libs/bindgen/src/rust/implements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::*;
use metadata::HasAttributes;

pub fn writer(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
if def.kind() != metadata::TypeKind::Interface
|| (!writer.implement && def.has_attribute("ExclusiveToAttribute"))
if !(def.kind() == metadata::TypeKind::Interface
&& (writer.implement || (writer.package && !def.has_attribute("ExclusiveToAttribute"))))
{
return quote! {};
}
Expand Down Expand Up @@ -190,12 +190,15 @@ pub fn writer(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
}
}
#[doc(hidden)]
#[cfg(feature = "std")]
#features
struct #implvtbl_ident<T: #impl_ident> (core::marker::PhantomData<T>);
#[cfg(feature = "std")]
#features
impl<T: #impl_ident> #implvtbl_ident<T> {
const VTABLE: #vtbl_ident = #vtbl_ident::new::<T>();
}
#[cfg(feature = "std")]
#features
impl #type_ident {
pub fn new<'a, T: #impl_ident>(this: &'a T) -> windows_core::ScopedInterface<'a, Self> {
Expand Down
1 change: 1 addition & 0 deletions crates/libs/bindgen/src/rust/interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,6 @@ fn gen_win_interface(writer: &Writer, def: metadata::TypeDef) -> TokenStream {
has_unknown_base,
));
tokens.combine(&writer.interface_vtbl(def, generics, &constraints, &features));
tokens.combine(&implements::writer(writer, def));
tokens
}
54 changes: 1 addition & 53 deletions crates/libs/bindgen/src/rust/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,26 +113,11 @@ fn gen_package(writer: &Writer) -> Result<()> {

trees.par_iter().try_for_each(|tree| {
let directory = format!("{directory}/{}", tree.namespace.replace('.', "/"));
let mut tokens = namespace(writer, tree);

let tokens_impl = if !writer.sys {
namespace_impl(writer, tree)
} else {
String::new()
};

if !writer.sys && !tokens_impl.is_empty() {
tokens.push_str("#[cfg(feature = \"implement\")]\ncore::include!(\"impl.rs\");\n");
}
let tokens = namespace(writer, tree);

let output = format!("{directory}/mod.rs");
write_to_file(&output, try_format(writer, &tokens))?;

if !writer.sys && !tokens_impl.is_empty() {
let output = format!("{directory}/impl.rs");
write_to_file(&output, try_format(writer, &tokens_impl))?;
}

Ok::<(), Error>(())
})?;

Expand Down Expand Up @@ -248,43 +233,6 @@ fn namespace(writer: &Writer, tree: &Tree) -> String {
}

tokens.combine(&extensions::gen_mod(writer, tree.namespace));

if writer.implement {
tokens.push_str(&namespace_impl(writer, tree));
}

tokens.into_string()
}

fn namespace_impl(writer: &Writer, tree: &Tree) -> String {
let writer = &mut writer.clone();
writer.namespace = tree.namespace;
let mut types = std::collections::BTreeMap::new();

for item in writer.reader.namespace_items(tree.namespace) {
if let metadata::Item::Type(def) = item {
let type_name = def.type_name();
if writer.reader.core_type(type_name).is_some() {
continue;
}
if def.kind() != metadata::TypeKind::Interface {
continue;
}
let tokens = implements::writer(writer, def);

if !tokens.is_empty() {
types.insert(type_name.name(), tokens);
}
}
}

let types = types.values();

let mut tokens = quote! {
#(#types)*
};

tokens.combine(&extensions::gen_impl(tree.namespace));
tokens.into_string()
}

Expand Down
1 change: 0 additions & 1 deletion crates/libs/windows/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ path = "../targets"
default = ["std"]
docs = []
deprecated = []
implement = []
std = ["windows-core/std"]
# generated features
AI = ["Foundation"]
Expand Down
144 changes: 0 additions & 144 deletions crates/libs/windows/src/Windows/AI/MachineLearning/impl.rs

This file was deleted.

Loading