Hello everyone.
I want to learn Rust and GTK (4), but before I can do so, I need to set up my environment, which I’m unfortunately having trouble with.
In the Flatpaked version of IntelliJ IDEA Community Edition (and, if I remember correctly, the upstream-archive version too), I try using the following Cargo.toml file along with the rust-stable (1.60.0) runtime from Flathub (the org.freedesktop.Sdk.Extension.rust-stable Flatpak package which installs into /var/lib/flatpak/runtime/org.freedesktop.Sdk.Extension.rust-stable) and the Gnome SDK, which seems to include GTK 4 (the org.gnome.Sdk Flatpak package which installs in /var/lib/flatpak/runtime/org.gnome.Sdk/x86_64/42/active/files/).
Contents of Cargo.toml:
[package]
name = "untitled3"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
gtk4 = "0.4.7"
cairo-sys-rs = "0.15.1"
glib-sys = "0.15.10"
gobject-sys = "0.15.10"
gio-sys = "0.15.10"[/code]
Here ( crates.io: Rust Package Registry ) is the Cargo crate I am using.
When I create a Rust project, I put “/var/lib/flatpak/runtime/org.freedesktop.Sdk.Extension.rust-stable/x86_64/21.08/active/files/bin” (without the quotes) as the “toolchain” and “/var/lib/flatpak/runtime/org.freedesktop.Sdk.Extension.rust-stable/x86_64/21.08/active/files/lib/rustlib/src/rust” (without the quotes) for the “standard library” part and choose Binary (application) for the Project Template.
At least the “toolchain” part seems to be correctly detected (because the IDE reports the version number 1.60.0).
I set the environment variables as follows (in the IDE, by clicking Run → Edit Configurations and going to Environment variables section - some of the following paths may be extraneous or invalid - I’ll look into that later).:
PKG_CONFIG_PATH=/var/lib/flatpak/runtime/org.gnome.Sdk/x86_64/42/active/files/lib/x86_64-linux-gnu/pkgconfig/;PATH=/var/lib/flatpak/runtime/org.gnome.Sdk/x86_64/42/active/files/sbin:/var/run/host/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/:/var/run/host/usr/bin:/var/lib/flatpak/runtime/org.gnome.Sdk/x86_64/42/active/files/lib/x86_64-linux-gnu/pkgconfig/:/var/lib/flatpak/runtime/org.freedesktop.Sdk.Extension.rust-stable/x86_64/21.08/active/files/bin/:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
The command-line-interface equivalent is as follows.:
cd ~/IdeaProjects/untitled3 && export PATH=/var/lib/flatpak/runtime/org.gnome.Sdk/x86_64/42/active/files/sbin:/var/run/host/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/:/var/run/host/usr/bin:/var/lib/flatpak/runtime/org.gnome.Sdk/x86_64/42/active/files/lib/x86_64-linux-gnu/pkgconfig/:/var/lib/flatpak/runtime/org.freedesktop.Sdk.Extension.rust-stable/x86_64/21.08/active/files/bin/:$PATH && export PKG_CONFIG_PATH=/var/lib/flatpak/runtime/org.gnome.Sdk/x86_64/42/active/files/lib/x86_64-linux-gnu/pkgconfig/ && cargo build && cargo run
The following is the output when I do it the GUI/IDE way.:
/var/lib/flatpak/runtime/org.freedesktop.Sdk.Extension.rust-stable/x86_64/21.08/active/files/bin/cargo build --color=always --message-format=json-diagnostic-rendered-ansi --package untitled3 --bin untitled3
Compiling glib-sys v0.15.10
Compiling gobject-sys v0.15.10
Compiling gio-sys v0.15.10
Compiling pango-sys v0.15.10
Compiling cairo-sys-rs v0.15.1
Compiling gdk-pixbuf-sys v0.15.10
Compiling gdk4-sys v0.4.2
Compiling graphene-sys v0.15.10
Compiling gsk4-sys v0.4.2
Compiling gtk4-sys v0.4.5
Compiling glib v0.15.11
Compiling gio v0.15.11
Compiling cairo-rs v0.15.11
Compiling pango v0.15.10
Compiling graphene-rs v0.15.1
Compiling gdk-pixbuf v0.15.11
Compiling gdk4 v0.4.7
Compiling gsk4 v0.4.7
Compiling gtk4 v0.4.7
Compiling untitled3 v0.1.0 (/home/user/IdeaProjects/untitled3)
warning: function is never used: `main`
--> src/main.rs:8:8
|
8 | fn main() {
| ^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: 1 warning emitted
Finished dev [unoptimized + debuginfo] target(s) in 1m 16s
Process finished with exit code 0
The following is when I do it via the command line (within the Flatpaked IDE).:
user@debian:~/IdeaProjects/untitled3$ cd ~/IdeaProjects/untitled3 && export PATH=/var/lib/flatpak/runtime/org.gnome.Sdk/x86_64/42/active/files/sbin:/var/run/host/usr/lib/gcc/x86_64-unknown-linux-gnu/11.3.0/../../../../x86_64-unknown-linux-gnu/bin/:/var/run/host/usr/bin:/var/lib/flatpak/runtime/org.gnome.Sdk/x86_64/42/active/files/lib/x86_64-linux-gnu/pkgconfig/:/var/lib/flatpak/runtime/org.freedesktop.Sdk.Extension.rust-stable/x86_64/21.08/active/files/bin/:$PATH && export PKG_CONFIG_PATH=/var/lib/flatpak/runtime/org.gnome.Sdk/x86_64/42/active/files/lib/x86_64-linux-gnu/pkgconfig/ && cargo build && cargo run
warning: function is never used: `main`
--> src/main.rs:8:8
|
8 | fn main() {
| ^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: `untitled3` (bin "untitled3") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
warning: function is never used: `main`
--> src/main.rs:8:8
|
8 | fn main() {
| ^^^^
|
= note: `#[warn(dead_code)]` on by default
warning: `untitled3` (bin "untitled3") generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.04s
Running `target/debug/untitled3`
Hello, world!
Goodbye, world!
user@debian:~/IdeaProjects/untitled3$
Here is the main.rs file’s contents.:
fn main() {
println!("Hello, world!");
use gtk4 as gtk;
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow};
fn main() {
let app = Application::builder()
.application_id("org.example.HelloWorld")
.build();
app.connect_activate(|app| {
// We create the main window.
let window = ApplicationWindow::builder()
.application(app)
.default_width(320)
.default_height(200)
.title("Hello, World!")
.build();
// Show the window.
window.show();
});
app.run();
}
println!("Goodbye, world!");
}
Here is my folder+project structure.:
user@debian:~/IdeaProjects/untitled3$ ls -a
. .. Cargo.lock Cargo.toml .git .gitignore .idea src target untitled3.iml
user@debian:~/IdeaProjects/untitled3$ ls -a ./src/
. .. main.rs
user@debian:~/IdeaProjects/untitled3$
Either way no windows pops up. Is this normal? Am I doing something wrong? How do I fix this problem?
Could someone please help me get this working correctly?
Any input would be GREATLY appreciated!
P.S.
The formatting of my post seems off, but I don’t know the correct syntax to fix things for that. If someone could let me know what the correct syntax is, I can fix my post (and use the syntax correctly for any potential future posts here).