Skip to content

Commit 6a169f2

Browse files
simlayemilio
authored andcommitted
Fix macOS test expectations
* 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.
1 parent f34e410 commit 6a169f2

38 files changed

+155
-120
lines changed

.github/workflows/bindgen.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
matrix:
7777
# TODO(#1954): These should be run on mac too, but turns out they're
7878
# broken.
79-
os: [ubuntu-latest]
79+
os: [ubuntu-latest, macos-latest]
8080
steps:
8181
- uses: actions/checkout@v2
8282

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,13 @@
140140

141141
## Added
142142

143+
* Objective-C structs now derive `Debug` and `Copy` to support C and Objective-C structs. [(#2176)][]
144+
143145
## Fixed
144146

147+
* Fixed lifetimes with Objective-C trait templates. [(#2176)][]
148+
* Fixed objc imports for non-`#[macro_use]` use. [(#2176)][]
149+
145150
## Changed
146151

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

155160
## Security
156161

162+
163+
[(#2176)]: https://github.com/rust-lang/rust-bindgen/pull/2176
164+
157165
# 0.59.1
158166

159167
Released 2021/07/26

src/codegen/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4129,7 +4129,7 @@ impl CodeGenerator for ObjCInterface {
41294129
.collect();
41304130

41314131
quote! {
4132-
pub trait #trait_name <#(#template_names),*> : #trait_constraints {
4132+
pub trait #trait_name <#(#template_names:'static),*> : #trait_constraints {
41334133
#( #impl_items )*
41344134
}
41354135
}
@@ -4145,7 +4145,7 @@ impl CodeGenerator for ObjCInterface {
41454145
if !self.is_category() && !self.is_protocol() {
41464146
let struct_block = quote! {
41474147
#[repr(transparent)]
4148-
#[derive(Clone)]
4148+
#[derive(Debug, Copy, Clone)]
41494149
pub struct #class_name(pub id);
41504150
impl std::ops::Deref for #class_name {
41514151
type Target = objc::runtime::Object;
@@ -4159,7 +4159,7 @@ impl CodeGenerator for ObjCInterface {
41594159
impl #class_name {
41604160
pub fn alloc() -> Self {
41614161
Self(unsafe {
4162-
msg_send!(objc::class!(#class_name), alloc)
4162+
msg_send!(class!(#class_name), alloc)
41634163
})
41644164
}
41654165
}
@@ -4381,7 +4381,7 @@ pub mod utils {
43814381
}
43824382
} else {
43834383
quote! {
4384-
use objc;
4384+
use objc::{self, msg_send, sel, sel_impl, class};
43854385
}
43864386
};
43874387

tests/expectations/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ authors = [
77
"Emilio Cobos Álvarez <[email protected]>",
88
"The Servo project developers",
99
]
10+
edition = "2018"
1011

1112
[dependencies]
1213
objc = "0.2"

tests/expectations/tests/libclang-4/objc_inheritance.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
)]
77
#![cfg(target_os = "macos")]
88

9-
#[macro_use]
10-
extern crate objc;
9+
use objc::{self, class, msg_send, sel, sel_impl};
1110
#[allow(non_camel_case_types)]
1211
pub type id = *mut objc::runtime::Object;
1312
#[repr(transparent)]
14-
#[derive(Clone)]
13+
#[derive(Debug, Copy, Clone)]
1514
pub struct Foo(pub id);
1615
impl std::ops::Deref for Foo {
1716
type Target = objc::runtime::Object;
@@ -22,13 +21,13 @@ impl std::ops::Deref for Foo {
2221
unsafe impl objc::Message for Foo {}
2322
impl Foo {
2423
pub fn alloc() -> Self {
25-
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
24+
Self(unsafe { msg_send!(class!(Foo), alloc) })
2625
}
2726
}
2827
impl IFoo for Foo {}
2928
pub trait IFoo: Sized + std::ops::Deref {}
3029
#[repr(transparent)]
31-
#[derive(Clone)]
30+
#[derive(Debug, Copy, Clone)]
3231
pub struct Bar(pub id);
3332
impl std::ops::Deref for Bar {
3433
type Target = objc::runtime::Object;
@@ -39,7 +38,7 @@ impl std::ops::Deref for Bar {
3938
unsafe impl objc::Message for Bar {}
4039
impl Bar {
4140
pub fn alloc() -> Self {
42-
Self(unsafe { msg_send!(objc::class!(Bar), alloc) })
41+
Self(unsafe { msg_send!(class!(Bar), alloc) })
4342
}
4443
}
4544
impl IFoo for Bar {}
@@ -63,7 +62,7 @@ impl std::convert::TryFrom<Foo> for Bar {
6362
impl IBar for Bar {}
6463
pub trait IBar: Sized + std::ops::Deref {}
6564
#[repr(transparent)]
66-
#[derive(Clone)]
65+
#[derive(Debug, Copy, Clone)]
6766
pub struct Baz(pub id);
6867
impl std::ops::Deref for Baz {
6968
type Target = objc::runtime::Object;
@@ -74,7 +73,7 @@ impl std::ops::Deref for Baz {
7473
unsafe impl objc::Message for Baz {}
7574
impl Baz {
7675
pub fn alloc() -> Self {
77-
Self(unsafe { msg_send!(objc::class!(Baz), alloc) })
76+
Self(unsafe { msg_send!(class!(Baz), alloc) })
7877
}
7978
}
8079
impl IBar for Baz {}

tests/expectations/tests/libclang-4/objc_template.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
)]
77
#![cfg(target_os = "macos")]
88

9-
#[macro_use]
10-
extern crate objc;
9+
use objc::{self, class, msg_send, sel, sel_impl};
1110
#[allow(non_camel_case_types)]
1211
pub type id = *mut objc::runtime::Object;
1312
#[repr(transparent)]
14-
#[derive(Clone)]
13+
#[derive(Debug, Copy, Clone)]
1514
pub struct Foo(pub id);
1615
impl std::ops::Deref for Foo {
1716
type Target = objc::runtime::Object;
@@ -22,11 +21,11 @@ impl std::ops::Deref for Foo {
2221
unsafe impl objc::Message for Foo {}
2322
impl Foo {
2423
pub fn alloc() -> Self {
25-
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
24+
Self(unsafe { msg_send!(class!(Foo), alloc) })
2625
}
2726
}
2827
impl<ObjectType: 'static> IFoo<ObjectType> for Foo {}
29-
pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
28+
pub trait IFoo<ObjectType: 'static>: Sized + std::ops::Deref {
3029
unsafe fn get(&self) -> *mut ObjectType
3130
where
3231
<Self as std::ops::Deref>::Target: objc::Message + Sized,
@@ -35,7 +34,7 @@ pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
3534
}
3635
}
3736
#[repr(transparent)]
38-
#[derive(Clone)]
37+
#[derive(Debug, Copy, Clone)]
3938
pub struct FooMultiGeneric(pub id);
4039
impl std::ops::Deref for FooMultiGeneric {
4140
type Target = objc::runtime::Object;
@@ -46,14 +45,14 @@ impl std::ops::Deref for FooMultiGeneric {
4645
unsafe impl objc::Message for FooMultiGeneric {}
4746
impl FooMultiGeneric {
4847
pub fn alloc() -> Self {
49-
Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) })
48+
Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) })
5049
}
5150
}
5251
impl<KeyType: 'static, ObjectType: 'static>
5352
IFooMultiGeneric<KeyType, ObjectType> for FooMultiGeneric
5453
{
5554
}
56-
pub trait IFooMultiGeneric<KeyType, ObjectType>:
55+
pub trait IFooMultiGeneric<KeyType: 'static, ObjectType: 'static>:
5756
Sized + std::ops::Deref
5857
{
5958
unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType

tests/expectations/tests/libclang-5/objc_inheritance.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
)]
77
#![cfg(target_os = "macos")]
88

9-
#[macro_use]
10-
extern crate objc;
9+
use objc::{self, class, msg_send, sel, sel_impl};
1110
#[allow(non_camel_case_types)]
1211
pub type id = *mut objc::runtime::Object;
1312
#[repr(transparent)]
14-
#[derive(Clone)]
13+
#[derive(Debug, Copy, Clone)]
1514
pub struct Foo(pub id);
1615
impl std::ops::Deref for Foo {
1716
type Target = objc::runtime::Object;
@@ -22,13 +21,13 @@ impl std::ops::Deref for Foo {
2221
unsafe impl objc::Message for Foo {}
2322
impl Foo {
2423
pub fn alloc() -> Self {
25-
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
24+
Self(unsafe { msg_send!(class!(Foo), alloc) })
2625
}
2726
}
2827
impl IFoo for Foo {}
2928
pub trait IFoo: Sized + std::ops::Deref {}
3029
#[repr(transparent)]
31-
#[derive(Clone)]
30+
#[derive(Debug, Copy, Clone)]
3231
pub struct Bar(pub id);
3332
impl std::ops::Deref for Bar {
3433
type Target = objc::runtime::Object;
@@ -39,7 +38,7 @@ impl std::ops::Deref for Bar {
3938
unsafe impl objc::Message for Bar {}
4039
impl Bar {
4140
pub fn alloc() -> Self {
42-
Self(unsafe { msg_send!(objc::class!(Bar), alloc) })
41+
Self(unsafe { msg_send!(class!(Bar), alloc) })
4342
}
4443
}
4544
impl IFoo for Bar {}
@@ -63,7 +62,7 @@ impl std::convert::TryFrom<Foo> for Bar {
6362
impl IBar for Bar {}
6463
pub trait IBar: Sized + std::ops::Deref {}
6564
#[repr(transparent)]
66-
#[derive(Clone)]
65+
#[derive(Debug, Copy, Clone)]
6766
pub struct Baz(pub id);
6867
impl std::ops::Deref for Baz {
6968
type Target = objc::runtime::Object;
@@ -74,7 +73,7 @@ impl std::ops::Deref for Baz {
7473
unsafe impl objc::Message for Baz {}
7574
impl Baz {
7675
pub fn alloc() -> Self {
77-
Self(unsafe { msg_send!(objc::class!(Baz), alloc) })
76+
Self(unsafe { msg_send!(class!(Baz), alloc) })
7877
}
7978
}
8079
impl IBar for Baz {}

tests/expectations/tests/libclang-5/objc_template.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
)]
77
#![cfg(target_os = "macos")]
88

9-
#[macro_use]
10-
extern crate objc;
9+
use objc::{self, class, msg_send, sel, sel_impl};
1110
#[allow(non_camel_case_types)]
1211
pub type id = *mut objc::runtime::Object;
1312
#[repr(transparent)]
14-
#[derive(Clone)]
13+
#[derive(Debug, Copy, Clone)]
1514
pub struct Foo(pub id);
1615
impl std::ops::Deref for Foo {
1716
type Target = objc::runtime::Object;
@@ -22,11 +21,11 @@ impl std::ops::Deref for Foo {
2221
unsafe impl objc::Message for Foo {}
2322
impl Foo {
2423
pub fn alloc() -> Self {
25-
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
24+
Self(unsafe { msg_send!(class!(Foo), alloc) })
2625
}
2726
}
2827
impl<ObjectType: 'static> IFoo<ObjectType> for Foo {}
29-
pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
28+
pub trait IFoo<ObjectType: 'static>: Sized + std::ops::Deref {
3029
unsafe fn get(&self) -> *mut ObjectType
3130
where
3231
<Self as std::ops::Deref>::Target: objc::Message + Sized,
@@ -35,7 +34,7 @@ pub trait IFoo<ObjectType>: Sized + std::ops::Deref {
3534
}
3635
}
3736
#[repr(transparent)]
38-
#[derive(Clone)]
37+
#[derive(Debug, Copy, Clone)]
3938
pub struct FooMultiGeneric(pub id);
4039
impl std::ops::Deref for FooMultiGeneric {
4140
type Target = objc::runtime::Object;
@@ -46,14 +45,14 @@ impl std::ops::Deref for FooMultiGeneric {
4645
unsafe impl objc::Message for FooMultiGeneric {}
4746
impl FooMultiGeneric {
4847
pub fn alloc() -> Self {
49-
Self(unsafe { msg_send!(objc::class!(FooMultiGeneric), alloc) })
48+
Self(unsafe { msg_send!(class!(FooMultiGeneric), alloc) })
5049
}
5150
}
5251
impl<KeyType: 'static, ObjectType: 'static>
5352
IFooMultiGeneric<KeyType, ObjectType> for FooMultiGeneric
5453
{
5554
}
56-
pub trait IFooMultiGeneric<KeyType, ObjectType>:
55+
pub trait IFooMultiGeneric<KeyType: 'static, ObjectType: 'static>:
5756
Sized + std::ops::Deref
5857
{
5958
unsafe fn objectForKey_(&self, key: *mut KeyType) -> *mut ObjectType

tests/expectations/tests/libclang-9/objc_inheritance.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
)]
77
#![cfg(target_os = "macos")]
88

9-
#[macro_use]
10-
extern crate objc;
9+
use objc::{self, class, msg_send, sel, sel_impl};
1110
#[allow(non_camel_case_types)]
1211
pub type id = *mut objc::runtime::Object;
1312
#[repr(transparent)]
14-
#[derive(Clone)]
13+
#[derive(Debug, Copy, Clone)]
1514
pub struct Foo(pub id);
1615
impl std::ops::Deref for Foo {
1716
type Target = objc::runtime::Object;
@@ -22,13 +21,13 @@ impl std::ops::Deref for Foo {
2221
unsafe impl objc::Message for Foo {}
2322
impl Foo {
2423
pub fn alloc() -> Self {
25-
Self(unsafe { msg_send!(objc::class!(Foo), alloc) })
24+
Self(unsafe { msg_send!(class!(Foo), alloc) })
2625
}
2726
}
2827
impl IFoo for Foo {}
2928
pub trait IFoo: Sized + std::ops::Deref {}
3029
#[repr(transparent)]
31-
#[derive(Clone)]
30+
#[derive(Debug, Copy, Clone)]
3231
pub struct Bar(pub id);
3332
impl std::ops::Deref for Bar {
3433
type Target = objc::runtime::Object;
@@ -39,7 +38,7 @@ impl std::ops::Deref for Bar {
3938
unsafe impl objc::Message for Bar {}
4039
impl Bar {
4140
pub fn alloc() -> Self {
42-
Self(unsafe { msg_send!(objc::class!(Bar), alloc) })
41+
Self(unsafe { msg_send!(class!(Bar), alloc) })
4342
}
4443
}
4544
impl IFoo for Bar {}
@@ -63,7 +62,7 @@ impl std::convert::TryFrom<Foo> for Bar {
6362
impl IBar for Bar {}
6463
pub trait IBar: Sized + std::ops::Deref {}
6564
#[repr(transparent)]
66-
#[derive(Clone)]
65+
#[derive(Debug, Copy, Clone)]
6766
pub struct Baz(pub id);
6867
impl std::ops::Deref for Baz {
6968
type Target = objc::runtime::Object;
@@ -74,7 +73,7 @@ impl std::ops::Deref for Baz {
7473
unsafe impl objc::Message for Baz {}
7574
impl Baz {
7675
pub fn alloc() -> Self {
77-
Self(unsafe { msg_send!(objc::class!(Baz), alloc) })
76+
Self(unsafe { msg_send!(class!(Baz), alloc) })
7877
}
7978
}
8079
impl IBar for Baz {}

0 commit comments

Comments
 (0)