Skip to content

Backend naming #4246

Closed
Closed

Description

@madsmtm

It has been bugging me for a long time that our backends are kinda wrongly named: They are named after the OS / platform that they target, instead of the API that they use.

This is a bit incorrect though, because a lot of APIs can be used on other platforms than their primary one. The most erregious case here is probably UIKit, which is used on three of Apple's platforms, mostly iOS, but increasingly visionOS and tvOS too. And with Mac Catalyst in recent times, it can even be used natively on macOS as well. Another example is that there exist projects like GNUStep that tries to bring AppKit to Linux platforms, and I think even Wayland can be used on macOS (?).

So many of the names in winit::platform::* are effectively false. I've tried to improve it a bit in #3756, but that only resolved the iOS/UIKit discrepancy - the Android backend, for example, should probably be called the NDK backend, as Android could technically run other backends as well (Wayland on Android any1?). Similarly, other platforms could target the NDK.

This becomes important now with #3433, since with that we'll kind of be locked into specific names (since we'll be releasing crates). So I've put this in the milestone to be figured out before the release.

See the table below for an overview of the naming scheme (with a few imaginary backends thrown in there for a broader context):

OS/Platform Backend / Actual API Name after platform Name after API
Android NDK winit-android winit-ndk
iOS/visionOS/tvOS/Mac Catalyst UIKit / Cocoa Touch winit-ios ? winit-uikit
macOS AppKit / Cocoa winit-macos winit-appkit
watchOS WatchKit winit-watchos winit-watchkit
Redox Orbital winit-redox winit-orbital
Many (predominantly unixes) Wayland ? winit-wayland
Many (predominantly unixes) X11 ? winit-x11
Web Web winit-web winit-web
Windows Win32 winit-windows winit-win32
Windows WinRT winit-windows winit-winrt
Many GTK ? winit-gtk
All Terminal ? winit-terminal
OpenHarmony / OHOS ? winit-ohos winit-?

Only problem is, clearly "Android", "iOS" and "macOS" are more discoverable and understandable terms than "NDK", "UIKit" and "AppKit". So maybe favouring consistency and correctness here is the wrong choice?

For a bit of prior art, GLFW uses "Cocoa", "Win32", "X11" and "Wayland" (API names). The SDL uses "Android", "Cocoa", "Windows", "Wayland", "UIKit" (bit of both). raw-window-handle uses API names.

Activity

  1. added this to the Version 0.31.0 milestone on May 21, 2025
  2. added
    S - api
    C - needs discussion
    on May 21, 2025
  3. kchibisov commented on May 21, 2025

    @kchibisov
    Member

    It has been bugging me for a long time that our backends are kinda wrongly named: They are named after the OS / platform that they target, instead of the API that they use.

    should be after the API in general, yes, naming with any other name doesn't make much sense.

  4. madsmtm commented on May 21, 2025

    @madsmtm
    MemberAuthor

    Do you have a preference between "Cocoa"/"Cocoa Touch" and "AppKit"/"UIKit"?

    Cocoa is kinda the legacy name, it's the union between the Foundation, AppKit and CoreData frameworks. I guess AppKit is more precise, since Cocoa refers to more things (e.g. the desktop environment itself). But on the other hand, StackOverflow has almost 40k questions tagged "cocoa", while only 1,5k tagged "appkit", so perhaps Cocoa might be more readily understood by users?

    I think my preference is AppKit, but maybe you/others have more insight?

  5. kchibisov commented on May 21, 2025

    @kchibisov
    Member

    I usually don't. AppKit/UiKit is more clear nowadays.

    I'm not sure about Android though, since if backend combines multiple providers then just android could be fine.

  6. madsmtm commented on May 21, 2025

    @madsmtm
    MemberAuthor

    @MarijnS95 what's your preference on Android backend naming? winit-ndk or winit-android?

  7. MarijnS95 commented on May 21, 2025

    @MarijnS95
    Member

    Naming the Android backend winit-ndk would imply limiting the backend to using just NDK primitives I think. I.e. that'd be the android-activity/native-activity backend/feature, somewhat ruling out android-activity/game-activity (which still utilizes a bunch of NDK primitives since they're wrappers over or underlying implementations of standard Android Java components). The latter is provided by a separate Android JetPack package that build systems need to pick up (IIRC).

    The android-activity crate abstracts both features behind a common interface (which also provides shared NDK wrapper objects and concepts). Perhaps winit-android-activity, or is that too long?

    At the same time a new android-view crate is currently being developed and perhaps proposed soon, which I don't know if it's going to replace "our Android winit backend" or just be a completely new one. Given that it's going to be a completely different approach with its own drawbacks and features, a separate backend seems preferable.

    Here's my amends to the table to represent this:

    OS/Platform Backend / Actual API Name after platform Name after API
    Android NativeActivity winit-android winit-(-android)-ndk
    Android GameActivity winit-android winit-agdk1?
    Android android-view winit-android 2?

    Footnotes

    1. https://developer.android.com/games/agdk ↩

    2. https://developer.android.com/reference/android/view/View ↩

  8. madsmtm commented on May 21, 2025

    @madsmtm
    MemberAuthor

    Hmm. android-view is also using the NDK, right? They're all just different activities?

    Given that it's going to be a completely different approach with its own drawbacks and features, a separate backend seems preferable.

    I guess I disagree with that comment, I'd like to avoid that we provide different Winit backends for what is essentially the same overarching APIs. So while I wouldn't say winit-android-activity is too long, it does seems to tie us to a specific crate, which I'd like to avoid. E.g. I didn't call the AppKit backend winit-objc2-app-kit.

    But maybe there are benefits here that I'm not yet seeing?

    CC @rib @mwcampbell, WDYT?

  9. MarijnS95 commented on May 21, 2025

    @MarijnS95
    Member

    Hmm. android-view is also using the NDK, right? They're all just different activities?

    Opening that repo, there's immediately some gradle files. Meanwhile, NDK -> Native Development Kit -> only Native (C) code/bindings that can be called from Rust, no complicated (Java-tailored) build systems needed.

    Besides that, the NDK doesn't have a View representation that I know of. Only the backing Surface but that's "limited" to rendering / presentation.

    However, I do think (and this was my 3+-year-old idea for a RustActivity) that any Java they need could possibly be precompiled and provided with the crate, leaving us to never need special/complicated build tools when I finally PR my "merge compiled Java-ish sources into a classes.dex and embed into the APK" branch to cargo-apk and xbuild.

    (I digress, let's immediately hide this comment as OT and move this yet-another-Android-backend-design-quest to a separate issue?)


    Calling it winit-android is preferable if we can merge all 3. At that point it's worth seeing if android-activity could be(come) the shared abstraction for all of them.

  10. madsmtm commented on May 21, 2025

    @madsmtm
    MemberAuthor

    Okay, let's go with winit-android then.

    I will move forwards with that, but until we do the actual release, we can always delete the crate again, and go with a different name.

  11. madsmtm commented on Jun 5, 2025

    @madsmtm
    MemberAuthor

    We discussed this in today's meeting, and decided that we're happy with the current naming (name after API, except for Android), so I'll close this for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C - needs discussionS - api

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions