Skip to content

Commit

Permalink
Fix macOS test expectations
Browse files Browse the repository at this point in the history
* Updated tests/expectations/Cargo.toml to use 2018 rust.
* Added Debug and Copy to objective-c structs.
* Fixed lifetimes in objective-c trait templates.
* Fixed imports for objective-c expectations tests.
  • Loading branch information
simlay committed Mar 8, 2022
1 parent f34e410 commit fcb3cc3
Show file tree
Hide file tree
Showing 38 changed files with 155 additions and 120 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bindgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
matrix:
# TODO(#1954): These should be run on mac too, but turns out they're
# broken.
os: [ubuntu-latest]
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v2

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@

## Added

* Objective-C structs now derive `Debug` and `Copy` to support C and Objective-C structs. [(#2176)][]

## Fixed

* Fixed lifetimes with Objective-C trait templates. [(#2176)][]
* Fixed objc imports for non-`#[macro_use]` use. [(#2176)][]

## Changed

* cexpr and nom have been updated, new msrv is 1.46 (#2107).
Expand All @@ -154,6 +159,9 @@

## Security


[(#2176)]: https://github.com/rust-lang/rust-bindgen/pull/2176

# 0.59.1

Released 2021/07/26
Expand Down
8 changes: 4 additions & 4 deletions src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4129,7 +4129,7 @@ impl CodeGenerator for ObjCInterface {
.collect();

quote! {
pub trait #trait_name <#(#template_names),*> : #trait_constraints {
pub trait #trait_name <#(#template_names:'static),*> : #trait_constraints {
#( #impl_items )*
}
}
Expand All @@ -4145,7 +4145,7 @@ impl CodeGenerator for ObjCInterface {
if !self.is_category() && !self.is_protocol() {
let struct_block = quote! {
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct #class_name(pub id);
impl std::ops::Deref for #class_name {
type Target = objc::runtime::Object;
Expand All @@ -4159,7 +4159,7 @@ impl CodeGenerator for ObjCInterface {
impl #class_name {
pub fn alloc() -> Self {
Self(unsafe {
msg_send!(objc::class!(#class_name), alloc)
msg_send!(class!(#class_name), alloc)
})
}
}
Expand Down Expand Up @@ -4381,7 +4381,7 @@ pub mod utils {
}
} else {
quote! {
use objc;
use objc::{self, msg_send, sel, sel_impl, class};
}
};

Expand Down
1 change: 1 addition & 0 deletions tests/expectations/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ authors = [
"Emilio Cobos Álvarez <emilio@crisal.io>",
"The Servo project developers",
]
edition = "2018"

[dependencies]
objc = "0.2"
Expand Down
15 changes: 7 additions & 8 deletions tests/expectations/tests/libclang-4/objc_inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
)]
#![cfg(target_os = "macos")]

#[macro_use]
extern crate objc;
use objc::{self, class, msg_send, sel, sel_impl};
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct Foo(pub id);
impl std::ops::Deref for Foo {
type Target = objc::runtime::Object;
Expand All @@ -22,13 +21,13 @@ impl std::ops::Deref for Foo {
unsafe impl objc::Message for Foo {}
impl Foo {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
Self(unsafe { msg_send!(class!(Foo), alloc) })
}
}
impl IFoo for Foo {}
pub trait IFoo: Sized + std::ops::Deref {}
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct Bar(pub id);
impl std::ops::Deref for Bar {
type Target = objc::runtime::Object;
Expand All @@ -39,7 +38,7 @@ impl std::ops::Deref for Bar {
unsafe impl objc::Message for Bar {}
impl Bar {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(Bar), alloc) })
Self(unsafe { msg_send!(class!(Bar), alloc) })
}
}
impl IFoo for Bar {}
Expand All @@ -63,7 +62,7 @@ impl std::convert::TryFrom<Foo> for Bar {
impl IBar for Bar {}
pub trait IBar: Sized + std::ops::Deref {}
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct Baz(pub id);
impl std::ops::Deref for Baz {
type Target = objc::runtime::Object;
Expand All @@ -74,7 +73,7 @@ impl std::ops::Deref for Baz {
unsafe impl objc::Message for Baz {}
impl Baz {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(Baz), alloc) })
Self(unsafe { msg_send!(class!(Baz), alloc) })
}
}
impl IBar for Baz {}
Expand Down
15 changes: 7 additions & 8 deletions tests/expectations/tests/libclang-4/objc_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
)]
#![cfg(target_os = "macos")]

#[macro_use]
extern crate objc;
use objc::{self, class, msg_send, sel, sel_impl};
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct Foo(pub id);
impl std::ops::Deref for Foo {
type Target = objc::runtime::Object;
Expand All @@ -22,11 +21,11 @@ impl std::ops::Deref for Foo {
unsafe impl objc::Message for Foo {}
impl Foo {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
Self(unsafe { msg_send!(class!(Foo), alloc) })
}
}
impl<ObjectType: 'static> IFoo<ObjectType> for Foo {}
pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
pub trait IFoo<ObjectType: 'static>: Sized + std::ops::Deref {
unsafe fn get(&self) -> *mut ObjectType
where
<Self as std::ops::Deref>::Target: objc::Message + Sized,
Expand All @@ -35,7 +34,7 @@ pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
}
}
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct FooMultiGeneric(pub id);
impl std::ops::Deref for FooMultiGeneric {
type Target = objc::runtime::Object;
Expand All @@ -46,14 +45,14 @@ impl std::ops::Deref for FooMultiGeneric {
unsafe impl objc::Message for FooMultiGeneric {}
impl FooMultiGeneric {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) })
Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) })
}
}
impl<KeyType: 'static, ObjectType: 'static>
IFooMultiGeneric<KeyType, ObjectType> for FooMultiGeneric
{
}
pub trait IFooMultiGeneric<KeyType, ObjectType>:
pub trait IFooMultiGeneric<KeyType: 'static, ObjectType: 'static>:
Sized + std::ops::Deref
{
unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType
Expand Down
15 changes: 7 additions & 8 deletions tests/expectations/tests/libclang-5/objc_inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
)]
#![cfg(target_os = "macos")]

#[macro_use]
extern crate objc;
use objc::{self, class, msg_send, sel, sel_impl};
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct Foo(pub id);
impl std::ops::Deref for Foo {
type Target = objc::runtime::Object;
Expand All @@ -22,13 +21,13 @@ impl std::ops::Deref for Foo {
unsafe impl objc::Message for Foo {}
impl Foo {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
Self(unsafe { msg_send!(class!(Foo), alloc) })
}
}
impl IFoo for Foo {}
pub trait IFoo: Sized + std::ops::Deref {}
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct Bar(pub id);
impl std::ops::Deref for Bar {
type Target = objc::runtime::Object;
Expand All @@ -39,7 +38,7 @@ impl std::ops::Deref for Bar {
unsafe impl objc::Message for Bar {}
impl Bar {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(Bar), alloc) })
Self(unsafe { msg_send!(class!(Bar), alloc) })
}
}
impl IFoo for Bar {}
Expand All @@ -63,7 +62,7 @@ impl std::convert::TryFrom<Foo> for Bar {
impl IBar for Bar {}
pub trait IBar: Sized + std::ops::Deref {}
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct Baz(pub id);
impl std::ops::Deref for Baz {
type Target = objc::runtime::Object;
Expand All @@ -74,7 +73,7 @@ impl std::ops::Deref for Baz {
unsafe impl objc::Message for Baz {}
impl Baz {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(Baz), alloc) })
Self(unsafe { msg_send!(class!(Baz), alloc) })
}
}
impl IBar for Baz {}
Expand Down
15 changes: 7 additions & 8 deletions tests/expectations/tests/libclang-5/objc_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
)]
#![cfg(target_os = "macos")]

