madsmtm / objc2

Bindings to Apple's frameworks in Rust
https://docs.rs/objc2/
MIT License
338 stars 39 forks source link

C-unwind and Rust 1.71.0 #539

Open herabit opened 9 months ago

herabit commented 9 months ago

Rust 1.71.0 stabilizes (at least partially) C-unwinding. However, due to issues with the feature attribute's usage on stable, one is unable to utilize C-unwind on Rust 1.71.0+, despite it being available, when on stable.

There should be some kind of additional conditional compilation code to handle these versions, while still maintaining the current MSRV of 0.60.0. I'm trying to figure out how myself rn, hence my fork.

madsmtm commented 9 months ago

If we just remove the #![feature(c_unwind)], then it should compile on stable, no?

madsmtm commented 9 months ago

Though actually making extern "C-unwind" sound will take more effort, since Rust panics and Objective-C exceptions are not compatible.

herabit commented 9 months ago

Yeah this is kind of annoying when I'm trying to make Rust cocoa wrappers that, are Rusty, and, safe. I wonder if there's any way to bridge this incompatibility...

madsmtm commented 6 months ago

Given that https://github.com/rust-lang/rust/issues/115285 is FCP, this is now becoming a bit more important.

Unfortunately, I can't really raise the MSRV for objc2 to 1.71.0 yet, as Winit's MSRV is still at 1.70.0 :/

herabit commented 6 months ago

It could, at least in the short term be an opt-in feature, or perhaps enabled only on newer rust versions with a crate such as rustversion, which, well allows conditional compilation based upon whatever version of rustc you're compiling for. It may be worth taking a look at, though, in the short term it may complicate maintainability, and anger some folk due to the additional dependency. A build script may be able to provide similar functionality, though, again with potential issues pertaining to maintainability, as managing a lot of conditional compilation can, really be a pain in the ass.

madsmtm commented 6 months ago

Yeah. I think the easier solution might be to allow a bump to Winit's Rust version on macOS only.

madsmtm commented 3 months ago

In bbf81aca542d6ae50fc1474fccd8783be993ae61 and fc7e6e2ba229b71fcf58d23d50d2df88b8b63ee2 I've improved upon this by making the (still unstable) feature available in block2, and by removing #![feature(c_unwind)].

madsmtm commented 1 week ago

Rust is deciding to let catching foreign unwinding (like Objective-C exceptions) in "C-unwind" be defined behaviour, see https://github.com/rust-lang/rust/pull/128321 and https://github.com/rust-lang/reference/pull/1226. With that, things are trivial to make safe, so I'll probably be bumping MSRV to 1.71 soon, and justify it as a soundness fix if anyone complains ;) .