zed
zed copied to clipboard
Migrate Zed to objc2
Check for existing issues
- [X] Completed
Describe the feature
It seems like the ecoystem is moving towards using objc2 instead of objc as the latter is unmaintained. Doing so would probably allow us to drop media crate altogether (plus it'd be a win in terms of interacting with Mac platform code). It also seems like the latest version of Blade (0.6.0) is using objc2 as well (though we're not using that for our Mac build I think?) Related: https://github.com/zed-industries/zed/issues/17467
Zed Version and System Specs
Zed: v0.168.0 (Zed Nightly 564936e1fee313efcd4643c5e78472f6dc44ffc5) OS: macOS 15.1.0 Memory: 64 GiB Architecture: aarch64
If applicable, add mockups / screenshots to help present your vision of the feature
No response
I've recently completed moving Blade to objc2, since it was blocking my blade-graphics-0.6 release. Seems to be working well: there are zero instances of msg_send! left in code now!
Might be worth reconsidering for Zed to just switch to Blade on macOS and drop the metal-rs based graphics backend, to save time instead of porting it. I realize that it may require a few changes in the presentation, related to how it may need to be done in CoreAnimation transaction in some cases but not the others. Happy to help get them in!
The Zed on Blade Metal path is currently available via "gpui/macos-blade" feature, and the latest Blade uprev is coming in #22409.
With #30347 merged, we're now up to date with the latest objc2 when it comes to dependencies. If Zed is interested in this kind of work, I'd be willing to start working on moving from objc to the objc2-* crate family. If yes, it could be a good idea to create a TODO list or a roadmap of sorts for the migration.
I asked a question about this subject on discord but got no official response from anyone on the Zed team but some other contributors and I had a brief conversation about this subject so I thought it made more sense to file it here as part of this issue to keep track of whats going to happen moving forward.
gpui uses the metal crate which is deprecated.
There is a TODO note in gpui Cargo.toml to replace the metal crate with objc2
objc2 = { version = "0.6", optional = true }
objc2-metal = { version = "0.3", optional = true }
#TODO: replace with "objc2"
metal.workspace = true
Blade currently uses objc2 and objc2-metal in the Blade Renderer
Does it make sense to have this be on the roadmap prior to publishing out gpui to crates.io ?
This is fairly obvious from the above comments but Zed also has references to the cocoa crate which is also deprecated...
- https://crates.io/crates/cocoa
- https://docs.rs/cocoa/0.26.1/cocoa/
- https://github.com/servo/core-foundation-rs/pull/731
This is kind of going to be a show stopper when Zed does eventually publish out gpui as a stand alone crate
On one hand it would be great to land this change incrementally, but on the other there's a fundamental incompatibility between objc2 and objc types; hence, we'll probably have to do it in one go.. which is pretty time-consuming, error-prone and does not give us immediate returns. I started hacking on this last week, but I don't have high hopes of pushing it over the line in few days or whatever.
Yeah the medal renderer is likely something which will need to be migrated in one go. I’ve mostly been looking at the platform code which also used objc for almost everything.
I also took a go at moving the platform code to objc2 it a while back, there’s surprisingly much which can be done incrementally.
There are quite a few standalone functions which can be migrated independantly. There’s also a common pattern of accessing a macos global and changing a few settings, which yes will create functions which mix objc2 and objc (yuck) but might still make migration easier.
There are however some large custom gpui classes which will undeniably need more work and big PR’s aswell.
Considering we already pull in objc2 through blade I don’t think it’s far fetched to think we could take a shot at it. A lot of the API’s provided by objc2 are marked safe and are less error prone to work with than objc, which will certainly help with migration, but since platform and rendering code is such a critical component and testing being difficult, I can see why this needs to be done carefully.
The main benefit I see behind this is removing a considerable chunk of Zed’s unsafe code, which is always good.