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

Fix macos expectations #2176

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I mostly just was putting the "links" section at the end of that unreleased release section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, right. Rendered, the markdown would not show anything under Security. My mistake.


# 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};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we worried about namespace pollution in the generated code with generic names like class and self ? This may be of no importance – I honestly do not have a good handle on the implications of bringing in these names unqualified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will admit that I don't know if self is needed here. It was there before so I left it in now that you question it, it may not be needed. The (unfortunate) generic class however is needed for the non-objc_extern_crate scenario.

Before rust edition 2018 (if I recall the history), things like:

#[macro_use] extern crate objc;

were required for all external crates and imported all macros from that crate via the #[macro_use] annotation. With rust 2018, one doesn't need extern crate foo for crate foo on src/lib.rs or src/main.rs but as a result one cannot just blanket import all the macros (this is probably for the best).

One unfortunate part of this is that macros use macros but the macros don't import the macros from the crates they use that I know of and not from the crates they live in (for the objc crate anyway).

Anyway, I bring this up because I find the #[macro_use] annotation nice but only because it works now. If I'm being honest this crate should probably deprecate it but argue that it's outside the scope of this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that deprecation is out of scope for this PR. I am pretty weak on the edition differences and macro scoping rules, but after your explanation I think the namespace collision problem is not worse than it was. Thanks.

}
};

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