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

Move feature and dependency tracking to the metadata crate #1544

Merged
merged 16 commits into from
Feb 17, 2022
4 changes: 3 additions & 1 deletion crates/libs/bindgen/src/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ fn gen_async_kind(kind: AsyncKind, name: &TypeDef, self_name: &TypeDef, cfg: &Cf
let constraints = gen_type_constraints(self_name, gen);
let name = gen_type_name(self_name, gen);
let namespace = gen.namespace("Windows.Foundation");
let cfg = cfg.and_async().gen(gen);
let mut cfg = cfg.clone();
cfg.add_feature("Windows.Foundation");
let cfg = gen.cfg(&cfg);

quote! {
#cfg
Expand Down
7 changes: 5 additions & 2 deletions crates/libs/bindgen/src/callbacks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ pub fn gen(def: &TypeDef, gen: &Gen) -> TokenStream {
let method = def.invoke_method();
let signature = method.signature(&[]);
let return_type = gen_return_sig(&signature, gen);
let cfg = gen.type_cfg(def).gen_with_doc(gen);
let cfg = def.cfg();
let doc = gen.doc(&cfg);
let features = gen.cfg(&cfg);

let params = signature.params.iter().map(|p| {
let name = gen_param_name(&p.def);
Expand All @@ -15,7 +17,8 @@ pub fn gen(def: &TypeDef, gen: &Gen) -> TokenStream {
});

quote! {
#cfg
#doc
#features
pub type #name = ::core::option::Option<unsafe extern "system" fn(#(#params),*) #return_type>;
}
}
116 changes: 0 additions & 116 deletions crates/libs/bindgen/src/cfg.rs

This file was deleted.

17 changes: 9 additions & 8 deletions crates/libs/bindgen/src/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ fn gen_class(def: &TypeDef, gen: &Gen) -> TokenStream {
let mut methods = quote! {};
let mut method_names = MethodNames::new();

let cfg = gen.type_cfg(def);
let features = cfg.gen(gen);
let doc = cfg.gen_doc(gen);
let cfg = def.cfg();
let doc = gen.doc(&cfg);
let features = gen.cfg(&cfg);

for (def, kind) in &interfaces {
if gen.min_xaml && *kind == InterfaceKind::Base && gen.namespace.starts_with("Windows.UI.Xaml") && !def.namespace().starts_with("Windows.Foundation") {
Expand All @@ -43,7 +43,7 @@ fn gen_class(def: &TypeDef, gen: &Gen) -> TokenStream {
if def.methods().next().is_some() {
let interface_name = format_token!("{}", def.name());
let interface_type = gen_type_name(def, gen);
let features = gen.type_cfg(def).gen(gen);
let features = gen.cfg(&def.cfg());

let hidden = if gen.doc {
quote! { #[doc(hidden)] }
Expand Down Expand Up @@ -129,7 +129,7 @@ fn gen_class(def: &TypeDef, gen: &Gen) -> TokenStream {
fn gen_agile(def: &TypeDef, cfg: &Cfg, gen: &Gen) -> TokenStream {
if def.is_agile() {
let name = gen_type_ident(def, gen);
let cfg = cfg.gen(gen);
let cfg = gen.cfg(cfg);
quote! {
#cfg
unsafe impl ::core::marker::Send for #name {}
Expand All @@ -147,7 +147,7 @@ fn gen_conversions(def: &TypeDef, cfg: &Cfg, gen: &Gen) -> TokenStream {

for def in &[Type::IUnknown, Type::IInspectable] {
let into = gen_element_name(def, gen);
let cfg = cfg.gen(gen);
let cfg = gen.cfg(cfg);
tokens.combine(&quote! {
#cfg
impl ::core::convert::From<#name> for #into {
Expand Down Expand Up @@ -186,7 +186,8 @@ fn gen_conversions(def: &TypeDef, cfg: &Cfg, gen: &Gen) -> TokenStream {
}

let into = gen_type_name(&def, gen);
let cfg = cfg.union(gen.type_cfg(&def)).gen(gen);
// TODO: simplify - maybe provide + operator?
let cfg = gen.cfg(&cfg.union(&def.cfg()));

tokens.combine(&quote! {
#cfg
Expand Down Expand Up @@ -222,7 +223,7 @@ fn gen_conversions(def: &TypeDef, cfg: &Cfg, gen: &Gen) -> TokenStream {

for def in def.bases() {
let into = gen_type_name(&def, gen);
let cfg = cfg.union(gen.type_cfg(&def)).gen(gen);
let cfg = gen.cfg(&cfg.union(&def.cfg()));

tokens.combine(&quote! {
#cfg
Expand Down
16 changes: 11 additions & 5 deletions crates/libs/bindgen/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ use super::*;
pub fn gen(def: &Field, gen: &Gen) -> TokenStream {
let name = gen_ident(def.name());
let ty = def.get_type(None);
let cfg = gen.field_cfg(def).gen_with_doc(gen);
let cfg = def.cfg();
let doc = gen.doc(&cfg);
let features = gen.cfg(&cfg);

if let Some(constant) = def.constant() {
if ty == constant.value_type() {
let value = gen_constant_type_value(&constant.value());
quote! {
#cfg
#doc
#features
pub const #name: #value;
}
} else {
Expand All @@ -26,12 +29,14 @@ pub fn gen(def: &Field, gen: &Gen) -> TokenStream {

if !gen.sys && ty.has_replacement() {
quote! {
#cfg
#doc
#features
pub const #name: #kind = #kind(#value);
}
} else {
quote! {
#cfg
#doc
#features
pub const #name: #kind = #value;
}
}
Expand All @@ -44,7 +49,8 @@ pub fn gen(def: &Field, gen: &Gen) -> TokenStream {
let kind = gen_default_type(&ty, gen);
let guid = gen_guid(&guid, gen);
quote! {
#cfg
#doc
#features
pub const #name: #kind = #kind {
fmtid: #guid,
pid: #id,
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/bindgen/src/delegates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ fn gen_win_delegate(def: &TypeDef, gen: &Gen) -> TokenStream {
let method = def.invoke_method();
let signature = method.signature(&def.generics);
let fn_constraint = gen_fn_constraint(def, &method, gen);
let cfg = gen.type_cfg(def);
let doc = cfg.gen_doc(gen);
let features = cfg.gen(gen);
let cfg = def.cfg();
let doc = gen.doc(&cfg);
let features = gen.cfg(&cfg);
let vtbl_signature = gen_vtbl_signature(def, &method, gen);
let invoke = gen_winrt_method(def, InterfaceKind::Default, &method, &mut MethodNames::new(), &mut MethodNames::new(), gen);
let invoke_upcall = gen_winrt_upcall(&signature, quote! { ((*this).invoke) });
Expand Down
6 changes: 3 additions & 3 deletions crates/libs/bindgen/src/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ pub fn gen(def: &TypeDef, gen: &Gen) -> TokenStream {
let underlying_type = def.underlying_type();
let underlying_type = gen_element_name(&underlying_type, gen);
let is_scoped = def.is_scoped();
let cfg = gen.type_cfg(def);
let features = cfg.gen(gen);
let doc = cfg.gen_doc(gen);
let cfg = def.cfg();
let doc = gen.doc(&cfg);
let features = gen.cfg(&cfg);

let mut fields: Vec<(TokenStream, TokenStream)> = def
.fields()
Expand Down
29 changes: 20 additions & 9 deletions crates/libs/bindgen/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ fn gen_function_if(entry: &[Type], gen: &Gen) -> TokenStream {
fn gen_sys_function(def: &MethodDef, gen: &Gen) -> TokenStream {
let name = gen_ident(def.name());
let signature = def.signature(&[]);
let cfg = gen.function_cfg(def).gen_with_doc(gen);
let cfg = def.cfg();
let doc = gen.doc(&cfg);
let features = gen.cfg(&cfg);
let mut return_type = gen_return_sig(&signature, gen);

if return_type.is_empty() {
Expand All @@ -67,7 +69,8 @@ fn gen_sys_function(def: &MethodDef, gen: &Gen) -> TokenStream {
});

quote! {
#cfg
#doc
#features
pub fn #name(#(#params),*) #return_type;
}
}
Expand Down Expand Up @@ -98,7 +101,9 @@ fn gen_win_function(def: &MethodDef, gen: &Gen) -> TokenStream {
}
};

let cfg = gen.function_cfg(def).gen_with_doc(gen);
let cfg = def.cfg();
let doc = gen.doc(&cfg);
let features = gen.cfg(&cfg);

match signature.kind() {
SignatureKind::Query => {
Expand All @@ -107,7 +112,8 @@ fn gen_win_function(def: &MethodDef, gen: &Gen) -> TokenStream {
let params = gen_win32_params(leading_params, gen);

quote! {
#cfg
#doc
#features
#[inline]
pub unsafe fn #name<#constraints T: ::windows::core::Interface>(#params) -> ::windows::core::Result<T> {
#[cfg(windows)]
Expand All @@ -130,7 +136,8 @@ fn gen_win_function(def: &MethodDef, gen: &Gen) -> TokenStream {
let params = gen_win32_params(leading_params, gen);

quote! {
#cfg
#doc
#features
#[inline]
pub unsafe fn #name<#constraints T: ::windows::core::Interface>(#params result__: *mut ::core::option::Option<T>) -> ::windows::core::Result<()> {
#[cfg(windows)]
Expand All @@ -155,7 +162,8 @@ fn gen_win_function(def: &MethodDef, gen: &Gen) -> TokenStream {
let abi_return_type_tokens = gen_abi_element_name(&return_type, gen);

quote! {
#cfg
#doc
#features
#[inline]
pub unsafe fn #name<#constraints>(#params) -> ::windows::core::Result<#return_type_tokens> {
#[cfg(windows)]
Expand All @@ -177,7 +185,8 @@ fn gen_win_function(def: &MethodDef, gen: &Gen) -> TokenStream {
let args = signature.params.iter().map(gen_win32_abi_arg);

quote! {
#cfg
#doc
#features
#[inline]
pub unsafe fn #name<#constraints>(#params) -> ::windows::core::Result<()> {
#[cfg(windows)]
Expand All @@ -198,7 +207,8 @@ fn gen_win_function(def: &MethodDef, gen: &Gen) -> TokenStream {
let args = signature.params.iter().map(gen_win32_abi_arg);

quote! {
#cfg
#doc
#features
#[inline]
pub unsafe fn #name<#constraints>(#params) #abi_return_type {
#[cfg(windows)]
Expand All @@ -220,7 +230,8 @@ fn gen_win_function(def: &MethodDef, gen: &Gen) -> TokenStream {
let does_not_return = does_not_return(def);

quote! {
#cfg
#doc
#features
#[inline]
pub unsafe fn #name<#constraints>(#params) #does_not_return {
#[cfg(windows)]
Expand Down
Loading