From 1b21bdc5bb30ab1d2be129f31ac501a1322d34e9 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Mon, 30 May 2022 11:01:34 +0200 Subject: [PATCH 1/3] Make all Vulkan types fundamental --- src/analysis/rust_type.rs | 2 +- src/analysis/types.rs | 4 ++++ src/codegen/sys/ffi_type.rs | 1 + src/library_postprocessing.rs | 17 ++++++++++++++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/analysis/rust_type.rs b/src/analysis/rust_type.rs index 142076845..a253d5689 100644 --- a/src/analysis/rust_type.rs +++ b/src/analysis/rust_type.rs @@ -271,7 +271,7 @@ impl<'env> RustTypeBuilder<'env> { UInt => ok("u32"), // maybe dependent on target system Short => ok_and_use("libc::c_short"), // depends of target system - UShort => ok_and_use("libc::c_ushort"), // depends o f target system + UShort => ok_and_use("libc::c_ushort"), // depends of target system Long => ok_and_use("libc::c_long"), // depends of target system ULong => ok_and_use("libc::c_ulong"), // depends of target system diff --git a/src/analysis/types.rs b/src/analysis/types.rs index d04fe5759..252bc6b1e 100644 --- a/src/analysis/types.rs +++ b/src/analysis/types.rs @@ -112,6 +112,10 @@ impl IsIncomplete for Record { // Search for GHookList in sys codegen for rationale. false } else { + // BADHACK: Prevent a horrible cyclic dependency on the "refs" array + if self.name == "VulkanDecoderPicture" { + return false; + } self.fields.as_slice().is_incomplete(lib) } } diff --git a/src/codegen/sys/ffi_type.rs b/src/codegen/sys/ffi_type.rs index 58168f941..8871572a1 100644 --- a/src/codegen/sys/ffi_type.rs +++ b/src/codegen/sys/ffi_type.rs @@ -150,6 +150,7 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result { | Type::List(..) | Type::SList(..) | Type::HashTable(..) => fix_name(env, tid, &inner), + Type::Custom(ref c) => return Ok(c.name.clone().into()), _ => { if let Some(glib_name) = env.library.type_(tid).get_glib_name() { if inner != glib_name { diff --git a/src/library_postprocessing.rs b/src/library_postprocessing.rs index 332663f26..93f48107c 100644 --- a/src/library_postprocessing.rs +++ b/src/library_postprocessing.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use log::{error, info}; use crate::{ - analysis::types::IsIncomplete, + analysis::{conversion_type::ConversionType, types::IsIncomplete}, config::{ gobjects::{GObject, GStatus}, matchable::Matchable, @@ -34,6 +34,7 @@ type DetectedCTypes = HashMap; impl Library { pub fn postprocessing(&mut self, config: &Config) { + self.define_vulkan_types(); self.fix_gtype(); self.check_resolved(); self.fill_empty_signals_c_types(); @@ -46,6 +47,20 @@ impl Library { self.mark_ignored_enum_members(config); } + fn define_vulkan_types(&mut self) { + if let Some(ns_id) = self.find_namespace("Vulkan") { + let ns = self.namespace_mut(ns_id); + for ns_type in ns.types.iter_mut().flatten() { + if let Type::Record(incomplete_record) = ns_type { + *ns_type = Type::Custom(Custom { + name: format!("ash::vk::{}", incomplete_record.name), + conversion_type: ConversionType::Direct, + }); + } + } + } + } + fn fix_gtype(&mut self) { if let Some(ns_id) = self.find_namespace("GObject") { // hide the `GType` type alias in `GObject` From 12fab48951e4172ca75cdab5162cfff4fb399cc0 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Tue, 28 Nov 2023 09:52:29 +0100 Subject: [PATCH 2/3] Don't prefix with `ash::vk::`, instead expect a crate named `vulkan::` This crate would be the place where either: 1. `ash::vk::*` is reexported; 2. manual reexports are generated from `Vulkan-1.0.gir`; 3. something else. --- src/codegen/sys/ffi_type.rs | 10 +++++++++- src/library_postprocessing.rs | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/codegen/sys/ffi_type.rs b/src/codegen/sys/ffi_type.rs index 8871572a1..2a6502c22 100644 --- a/src/codegen/sys/ffi_type.rs +++ b/src/codegen/sys/ffi_type.rs @@ -150,7 +150,15 @@ fn ffi_inner(env: &Env, tid: library::TypeId, mut inner: String) -> Result { | Type::List(..) | Type::SList(..) | Type::HashTable(..) => fix_name(env, tid, &inner), - Type::Custom(ref c) => return Ok(c.name.clone().into()), + // TODO: Add namespace! + Type::Custom(ref c) => { + // return Ok(c.name.clone().into()); + Ok(format!( + "{}::{}", + env.namespaces[tid.ns_id].higher_crate_name, c.name + ) + .into()) + } _ => { if let Some(glib_name) = env.library.type_(tid).get_glib_name() { if inner != glib_name { diff --git a/src/library_postprocessing.rs b/src/library_postprocessing.rs index 93f48107c..95181de01 100644 --- a/src/library_postprocessing.rs +++ b/src/library_postprocessing.rs @@ -53,7 +53,8 @@ impl Library { for ns_type in ns.types.iter_mut().flatten() { if let Type::Record(incomplete_record) = ns_type { *ns_type = Type::Custom(Custom { - name: format!("ash::vk::{}", incomplete_record.name), + // name: format!("ash::vk::{}", incomplete_record.name), + name: incomplete_record.name.clone(), conversion_type: ConversionType::Direct, }); } From 1e902d72d5bf19a83bd34c3b0c21d556ba7abc52 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Tue, 28 Nov 2023 09:53:30 +0100 Subject: [PATCH 3/3] WIP: Don't treat the `vulkan.` (lowercase?) namespace as "ignored" Gir.toml glob matches don't seem to function: [[object]] name = "vulkan.*" status = "generate" [[object]] name = "vulkan.*" status = "generate" --- src/analysis/rust_type.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/analysis/rust_type.rs b/src/analysis/rust_type.rs index a253d5689..d26d57d49 100644 --- a/src/analysis/rust_type.rs +++ b/src/analysis/rust_type.rs @@ -68,7 +68,17 @@ impl RustType { type_name.as_str() ); - if env.type_status(&type_id.full_name(&env.library)).ignored() { + // if env.namespaces[type_id.ns_id].higher_crate_name == "vulkan" { + // dbg!(&type_name); + // dbg!(&type_id.full_name(&env.library)); + // // dbg!(&env.config.objects); + // // panic!(); + // } + if env.type_status(&type_id.full_name(&env.library)).ignored() + // TODO + && env.namespaces[type_id.ns_id].higher_crate_name != "vulkan" + { + // dbg!(&type_name); return Err(TypeError::Ignored(type_name)); } }