Skip to content

Commit

Permalink
Add CoreFoundation framework
Browse files Browse the repository at this point in the history
Co-authored-by: samuelsleight <[email protected]>
Co-authored-by: silvanshade <[email protected]>
  • Loading branch information
3 people committed Dec 9, 2024
1 parent 3a565e0 commit b18750f
Show file tree
Hide file tree
Showing 62 changed files with 1,402 additions and 891 deletions.
26 changes: 13 additions & 13 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions Cargo.lock

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

10 changes: 4 additions & 6 deletions crates/header-translator/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ pub struct Config {
}

fn uses_system_config(library_name: &str) -> bool {
match library_name {
"System" | "bitflags" | "block2" | "libc" | "objc2" => true,
// Temporary
"CoreFoundation" => true,
_ => false,
}
matches!(
library_name,
"System" | "bitflags" | "block2" | "libc" | "objc2"
)
}

impl Config {
Expand Down
12 changes: 1 addition & 11 deletions crates/header-translator/src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ impl Location {
"block2" => LocationLibrary::Block2,
"libc" => LocationLibrary::Libc,
"objc2" => LocationLibrary::Objc2,
// Temporary
"CoreFoundation" => LocationLibrary::System,
library => {
if let Some(krate) = config.libraries.get(library).map(|lib| &*lib.krate) {
if library == emission_library {
Expand Down Expand Up @@ -242,19 +240,11 @@ impl<N: ToOptionString> ItemIdentifier<N> {
}

pub fn with_name(name: N, entity: &Entity<'_>, context: &Context<'_>) -> Self {
let mut location = context.get_location(entity).unwrap_or_else(|| {
let location = context.get_location(entity).unwrap_or_else(|| {
warn!(?entity, "ItemIdentifier from unknown header");
Location::from_components(vec!["__Unknown__".into()])
});

// TODO: Get rid of these hacks
if let Some("CGFloat" | "CGPoint" | "CGRect" | "CGSize") = name.to_option() {
location = Location::from_components(vec!["Foundation".into(), "NSGeometry".into()]);
}
if let Some("CFTimeInterval") = name.to_option() {
location = Location::from_components(vec!["System".into()]);
}

Self { name, location }
}

Expand Down
5 changes: 4 additions & 1 deletion crates/header-translator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,10 @@ fn update_ci(workspace_dir: &Path, config: &Config) -> io::Result<()> {
.as_ref()
.is_some_and(|v| VersionReq::parse("<=10.0").unwrap().matches(v))
})?;
writer(&mut ci, config, "FRAMEWORKS_GNUSTEP", |lib| lib.gnustep)?;
writer(&mut ci, config, "FRAMEWORKS_GNUSTEP", |lib| {
// HACK: CoreFoundation uses mach types that GNUStep doesn't support
lib.gnustep && lib.krate != "objc2-core-foundation"
})?;

write!(&mut ci, " # END AUTOMATICALLY GENERATED{after}")?;

Expand Down
1 change: 0 additions & 1 deletion crates/header-translator/system-config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class.NSObject.methods.release.skipped = true

# TODO: Move these
# `ns_consumed`, `cf_consumed` and `os_consumed`
fn.CFAutorelease.skipped = true
fn.IOServiceGetMatchingService.skipped = true
fn.IOServiceGetMatchingServices.skipped = true
fn.IOServiceAddMatchingNotification.skipped = true
Expand Down
4 changes: 3 additions & 1 deletion crates/objc2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,14 @@ iai = { version = "0.1", git = "https://github.com/madsmtm/iai", branch = "callg
static_assertions = "1.1.0"
memoffset = "0.9.0"
block2 = { path = "../block2", default-features = false }
objc2-core-foundation = { path = "../../framework-crates/objc2-core-foundation", default-features = false, features = [
"CFCGTypes",
] }
objc2-foundation = { path = "../../framework-crates/objc2-foundation", default-features = false, features = [
"NSArray",
"NSDate",
"NSDictionary",
"NSEnumerator",
"NSGeometry",
"NSKeyValueObserving",
"NSNotification",
"NSObject",
Expand Down
2 changes: 1 addition & 1 deletion crates/objc2/src/top_level_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ pub unsafe trait MainThreadOnly: private::SealedMainThreadOnly {
/// use objc2::{MainThreadOnly, MainThreadMarker};
/// # #[cfg(available_in_app_kit)]
/// use objc2_app_kit::NSView;
/// use objc2_foundation::CGRect;
/// use objc2_core_foundation::CGRect;
/// #
/// # use objc2::rc::{Allocated, Retained};
/// #
Expand Down
1 change: 1 addition & 0 deletions crates/objc2/src/topics/about_generated/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
querying the underlying data.
* Added new framework crates:
- `ScreenSaver` / `objc2-screen-saver`.
- `CoreFoundation` / `objc2-core-foundation`.

### Changed
* Allow using `MainThreadBound` without the `NSThread` feature flag.
Expand Down
1 change: 1 addition & 0 deletions crates/objc2/src/topics/about_generated/list_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
| `ContactsUI` | [![`objc2-contacts-ui`](https://badgen.net/crates/v/objc2-contacts-ui)](https://crates.io/crates/objc2-contacts-ui) | [![docs.rs](https://docs.rs/objc2-contacts-ui/badge.svg)](https://docs.rs/objc2-contacts-ui/) |
| `CoreBluetooth` | [![`objc2-core-bluetooth`](https://badgen.net/crates/v/objc2-core-bluetooth)](https://crates.io/crates/objc2-core-bluetooth) | [![docs.rs](https://docs.rs/objc2-core-bluetooth/badge.svg)](https://docs.rs/objc2-core-bluetooth/) |
| `CoreData` | [![`objc2-core-data`](https://badgen.net/crates/v/objc2-core-data)](https://crates.io/crates/objc2-core-data) | [![docs.rs](https://docs.rs/objc2-core-data/badge.svg)](https://docs.rs/objc2-core-data/) |
| `CoreFoundation` | [![`objc2-core-foundation`](https://badgen.net/crates/v/objc2-core-foundation)](https://crates.io/crates/objc2-core-foundation) | [![docs.rs](https://docs.rs/objc2-core-foundation/badge.svg)](https://docs.rs/objc2-core-foundation/) |
| `CoreImage` | [![`objc2-core-image`](https://badgen.net/crates/v/objc2-core-image)](https://crates.io/crates/objc2-core-image) | [![docs.rs](https://docs.rs/objc2-core-image/badge.svg)](https://docs.rs/objc2-core-image/) |
| `CoreLocation` | [![`objc2-core-location`](https://badgen.net/crates/v/objc2-core-location)](https://crates.io/crates/objc2-core-location) | [![docs.rs](https://docs.rs/objc2-core-location/badge.svg)](https://docs.rs/objc2-core-location/) |
| `CoreML` | [![`objc2-core-ml`](https://badgen.net/crates/v/objc2-core-ml)](https://crates.io/crates/objc2-core-ml) | [![docs.rs](https://docs.rs/objc2-core-ml/badge.svg)](https://docs.rs/objc2-core-ml/) |
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Interop with `core-foundation`-like crates
# Interop with other crates

The `objc2` project does not [yet](https://github.com/madsmtm/objc2/issues/556) provide bindings to CoreFoundation and similar frameworks.
The `objc2` project may not provide bindings for all frameworks, so in certain cases you may need to use existing crates like [`core-foundation`], [`core-graphics`], [`security-framework`], [`system-configuration`] and so on to interact with a given framework.

To interact with these, you will have to use existing crates like [`core-foundation`], [`core-graphics`], [`security-framework`], [`system-configuration`] and so on.

This can, however, pose a bit of an issue, since `objc2` and [`block2`] impose certain requirements on the types involved.
This can pose a bit of an issue, since `objc2` and [`block2`] impose certain requirements on the types involved.

[`core-foundation`]: https://crates.io/crates/core-foundation
[`core-graphics`]: https://crates.io/crates/core-graphics
Expand Down
4 changes: 2 additions & 2 deletions crates/objc2/src/topics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ pub mod about_generated;
#[doc = include_str!("alternatives.md")]
pub mod alternatives {}
#[cfg(not(feature = "gnustep-1-7"))]
#[doc = include_str!("core_foundation_interop.md")]
pub mod core_foundation_interop {}
#[doc = include_str!("crate_interop.md")]
pub mod crate_interop {}
#[doc = include_str!("kvo.md")]
pub mod kvo {}
#[doc = include_str!("layered_safety.md")]
Expand Down
Loading

0 comments on commit b18750f

Please sign in to comment.