From 9a085ee6c5ae83688aaeb17ea064bfd52b921b9b Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 11 Dec 2024 02:32:32 +0100 Subject: [PATCH] Fix various header-translator errors --- crates/header-translator/src/id.rs | 6 +++++- crates/header-translator/src/main.rs | 5 ++++- crates/header-translator/src/method.rs | 6 +++++- crates/header-translator/src/unexposed_attr.rs | 1 + crates/objc2/src/topics/about_generated/CHANGELOG.md | 1 + framework-crates/objc2-io-surface/src/lib.rs | 4 ++++ framework-crates/objc2-io-surface/translation-config.toml | 3 +++ generated | 2 +- 8 files changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/header-translator/src/id.rs b/crates/header-translator/src/id.rs index 02b6885dd..330fa7f7f 100644 --- a/crates/header-translator/src/id.rs +++ b/crates/header-translator/src/id.rs @@ -238,11 +238,15 @@ impl ItemIdentifier { } pub fn with_name(name: N, entity: &Entity<'_>, context: &Context<'_>) -> Self { - let location = context.get_location(entity).unwrap_or_else(|| { + let mut location = context.get_location(entity).unwrap_or_else(|| { error!(?entity, "ItemIdentifier from unknown header"); Location::from_components(vec!["__Unknown__".into()]) }); + if let Some("IOSurfaceRef") = name.to_option() { + location = Location::from_components(vec!["IOSurface".into(), "IOSurfaceRef".into()]); + } + Self { name, location } } diff --git a/crates/header-translator/src/main.rs b/crates/header-translator/src/main.rs index 084449a69..6bb39d4fb 100644 --- a/crates/header-translator/src/main.rs +++ b/crates/header-translator/src/main.rs @@ -136,7 +136,10 @@ fn main() -> Result<(), BoxError> { let mut includes_file = fs::File::create(&includes).unwrap(); // Make sure that we pick the IOSurfaceRef that IOSurface defines, // instead of the one that CoreGraphics defines. - writeln!(&mut includes_file, "#import ")?; + if platform_config_filter(&config.libraries["IOSurface"]) { + writeln!(&mut includes_file, "#include ")?; + writeln!(&mut includes_file, "#include ")?; + } // Part of .modulemap writeln!(&mut includes_file, "#import ")?; for lib in config.libraries.values() { diff --git a/crates/header-translator/src/method.rs b/crates/header-translator/src/method.rs index 1660091cc..f5e6cf8e4 100644 --- a/crates/header-translator/src/method.rs +++ b/crates/header-translator/src/method.rs @@ -761,7 +761,11 @@ pub(crate) fn handle_reserved(name: &str) -> String { ident.to_string() } // translate whatever remains unchanged (needed for, e.g., `_`) - else { + else if name == "self" { + "self_".into() + } else if name == "super" { + "super_".into() + } else { name.into() } } diff --git a/crates/header-translator/src/unexposed_attr.rs b/crates/header-translator/src/unexposed_attr.rs index 409851a10..28547d66b 100644 --- a/crates/header-translator/src/unexposed_attr.rs +++ b/crates/header-translator/src/unexposed_attr.rs @@ -230,6 +230,7 @@ impl UnexposedAttr { "CF_SWIFT_NAME" | "CF_SWIFT_UNAVAILABLE_FROM_ASYNC" | "DISPATCH_SWIFT_NAME" + | "IOSFC_SWIFT_NAME" | "NS_REFINED_FOR_SWIFT_ASYNC" | "NS_SWIFT_ASYNC_NAME" | "NS_SWIFT_ASYNC_THROWS_ON_FALSE" diff --git a/crates/objc2/src/topics/about_generated/CHANGELOG.md b/crates/objc2/src/topics/about_generated/CHANGELOG.md index fa53b801e..6f0a3a807 100644 --- a/crates/objc2/src/topics/about_generated/CHANGELOG.md +++ b/crates/objc2/src/topics/about_generated/CHANGELOG.md @@ -25,6 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `CoreFoundation` / `objc2-core-foundation`. - `CoreText` / `objc2-core-text`. - `CoreVideo` / `objc2-core-video`. + - `IOSurface` / `objc2-io-surface`. - `ScreenSaver` / `objc2-screen-saver`. ### Changed diff --git a/framework-crates/objc2-io-surface/src/lib.rs b/framework-crates/objc2-io-surface/src/lib.rs index b517511e0..ad8da93ba 100644 --- a/framework-crates/objc2-io-surface/src/lib.rs +++ b/framework-crates/objc2-io-surface/src/lib.rs @@ -24,3 +24,7 @@ pub use self::generated::*; pub(crate) type Boolean = u8; #[allow(dead_code)] pub(crate) type OSType = u32; + +/// [Apple's documentation](https://developer.apple.com/documentation/iosurface/iosurfaceref?language=objc) +#[cfg(feature = "IOSurfaceRef")] +pub type IOSurfaceRef = *mut core::ffi::c_void; diff --git a/framework-crates/objc2-io-surface/translation-config.toml b/framework-crates/objc2-io-surface/translation-config.toml index d7efdfb42..97385e356 100644 --- a/framework-crates/objc2-io-surface/translation-config.toml +++ b/framework-crates/objc2-io-surface/translation-config.toml @@ -14,3 +14,6 @@ fn.IOSurfaceLookupFromXPCObject.skipped = true # Needs task_id_token_t fn.IOSurfaceSetOwnershipIdentity.skipped = true + +# Defined in other crates too, so needs manual definition +typedef.IOSurfaceRef.skipped = true diff --git a/generated b/generated index 69ad7e0f3..302b1e2fc 160000 --- a/generated +++ b/generated @@ -1 +1 @@ -Subproject commit 69ad7e0f3874cd0b661fc1977c9ea4e1151efc92 +Subproject commit 302b1e2fc41dc762ad03fea2284c08ce8e34dc82