There are a few recommended ways to set up your workstation in order to develop
Let us go through them one by one.
Cargo is Rust's build system and package manager. If following the book is all you care about, using only Cargo will work fine for you.
Now create a new project by executing:
cargo new my-gtk-app
Add the following lines to your
[dependencies.gtk] version = "0.1" package = "gtk4"
Now you can run your application by executing:
Cargo is nearly enough, but it is not well suited for handling resources such as icons or UI definition files. That is why we recommend to use Meson on top of it. It is cross-platform and its syntax is very readable. Meson takes care of
- building and installing resources
- installing auxiliary files such as icons and settings schemas
You can download a ready-to-use gtk-rust-template here. Follow the instructions in the README to initialize your own application. Then configure your project.
meson --prefix=/usr build
In order to compile and install it run the following commands. You have to execute it every time you modify your application.
ninja -C build && ninja -C build install
Now the application should be in a folder included in your system path. You can either start it with the application launcher of your choice or in the terminal.
If you develop on Linux, using Flatpak is the most convenient option. With Flatpak your whole workflow is containerized and your users get the very same application you develop on (including all dependencies). First, assure that Flatpak is installed on your system, check this website to see if any steps are necessary on your distribution. Then download the gtk-rust-template and follow the instructions in its README.
Then either install:
That is it. The build dependencies can be downloaded by the IDE. With GNOME Builder, you only have to press the run button for that.