Skip to content

Commit

Permalink
Add helper crate with common imports
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Mar 19, 2024
1 parent 7758a49 commit b04371d
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 9 deletions.
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions crates/icrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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 = []

Expand Down
4 changes: 3 additions & 1 deletion crates/icrate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
28 changes: 28 additions & 0 deletions crates/objc2-helpers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
41 changes: 41 additions & 0 deletions crates/objc2-helpers/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit b04371d

Please sign in to comment.