#[macro_use]
extern crate objc;
use objc::{self, class, msg_send, sel, sel_impl};
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct Foo(pub id);
impl std::ops::Deref for Foo {
type Target = objc::runtime::Object;
Expand All @@ -22,11 +21,11 @@ impl std::ops::Deref for Foo {
unsafe impl objc::Message for Foo {}
impl Foo {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
Self(unsafe { msg_send!(class!(Foo), alloc) })
}
}
impl<ObjectType: 'static> IFoo<ObjectType> for Foo {}
pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
pub trait IFoo<ObjectType: 'static>: Sized + std::ops::Deref {
unsafe fn get(&self) -> *mut ObjectType
where
<Self as std::ops::Deref>::Target: objc::Message + Sized,
Expand All @@ -35,7 +34,7 @@ pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
}
}
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct FooMultiGeneric(pub id);
impl std::ops::Deref for FooMultiGeneric {
type Target = objc::runtime::Object;
Expand All @@ -46,14 +45,14 @@ impl std::ops::Deref for FooMultiGeneric {
unsafe impl objc::Message for FooMultiGeneric {}
impl FooMultiGeneric {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) })
Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) })
}
}
impl<KeyType: 'static, ObjectType: 'static>
IFooMultiGeneric<KeyType, ObjectType> for FooMultiGeneric
{
}
pub trait IFooMultiGeneric<KeyType, ObjectType>:
pub trait IFooMultiGeneric<KeyType: 'static, ObjectType: 'static>:
Sized + std::ops::Deref
{
unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType
Expand Down
15 changes: 7 additions & 8 deletions tests/expectations/tests/libclang-9/objc_inheritance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
)]
#![cfg(target_os = "macos")]

#[macro_use]
extern crate objc;
use objc::{self, class, msg_send, sel, sel_impl};
#[allow(non_camel_case_types)]
pub type id = *mut objc::runtime::Object;
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct Foo(pub id);
impl std::ops::Deref for Foo {
type Target = objc::runtime::Object;
Expand All @@ -22,13 +21,13 @@ impl std::ops::Deref for Foo {
unsafe impl objc::Message for Foo {}
impl Foo {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
Self(unsafe { msg_send!(class!(Foo), alloc) })
}
}
impl IFoo for Foo {}
pub trait IFoo: Sized + std::ops::Deref {}
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct Bar(pub id);
impl std::ops::Deref for Bar {
type Target = objc::runtime::Object;
Expand All @@ -39,7 +38,7 @@ impl std::ops::Deref for Bar {
unsafe impl objc::Message for Bar {}
impl Bar {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(Bar), alloc) })
Self(unsafe { msg_send!(class!(Bar), alloc) })
}
}
impl IFoo for Bar {}
Expand All @@ -63,7 +62,7 @@ impl std::convert::TryFrom<Foo> for Bar {
impl IBar for Bar {}
pub trait IBar: Sized + std::ops::Deref {}
#[repr(transparent)]
#[derive(Clone)]
#[derive(Debug, Copy, Clone)]
pub struct Baz(pub id);
impl std::ops::Deref for Baz {
type Target = objc::runtime::Object;
Expand All @@ -74,7 +73,7 @@ impl std::ops::Deref for Baz {
unsafe impl objc::Message for Baz {}
impl Baz {
pub fn alloc() -> Self {
Self(unsafe { msg_send!(objc::class!(Baz), alloc) })
Self(unsafe { msg_send!(class!(Baz), alloc) })
}
}
impl IBar for Baz {}
Expand Down

0 comments on commit fcb3cc3

Please sign in to comment.