I'm not really a windows user, but given the latest discussion on the rust subreddit, I thought I give using gtk4-rs on windows a try.
To set up my build environment, I followed this blog post:
That way, I successfully built and installed gtk4/master
. And I can launch gtk4-demo.
Building from the tag 4.3.0
didn't work for me, as the source of glib
couldn't be checked out.
In the blog above, things got installed to C:\GNOME
. I chose C:\GTK
instead, but the name doesn't really matter.
I wouldn't use spaces in the name, though.
After that, I've installed then rust/stable via rustup (from https://www.rust-lang.org/tools/install):
C:\Users\oleid\src\gtk4-rs>rustup show
Default host: x86_64-pc-windows-msvc
rustup home: C:\Users\leido\.rustup
stable-x86_64-pc-windows-msvc (default)
rustc 1.52.1 (9bc8c42bb 2021-05-09)
The next tool you need is pkg-config
. The build scripts of gtk-rs depend on it.
It would seem the following is a stripped-down version without extra dependencies. Less is more here, so I used it:
https://sourceforge.net/projects/pkgconfiglite/files/latest/download
All you need to to is to unpack it and add the executable to your system PATH
.
Or unpack it to somee folder which is already searched for executables.
To check if this worked, open x64 Native Tools Command Prompt for VS 2019 again and type:
C:\SomePath> pkg-config
Must specify package names on the command line
To test if things work, I used the gtk-rs souce. You could create a minimal example as well. If you'd like to build the examples from gtk-rs as I did, do the following:
C:\Users\oleid\src> git clone --recursive https://github.com/gtk-rs/gtk4-rs.git
C:\Users\oleid\src> cd gtk4-rs
When simply running cargo run --bin clock
compilation will fail. We need to tell the rust bindings where to look for the libraries.
Here, pkg-config comes into play. We need to tell pkg-config where to find the libraries we build before.
C:\Users\oleid\src\gtk4-rs>set PKG_CONFIG_PATH=C:\GTK\lib\pkgconfig
C:\Users\oleid\src\gtk4-rs>pkg-config --libs cairo
-LC:/GTK/lib -lcairo
Now the following command will work:
C:\Users\leido\src\gtk4-rs>cargo build --bin clock
When running, however, the system will complain that the libraries cannot be found.
We can change the path temporarily to make the system find its dependencies:
C:\Users\oleid\src\gtk4-rs>set PATH=%PATH%;C:\GTK\bin
C:\Users\oleid\src\gtk4-rs>cargo run --bin clock