Skip to content

Commit

Permalink
Move objc2::foundation to icrate::Foundation
Browse files Browse the repository at this point in the history
With the plan to have most of it autogenerated
  • Loading branch information
madsmtm committed Dec 8, 2022
1 parent f4be196 commit 47cd390
Show file tree
Hide file tree
Showing 63 changed files with 448 additions and 463 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ jobs:
ARGS: --no-default-features --features=std,${{ matrix.runtime || 'apple' }} ${{ matrix.args }}
# Use --no-fail-fast, except with dinghy
TESTARGS: ${{ matrix.dinghy && ' ' || '--no-fail-fast' }} ${{ matrix.test-args }}
SOME_FEATURES: ${{ matrix.features || 'malloc,block,exception,foundation' }}
FEATURES: ${{ matrix.features || 'malloc,block,exception,foundation,catch-all,verify,uuid' }}
SOME_FEATURES: ${{ matrix.features || 'malloc,block,exception,Foundation' }}
FEATURES: ${{ matrix.features || 'malloc,block,exception,Foundation,catch-all,verify,uuid' }}
UNSTABLE_FEATURES: ${{ matrix.unstable-features || 'unstable-autoreleasesafe,unstable-c-unwind' }}
CMD: cargo

Expand Down Expand Up @@ -428,7 +428,7 @@ jobs:

- name: Test static class and selectors
if: ${{ !matrix.dinghy && (matrix.runtime || 'apple') == 'apple' }}
run: cargo test ${{ env.ARGS }} ${{ env.TESTARGS }} --features foundation,unstable-static-sel,unstable-static-class
run: cargo test ${{ env.ARGS }} ${{ env.TESTARGS }} --features Foundation,unstable-static-sel,unstable-static-class

