objc2 icon indicating copy to clipboard operation
objc2 copied to clipboard

C-unwind and Rust 1.71.0

Open herabit opened this issue 2 years ago • 7 comments

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.

herabit avatar Dec 10 '23 07:12 herabit

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

madsmtm avatar Dec 10 '23 07:12 madsmtm

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

madsmtm avatar Dec 10 '23 07:12 madsmtm

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...

herabit avatar Dec 10 '23 08:12 herabit

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 :/

madsmtm avatar Mar 14 '24 15:03 madsmtm

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.

herabit avatar Mar 14 '24 20:03 herabit

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

madsmtm avatar Mar 14 '24 22:03 madsmtm

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 avatar Jun 02 '24 16:06 madsmtm

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 ;) .

madsmtm avatar Sep 05 '24 21:09 madsmtm

I have bumped MSRV to 1.71, and used C-unwind when it makes sense, will be released in the next version of objc2.

madsmtm avatar Sep 16 '24 12:09 madsmtm