Okay, if you are reading this, you may (probably) have been searching for something like "rust gtk getting started" on Google. Most of them points to another awesome guides such as here.
Why GTK, you ask? At the time of writing:
- Azul is still in alpha. And the output binary is too large (5MB for a simple HelloWorld app).
- Iced is in 0.1 (it's good still, I may create a new writeup for this later).
- gtk-rs is complete and stable already.
Trust me, I had a hellish time with stuff like Cmake, MSYS, MinGW,... on Windows. No, I don't hate them, but there was a time when the term "A software distribution and building platform on Windows" doesn't make sense to me. I just... don't get it at all.
But I know I have to, eventually. And there it is! I bumped into this article via Google and I realized something I should a long time ago:
- Msys / Msys2 / MSVC,... they are the name of "toolchains", a collection of software to get something (mostly app development) done. Microsoft provides Visual Studio and Visual Studio Build Tools (which we might know as MSVC), it's great. And yes, it's locked into Windows ecosystem. But if you're interested in cross-platform development (like me), then you will want Msys2 and its fabulous GNU toolchain. It consists of 3
subsystems, from the
The mingw subsystems provide native Windows programs and are the main focus of the project. These programs are built to co-operate well with other Windows programs, independently of the other subsystems. This part builds on the MinGW-w64 project.
msys2subsystem provides an emulated mostly-POSIX-compliant environment for building software, package management, and shell scripting. These programs live in a virtual single-root filesystem (the root is the MSYS2 installation directory). Some effort is made to have the programs work well with native Windows programs, but it's not seamless. This part builds on the Cygwin project.
Each of the subsystems provides its own native (i.e. target=host) compiler toolchain, in
mingw-w64-x86_64-toolchain. There are also cross compiler toolchains with
mingw-w64-cross-toolchain, but these are of limited use because there are no library packages for them.
The best way is to follow official instruction. If you are on Windows (probably, because that's why you are reading this post), you'd better go with downloading
rust-init.exe (64-bit version).
After installing, check your rust installation with:
To update Rust itself, use:
Yes, this is the most important part. Simply use this command:
Because gtk-rs doesn't support MSVC toolchain yet, you will bump into several problems if you forgot to add that target. Then use this command to show current targets:
You will see something like this:
To switch to GNU toolchain, use this:
First, grab the installer here
Then set these environment variables. You can see it by right-clicking on "This PC" > Properties > Advanced System Settings
Next, use following commands in
MSYS Shell (NOT
Command Prompt or
By this way, MSYS will download necessary toolchain to compile GTK apps, then our project will be able to find it by looking up the environment variables.
If there are missing dependencies, you can easily install them by using MSYS Shell with
pacman. This command can cover most of them (including
Now it's on, you should be able to get GTK app up and running. Please kepe in mind that gtk-rs is not supporting MSVC at the moment. Track the issue here.