- name: Run assembly tests
if: ${{ !contains(matrix.runtime, 'compiler-rt') }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ fork [here][origin-issue-101]:
- [`objc_id`](https://github.com/SSheldon/rust-objc-id)
- Moved to `objc2::rc`.
- [`objc-foundation`](https://github.com/SSheldon/rust-objc-foundation)
- Moved to `objc2::foundation`.
- Moved to `icrate::Foundation`.
- [`block`](https://github.com/SSheldon/rust-block)
- Renamed to `block2`.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# Changelog

Changes to the `objc2::foundation` module will be documented in this file.
This previously existed as a separate crate `objc2_foundation`, hence the
separation.
Changes to `icrate` will be documented in this file.

This previously existed as a separate crate `objc2_foundation`, later it was
integrated into `objc2::foundation`, and later again split out - hence the
confusing versioning.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased - YYYY-MM-DD
## icrate Unreleased - YYYY-MM-DD

### Added
* Added `NSString::write_to_file`.
* Added `NSLock` class and `NSLocking` protocol.

### Changed
* **BREAKING**: Moved from `objc2::foundation` into `icrate::Foundation`.

### Fixed
* Fixed `NSZone` not being `#[repr(C)]`.


## objc2 0.3.0-beta.3 - 2022-09-01
## objc2::foundation 0.3.0-beta.3 - 2022-09-01

### Added
* Added `NSSet`.
Expand All @@ -36,7 +41,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
binding to requires a non-negative size.


## objc2 0.3.0-beta.2 - 2022-08-28
## objc2::foundation 0.3.0-beta.2 - 2022-08-28

### Added
* Added `NSNumber`.
Expand Down
5 changes: 4 additions & 1 deletion crates/icrate/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ license = "MIT"
objc2 = { path = "../objc2", version = "=0.3.0-beta.3", default-features = false, optional = true }
block2 = { path = "../block2", version = "=0.2.0-alpha.6", default-features = false, optional = true }

# Provide methods to convert between `uuid::Uuid` and `icrate::Foundation::NSUUID`
uuid = { version = "1.1.2", optional = true, default-features = false }

[package.metadata.docs.rs]
default-target = "x86_64-apple-darwin"
all-features = true
Expand Down Expand Up @@ -88,4 +91,4 @@ unstable-docsrs = []
AppKit = ["Foundation", "CoreData"]
AuthenticationServices = ["Foundation"]
CoreData = ["Foundation"]
Foundation = ["objective-c", "blocks", "objc2/foundation"]
Foundation = ["objective-c", "blocks"]
3 changes: 2 additions & 1 deletion crates/icrate/examples/basic_usage.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use icrate::ns_string;
use icrate::objc2::rc::autoreleasepool;
use icrate::Foundation::{ns_string, NSArray, NSDictionary, NSObject};
use icrate::Foundation::{NSArray, NSDictionary, NSObject};

fn main() {
// Create and compare NSObjects
Expand Down
3 changes: 2 additions & 1 deletion crates/icrate/examples/delegate.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#![cfg_attr(not(target_os = "macos"), allow(unused))]
use icrate::ns_string;
use icrate::objc2::declare::{Ivar, IvarDrop};
use icrate::objc2::rc::{Id, Shared};
use icrate::objc2::runtime::Object;
use icrate::objc2::{declare_class, extern_class, msg_send, msg_send_id, ClassType};
use icrate::Foundation::{ns_string, NSCopying, NSObject, NSString};
use icrate::Foundation::{NSCopying, NSObject, NSString};

#[cfg(target_os = "macos")]
#[link(name = "AppKit", kind = "framework")]
Expand Down
2 changes: 1 addition & 1 deletion crates/icrate/examples/nspasteboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl NSPasteboard {
/// <https://developer.apple.com/documentation/appkit/nspasteboard/1524454-readobjectsforclasses?language=objc>
pub fn text_impl_2(&self) -> Id<NSString, Shared> {
// The NSPasteboard API is a bit weird, it requires you to pass
// classes as objects, which `objc2::foundation::NSArray` was not
// classes as objects, which `icrate::Foundation::NSArray` was not
// really made for - so we convert the class to an `Object` type
// instead. Also, we wrap it in `ManuallyDrop` because I'm not sure
// how classes handle `release` calls?
Expand Down
3 changes: 2 additions & 1 deletion crates/icrate/examples/speech_synthesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
use std::thread;
use std::time::Duration;

use icrate::ns_string;
use icrate::objc2::rc::{Id, Owned};
use icrate::objc2::{extern_class, msg_send, msg_send_id, ClassType};
use icrate::Foundation::{ns_string, NSObject, NSString};
use icrate::Foundation::{NSObject, NSString};

#[cfg(target_os = "macos")]
mod appkit {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ use core::mem::ManuallyDrop;
use core::ptr;
use core::sync::atomic::{AtomicPtr, Ordering};

use crate::foundation::NSString;
use crate::rc::Id;
use crate::runtime::Class;
use crate::Foundation::NSString;
use objc2::rc::Id;
use objc2::runtime::Class;

// This is defined in CoreFoundation, but we don't emit a link attribute
// here because it is already linked via Foundation.
Expand Down Expand Up @@ -239,7 +239,7 @@ impl CachedNSString {
}
}

/// Creates an [`NSString`][`crate::foundation::NSString`] from a static string.
/// Creates an [`NSString`][`crate::Foundation::NSString`] from a static string.
///
/// Note: This works by placing statics in special sections, which may not
/// work completely reliably yet, see [#258]; until then, you should be
Expand All @@ -254,8 +254,8 @@ impl CachedNSString {
/// the argument, and produces a `&'static NSString`:
///
/// ```
/// use objc2::ns_string;
/// use objc2::foundation::NSString;
/// use icrate::ns_string;
/// use icrate::Foundation::NSString;
/// # #[cfg(feature = "gnustep-1-7")]
/// # unsafe { objc2::__gnustep_hack::get_class_to_force_linkage() };
/// let hello: &'static NSString = ns_string!("hello");
Expand All @@ -274,7 +274,7 @@ impl CachedNSString {
/// string to the most efficient encoding, you don't have to do anything!
///
/// ```
/// # use objc2::ns_string;
/// # use icrate::ns_string;
/// # #[cfg(feature = "gnustep-1-7")]
/// # unsafe { objc2::__gnustep_hack::get_class_to_force_linkage() };
/// let hello_ru = ns_string!("Привет");
Expand All @@ -292,7 +292,7 @@ impl CachedNSString {
/// expect:
///
/// ```
/// # use objc2::ns_string;
/// # use icrate::ns_string;
/// # #[cfg(feature = "gnustep-1-7")]
/// # unsafe { objc2::__gnustep_hack::get_class_to_force_linkage() };
/// let example = ns_string!("example\0");
Expand All @@ -312,8 +312,8 @@ impl CachedNSString {
/// Because of that, this should be preferred over [`NSString::from_str`]
/// where possible.
///
/// [`NSString::from_str`]: crate::foundation::NSString::from_str
#[cfg(feature = "foundation")] // For auto_doc_cfg
/// [`NSString::from_str`]: crate::Foundation::NSString::from_str
#[cfg(feature = "Foundation")] // For auto_doc_cfg
#[macro_export]
macro_rules! ns_string {
($s:expr) => {{
Expand Down Expand Up @@ -362,7 +362,7 @@ macro_rules! __ns_string_inner {
// The full UTF-16 contents along with the written length.
const UTF16_FULL: (&[u16; $inp.len()], usize) = {
let mut out = [0u16; $inp.len()];
let mut iter = $crate::foundation::__ns_string::EncodeUtf16Iter::new($inp);
let mut iter = $crate::Foundation::__ns_string::EncodeUtf16Iter::new($inp);
let mut written = 0;

while let Some((state, chars)) = iter.next() {
Expand Down Expand Up @@ -403,17 +403,17 @@ macro_rules! __ns_string_inner {
// The section is the same as what clang sets, see:
// https://github.com/llvm/llvm-project/blob/release/13.x/clang/lib/CodeGen/CodeGenModule.cpp#L5243
#[link_section = "__DATA,__cfstring"]
static CFSTRING: $crate::foundation::__ns_string::CFConstString = unsafe {
if $crate::foundation::__ns_string::is_ascii_no_nul($inp) {
static CFSTRING: $crate::Foundation::__ns_string::CFConstString = unsafe {
if $crate::Foundation::__ns_string::is_ascii_no_nul($inp) {
// This is technically an optimization (UTF-16 strings are
// always valid), but it's a fairly important one!
$crate::foundation::__ns_string::CFConstString::new_ascii(
&$crate::foundation::__ns_string::__CFConstantStringClassReference,
$crate::Foundation::__ns_string::CFConstString::new_ascii(
&$crate::Foundation::__ns_string::__CFConstantStringClassReference,
&ASCII,
)
} else {
$crate::foundation::__ns_string::CFConstString::new_utf16(
&$crate::foundation::__ns_string::__CFConstantStringClassReference,
$crate::Foundation::__ns_string::CFConstString::new_utf16(
&$crate::Foundation::__ns_string::__CFConstantStringClassReference,
&UTF16,
)
}
Expand All @@ -426,7 +426,7 @@ macro_rules! __ns_string_inner {
#[macro_export]
macro_rules! __ns_string_inner {
($inp:ident) => {{
use $crate::foundation::__ns_string::CachedNSString;
use $crate::Foundation::__ns_string::CachedNSString;
static CACHED_NSSTRING: CachedNSString = CachedNSString::new();
CACHED_NSSTRING.get($inp)
}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use super::{
NSCopying, NSEnumerator, NSFastEnumeration, NSFastEnumerator, NSMutableArray, NSMutableCopying,
NSObject, NSRange,
};
use crate::rc::{DefaultId, Id, Owned, Ownership, Shared, SliceId};
use crate::runtime::Object;
use crate::{ClassType, Message, __inner_extern_class, extern_methods, msg_send, msg_send_id};
use objc2::rc::{DefaultId, Id, Owned, Ownership, Shared, SliceId};
use objc2::runtime::Object;
use objc2::{ClassType, Message, __inner_extern_class, extern_methods, msg_send, msg_send_id};

__inner_extern_class!(
/// An immutable ordered collection of objects.
Expand Down Expand Up @@ -306,8 +306,8 @@ mod tests {
use alloc::vec::Vec;

use super::*;
use crate::foundation::{NSNumber, NSString};
use crate::rc::{RcTestObject, ThreadTestData};
use crate::Foundation::{NSNumber, NSString};
use objc2::rc::{__RcTestObject, __ThreadTestData};

fn sample_array(len: usize) -> Id<NSArray<NSObject, Owned>, Owned> {
let mut vec = Vec::with_capacity(len);
Expand Down Expand Up @@ -377,8 +377,8 @@ mod tests {

#[test]
fn test_retains_stored() {
let obj = Id::into_shared(RcTestObject::new());
let mut expected = ThreadTestData::current();
let obj = Id::into_shared(__RcTestObject::new());
let mut expected = __ThreadTestData::current();

let input = [obj.clone(), obj.clone()];
expected.retain += 2;
Expand Down Expand Up @@ -417,9 +417,9 @@ mod tests {

#[test]
fn test_nscopying_uses_retain() {
let obj = Id::into_shared(RcTestObject::new());
let obj = Id::into_shared(__RcTestObject::new());
let array = NSArray::from_slice(&[obj]);
let mut expected = ThreadTestData::current();
let mut expected = __ThreadTestData::current();

let _copy = array.copy();
expected.assert_current();
Expand All @@ -435,9 +435,9 @@ mod tests {
ignore = "this works differently on different framework versions"
)]
fn test_iter_no_retain() {
let obj = Id::into_shared(RcTestObject::new());
let obj = Id::into_shared(__RcTestObject::new());
let array = NSArray::from_slice(&[obj]);
let mut expected = ThreadTestData::current();
let mut expected = __ThreadTestData::current();

let iter = array.iter();
expected.retain += 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use core::panic::{RefUnwindSafe, UnwindSafe};
use super::{
NSCopying, NSDictionary, NSMutableAttributedString, NSMutableCopying, NSObject, NSString,
};
use crate::rc::{Allocated, DefaultId, Id, Shared};
use crate::runtime::Object;
use crate::{extern_class, extern_methods, ClassType};
use objc2::rc::{Allocated, DefaultId, Id, Shared};
use objc2::runtime::Object;
use objc2::{extern_class, extern_methods, ClassType};

extern_class!(
/// A string that has associated attributes for portions of its text.
Expand Down Expand Up @@ -150,7 +150,7 @@ mod tests {
use alloc::{format, vec};

use super::*;
use crate::rc::{autoreleasepool, Owned};
use objc2::rc::{autoreleasepool, Owned};

#[test]
fn test_new() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use core::fmt;
use core::panic::{RefUnwindSafe, UnwindSafe};

use super::{NSCopying, NSDictionary, NSObject, NSString};
use crate::rc::{Id, Shared};
use crate::{extern_class, extern_methods, ClassType};
use objc2::rc::{Id, Shared};
use objc2::{extern_class, extern_methods, ClassType};

extern_class!(
/// A representation of the code and resources stored in a bundle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::cmp::Ordering;

use crate::{Encode, Encoding, RefEncode};
use objc2::encode::{Encode, Encoding, RefEncode};

/// Constants that indicate sort order.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::rc::{Id, Owned, Ownership};
use crate::{msg_send_id, Message};
use objc2::rc::{Id, Owned, Ownership};
use objc2::{msg_send_id, Message};

pub unsafe trait NSCopying: Message {
/// Indicates whether the type is mutable or immutable.
Expand All @@ -21,7 +21,7 @@ pub unsafe trait NSCopying: Message {
/// `copy` message (and others) does not create a new instance, but
/// instead just retains the instance).
///
/// [`NSString`]: crate::foundation::NSString
/// [`NSString`]: crate::Foundation::NSString
type Ownership: Ownership;

/// The output type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use core::panic::{RefUnwindSafe, UnwindSafe};
use core::slice::{self, SliceIndex};

use super::{NSCopying, NSMutableCopying, NSMutableData, NSObject};
use crate::rc::{DefaultId, Id, Shared};
use crate::runtime::{Class, Object};
use crate::{extern_class, extern_methods, msg_send_id, ClassType};
use objc2::rc::{DefaultId, Id, Shared};
use objc2::runtime::{Class, Object};
use objc2::{extern_class, extern_methods, msg_send_id, ClassType};

extern_class!(
/// A static byte buffer in memory.
Expand Down Expand Up @@ -53,7 +53,7 @@ extern_methods!(
//
// NSMutableData does not have this problem.
#[cfg(feature = "gnustep-1-7")]
let cls = crate::class!(NSDataWithDeallocatorBlock);
let cls = objc2::class!(NSDataWithDeallocatorBlock);
#[cfg(not(feature = "gnustep-1-7"))]
let cls = Self::class();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use core::panic::{RefUnwindSafe, UnwindSafe};
use core::ptr;

use super::{NSArray, NSCopying, NSEnumerator, NSFastEnumeration, NSObject};
use crate::rc::{DefaultId, Id, Owned, Shared, SliceId};
use crate::{ClassType, __inner_extern_class, extern_methods, msg_send, msg_send_id, Message};
use objc2::rc::{DefaultId, Id, Owned, Shared, SliceId};
use objc2::{ClassType, __inner_extern_class, extern_methods, msg_send, msg_send_id, Message};

__inner_extern_class!(
#[derive(PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -162,8 +162,8 @@ mod tests {
use alloc::vec;

use super::*;
use crate::foundation::NSString;
use crate::rc::autoreleasepool;
use crate::Foundation::NSString;
use objc2::rc::autoreleasepool;

fn sample_dict(key: &str) -> Id<NSDictionary<NSString, NSObject>, Shared> {
let string = NSString::from_str(key);
Expand Down
Loading

0 comments on commit 47cd390

Please sign in to comment.