4 releases

0.2.0 Apr 4, 2023
0.1.2 Mar 28, 2023
0.1.1 Mar 26, 2023
0.1.0 Mar 26, 2023

#820 in Hardware support


Used in lemna-wx-rs

MIT license

53KB
1.5K SLoC

Rust 899 SLoC // 0.0% comments C++ 551 SLoC // 0.0% comments

wx-rs

Crates.io Docs.rs

This is an alpha release. Don't expect much from me.

Only builds on the MSVC toolchain right now

An extremely partial set of bindings to wxWidgets, for Rust. The intent is that you can import this and all the bits of wxWidgets provided are statically linked in. Implements HasRawWindowHandle. Callbacks are used for rendering and event handling. Features:

  • Window initialization
  • Keyboard, mouse events
  • Clipboard support
  • Native menus
  • Cursor selection

Some things that'd be great to have:

  • The build script has only been tested on MSVC. Previously I've gotten this to compile on OSX and Windows with the GNU toolchain. There's no reason why this can't work on Linux as well.
  • Icon support for Windows/Linux

Building

The approach this crate takes is to download wxWidgets into the ./dist directory, then build it. This means that you need to have a toolchain capable of compiling wxWidgets.

Why are we doing this instead of using submodules? Because with submodules cargo would naturally check out files, but this isn't desirable since we want cargo to ignore these files when packaging (because wxWidgets is huge: The package, when you trim out all non-source files is still around 100MB).

Why do we save/compile to dist rather than cargo's preferred OUT_DIR? Because with the latter, we'd have to recompile wxWidgets more frequently. Since it takes quite a while to do so, it's much nicer to only have to compile once and then have the artifact around forever.

If you want to do a fresh install, just rm -R ./dist.

Building wxWidgets

Windows

Using the MSVC toolchain

Make sure you're using ""x64 Native Tools Command Prompt for VS 2019"", and that cargo is in your path when compiling for the first time. After it's built, msys works fine to continue building things from the Rust side.

Using the GNU toolchain on Windows

This depends on nightly rust to build correctly

Getting MSYS2

https://www.msys2.org/

$ pacman -Syu
$ pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-libexpat mingw-w64-x86_64-zlib msys2-w32api-runtime pacman -S mingw-w64-x86_64-lld

Building

This is a note of what needs to be integrated into the build script.

In a MSYS2 MinGW64 terminal:

$ cd dist/wxWidgets
$ mkdir msw64-release-build
$ ../configure --with-opengl --disable-shared
$ make -j20

Using the OSX toolchain

... why aren't I documented? :(

Dependencies

~0.1–2.2MB
~36K SLoC