diff --git a/Cargo.lock b/Cargo.lock index 1a79cbe0a..00e35fece 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -185,6 +185,7 @@ dependencies = [ "block2", "dispatch", "objc2", + "objc2-helpers", "static_assertions", ] @@ -319,6 +320,14 @@ dependencies = [ name = "objc2-encode" version = "4.0.0" +[[package]] +name = "objc2-helpers" +version = "0.0.0" +dependencies = [ + "block2", + "objc2", +] + [[package]] name = "objc2-proc-macros" version = "0.1.1" diff --git a/crates/icrate/Cargo.toml b/crates/icrate/Cargo.toml index 21743bb16..9a21ff486 100644 --- a/crates/icrate/Cargo.toml +++ b/crates/icrate/Cargo.toml @@ -25,6 +25,7 @@ workspace = true [dependencies] objc2 = { path = "../objc2", version = "0.5.0", default-features = false, optional = true } block2 = { path = "../block2", version = "0.4.0", default-features = false, optional = true } +objc2-helpers = { path = "../objc2-helpers" } dispatch = { version = "0.2.0", optional = true } [dev-dependencies] @@ -90,23 +91,29 @@ required-features = [ default = ["std", "apple"] # Currently not possible to turn off, put here for forwards compatibility. -std = ["alloc", "objc2?/std", "block2?/std"] -alloc = ["objc2?/alloc", "block2?/alloc"] +std = ["alloc", "objc2?/std", "block2?/std", "objc2-helpers/std"] +alloc = ["objc2?/alloc", "block2?/alloc", "objc2-helpers/alloc"] # Runtime selection. See `objc-sys` for details. -apple = ["objc2?/apple", "block2?/apple"] -gnustep-1-7 = ["objc2?/gnustep-1-7", "block2?/gnustep-1-7"] -gnustep-1-8 = ["gnustep-1-7", "objc2?/gnustep-1-8", "block2?/gnustep-1-8"] -gnustep-1-9 = ["gnustep-1-8", "objc2?/gnustep-1-9", "block2?/gnustep-1-9"] -gnustep-2-0 = ["gnustep-1-9", "objc2?/gnustep-2-0", "block2?/gnustep-2-0"] -gnustep-2-1 = ["gnustep-2-0", "objc2?/gnustep-2-1", "block2?/gnustep-2-1"] +apple = ["objc2?/apple", "block2?/apple", "objc2-helpers/apple"] +gnustep-1-7 = ["objc2?/gnustep-1-7", "block2?/gnustep-1-7", "objc2-helpers/gnustep-1-7"] +gnustep-1-8 = ["gnustep-1-7", "objc2?/gnustep-1-8", "block2?/gnustep-1-8", "objc2-helpers/gnustep-1-8"] +gnustep-1-9 = ["gnustep-1-8", "objc2?/gnustep-1-9", "block2?/gnustep-1-9", "objc2-helpers/gnustep-1-9"] +gnustep-2-0 = ["gnustep-1-9", "objc2?/gnustep-2-0", "block2?/gnustep-2-0", "objc2-helpers/gnustep-2-0"] +gnustep-2-1 = ["gnustep-2-0", "objc2?/gnustep-2-1", "block2?/gnustep-2-1", "objc2-helpers/gnustep-2-1"] + +objc2 = ["dep:objc2", "objc2-helpers/objc2"] # Deprecated. objective-c = ["objc2"] +block2 = ["dep:block2", "objc2-helpers/block2"] + # Deprecated. block = ["block2"] +dispatch = ["dep:dispatch"] + # For better documentation on docs.rs unstable-docsrs = [] diff --git a/crates/icrate/src/lib.rs b/crates/icrate/src/lib.rs index e091c6604..8d6143db7 100644 --- a/crates/icrate/src/lib.rs +++ b/crates/icrate/src/lib.rs @@ -139,10 +139,12 @@ pub extern crate objc2; pub extern crate block2; mod additions; -mod common; #[allow(unreachable_pub)] mod generated; +#[allow(unused_imports)] +pub(crate) use objc2_helpers as common; + /// Deprecated alias of [`Foundation::ns_string`]. #[macro_export] #[deprecated = "use icrate::Foundation::ns_string instead"] diff --git a/crates/objc2-helpers/Cargo.toml b/crates/objc2-helpers/Cargo.toml new file mode 100644 index 000000000..952b07a31 --- /dev/null +++ b/crates/objc2-helpers/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "objc2-helpers" +version = "0.0.0" +edition = "2021" +rust-version = "1.60" +publish = false # Need to get rid of this crate before next release + +[dependencies] +objc2 = { path = "../objc2", version = "0.5.0", default-features = false, optional = true } +block2 = { path = "../block2", version = "0.4.0", default-features = false, optional = true } + +[features] +default = ["std"] + +# Currently not possible to turn off, put here for forwards compatibility. +std = ["alloc", "objc2?/std", "block2?/std"] +alloc = ["objc2?/alloc", "block2?/alloc"] + +# Runtime selection. See `objc-sys` for details. +apple = ["objc2?/apple", "block2?/apple"] +gnustep-1-7 = ["objc2?/gnustep-1-7", "block2?/gnustep-1-7"] +gnustep-1-8 = ["gnustep-1-7", "objc2?/gnustep-1-8", "block2?/gnustep-1-8"] +gnustep-1-9 = ["gnustep-1-8", "objc2?/gnustep-1-9", "block2?/gnustep-1-9"] +gnustep-2-0 = ["gnustep-1-9", "objc2?/gnustep-2-0", "block2?/gnustep-2-0"] +gnustep-2-1 = ["gnustep-2-0", "objc2?/gnustep-2-1", "block2?/gnustep-2-1"] + +objc2 = ["dep:objc2"] +block2 = ["dep:block2"] diff --git a/crates/objc2-helpers/src/lib.rs b/crates/objc2-helpers/src/lib.rs new file mode 100644 index 000000000..4ceff22eb --- /dev/null +++ b/crates/objc2-helpers/src/lib.rs @@ -0,0 +1,41 @@ +pub use core::ffi::c_void; +pub use core::marker::PhantomData; +pub use core::ptr::NonNull; +#[cfg(feature = "std")] +pub use std::os::raw::{ + c_char, c_double, c_float, c_int, c_long, c_longlong, c_schar, c_short, c_uchar, c_uint, + c_ulong, c_ulonglong, c_ushort, +}; + +#[cfg(feature = "objc2")] +pub use objc2::encode::{Encode, Encoding, RefEncode}; +#[cfg(feature = "objc2")] +pub use objc2::ffi::{NSInteger, NSIntegerMax, NSUInteger, NSUIntegerMax, IMP}; +#[cfg(feature = "objc2")] +pub use objc2::mutability::{ + Immutable, ImmutableWithMutableSubclass, InteriorMutable, IsIdCloneable, IsMainThreadOnly, + MainThreadOnly, Mutable, MutableWithImmutableSuperclass, +}; +#[cfg(feature = "objc2")] +pub use objc2::rc::{Allocated, DefaultId, Id}; +#[cfg(feature = "objc2")] +pub use objc2::runtime::{AnyClass, AnyObject, Bool, Sel}; +#[cfg(feature = "objc2")] +pub use objc2::runtime::{NSObject, NSObjectProtocol, ProtocolObject}; +#[cfg(feature = "objc2")] +pub use objc2::{ + __inner_extern_class, extern_category, extern_class, extern_methods, extern_protocol, + ClassType, Message, ProtocolType, +}; + +#[cfg(feature = "block2")] +pub use block2::Block; + +// TODO +#[cfg(feature = "objc2")] +pub type AnyProtocol = AnyObject; +pub type TodoFunction = *const c_void; +#[cfg(feature = "objc2")] +pub type TodoClass = AnyObject; +#[cfg(feature = "objc2")] +pub type TodoProtocols = AnyObject;