Skip to content

Split Winit up into multiple crates #3433

@madsmtm

Description

@madsmtm

Part of #3367, opening to discuss separately.

Winit is designed around a single crate with a specific set of backends, which is great for users that can use that, but there is a need for other backends that are not implemented in Winit today, like GTK. Additionally, the backend-specific extensions that we do have usually constrain some other part of the design.

So it would probably be useful to try to split Winit into multiple smaller crates (though still in the same repository), to ease doing this work. The top-level winit crate would still remain.

Along with this, we'd want a way to write out-of-tree backends, and allow the user to integrate them into their application. This could probably be solved by introducing internal / "backend" traits, and keep a dyn in structures inside the winit crate.

A rough implementation plan could be:

  • Create a winit-core crate, which contains the common types that all backends use (like dpi and keyboard types)
  • Make traits in winit-core, that implements the desired functionality, and move each backend to also implement those traits.
  • Move the main winit crate to an API that is not cfg-based, but dyn Trait-based.
  • Introduce a winit-common crate to have shared functionality between the crates, which will be intended for winit internal usage and help writing new backends.
  • Move the backends out into separate crates, which all depend on winit-core, but still have the main winit crate "merge" these backends with cfgs, not with a trait.

@kchibisov: I've tried to fairly faithfully reproduce what I felt was the important points from #3367, but please edit this issue description with your own.

EDIT: Implementation history:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions