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

Add objc_sys crate #19

Merged
merged 36 commits into from
Sep 8, 2021
Merged

Add objc_sys crate #19

merged 36 commits into from
Sep 8, 2021

Conversation

madsmtm
Copy link
Owner

@madsmtm madsmtm commented Sep 2, 2021

Adds a new crate called objc_sys, which is like the old objc::runtime but only containing raw bindings, making it usable by other libraries like fruity.

Because it has the links key in Cargo.toml, it's now possible for downstream users to customize the linking to libobjc, see the cargo section on Overriding Build Scripts.

To create these bindings I've used bindgen to help me out, though I've had to modify them a lot manually because I wanted to have better *const vs. *mut pointer declarations (and had to ensure that the bindings were available on previous libobjc versions).
The fact that Apple has put their libobjc as open source has been really helpful. See their website and my git mirror.

TODO:

  • All the initial moving and bindgen stuff
  • Verify GNUStep support. See also the discussion in Add support for the GNUstep Objective-C runtime SSheldon/rust-objc#27
  • Check GCC headers through. We're not gonna be supporting that since it doesn't have ARC.
  • Document targeted versions:
    • macOS 10.7
    • iOS 5.0
    • tvOS 9.0
    • watchOS 1.0
    • bridgeOS 2.0
  • Link to other Objective-C runtimes
  • In general document objc_sys
  • Look through objc-abi.h and add missing symbols
  • Add feature to vendor GNUStep's libobjc2? Postponed, see README.
  • Differentiate between ABI and runtime? Not that important in documentation.
  • Set up cc compilers (clang, gcc, ...?) to use the correct runtime. Postponed, see README.
  • Add objc_block_sys crate. Postponed

Types:
- Imp -> IMP
- Object -> objc_object
- Sel -> objc_selector
- Protocol -> objc_protocol
- Class -> objc_class
- Ivar -> objc_ivar
- Method -> objc_method

New type aliases:
- id
- SEL
- Class
- Ivar
- Method
- Protocol (alias of objc_protocol, not a pointer)
Makes it possible to assign which pointers are mutable and which are immutable.
Also remove redundant (the original) function definitions
Makes it possible for downstream users to customize the linking to libobjc, see https://doc.rust-lang.org/cargo/reference/build-scripts.html#overriding-build-scripts
@madsmtm madsmtm changed the title WIP: -sys crates objc_sys crate Sep 5, 2021
This is the lowest version we'll target because they added support for the `objc_msgSend` family of functions which we might want to use (instead of the current `objc_msg_lookup`). Alternatively we could have chosen v1.6, but they're both from 2013 so it's kinda moot at this point. v1.5 is missing lots of functionality.

Commit gnustep/libobjc2@50a797f
This can be used to see the main differences in the objc API from v1.7 to v2.1; in essence, the API we'll be using haven't actually changed!

Commit gnustep/libobjc2@282486d
Also add objc_retainAutoreleaseReturnValue that I missed in 052bcd6
Probably all of the underlying APIs can handle NULL values, so not having this possibility is restricting.

And most of them can sometimes _return_ a NULL value, so not handling that is unsound!
@madsmtm madsmtm force-pushed the sys-crates branch 3 times, most recently from d48774a to 85254d8 Compare September 6, 2021 07:08
It's unclear how much these are part of the ABI stability, and whether they're actually useful
@madsmtm madsmtm changed the title objc_sys crate Add objc_sys crate Sep 7, 2021
@madsmtm
Copy link
Owner Author

madsmtm commented Sep 8, 2021

Wow, this took wayyy longer to make than the few hours I had anticipated!

@madsmtm madsmtm merged commit 8d49116 into master Sep 8, 2021
@madsmtm madsmtm deleted the sys-crates branch September 8, 2021 09:21
@madsmtm madsmtm mentioned this pull request Dec 21, 2021
@madsmtm madsmtm added this to the objc2 v0.3 milestone Apr 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant