6 ms·
Original Nautilus and early GNOME developer here. I am very out of touch with what is current, so excuse some possibly ignorant questions. How is this a Rust-ba
by diskzero 5y ago
Original Nautilus and early GNOME developer here. I am very out of touch with what is current, so excuse some possibly ignorant questions. How is this a Rust-based environment if it is based on GTK? I assume GTK is still essentially the C-based GTK we used with some improvements.
Why is this called Rust-based? I’ll do some more research but would like to get some insight from more knowledgeable sources.
- Narishma 5y agoGTK is just a library, you can use it from any language it has bindings for.
- diskzero 5y agoUnderstood. I have made significant contributions to GTK. My contributions possibly had memory leaks or memory corruption issues that will bring down the higher Rust layer. I am trying to understand the purpose of the Rust layer. It is fine with me if it is because Rust is interesting, but what is being presented doesn’t seem like a Rust desktop environment _to me_.
- IshKebab 5y agoIt's not 100% Rust but I think you would expect that GTK itself is fairly well tested - probably much better tested than any new app you write that uses it, so it is still worth it to write that app in Rust. And it has to be said that memory safety isn't Rust's only compelling feature. It also has a pretty great build system, a decent library ecosystem, a very strong type system which gives you an "if it compiles it works" experience surprisingly often, probably the best multithreading system, etc. etc.
- Taywee 5y agoThe big selling point of Rust in respect to these kinds of scenarios is that it's very often that a C or C++ library says things like "You must not call function CallAfterFoo before function Foo is called", or "Once you call DestroyObject, that object must not be used again", or "You must not call SomethingDangerous while a ResourceOwningObject exists", and so on and so on. In well-tested libraries like GTK, SQLite, Curl, and such, they are often quite robust just based on having been heavily developed and tested by many people over a very long time, and there are still ways that they can be misused and abused that are usually well-documented and warned against. A well-developed Rust wrapper actually makes it impossible to misuse one of these libraries from Rust, and therefore better enables a much smaller team of developers to write secure, robust applications. Rust can guarantee these documented restrictions at the type level and even make impossible many error conditions. So even though the UI is GTK, Rust still enables developers to write more robust applications with less fear. Personally, I find that GTK with Rust is a very pleasant experience. It's less about guaranteeing that the lower libraries have no bugs and more about preventing people from interacting with the libraries in dangerous or buggy ways.
- ranfdev 5y agoI've made some small contributions to gtk-rs-core (the library providing rust bindings to glib, gdk...). While the lower layers written in C do impact the overall safety, the bindings are made to be as safe as possible. For example: every glib parameter that may take NULL in Rust becomes an Option<T>. GObject's methods are defined on traits and checked by the Rust type system. There are also some macros to provide an easy and safe interface to the GLib type system. All of this directly applies to gtk-rs. Overall, the bindings are well documented and with many examples. There's even a book. Also, there's a great community around them. Bindings website: https://gtk-rs.org/ https://gtk-rs.org/
- pxc 5y agoI agree! I think they're just using Rust because they'd rather use it than C, not because they need safety guarantees for the DE applications.
- deleted 5y ago[deleted]
- jandrese 5y agoThe issue is that Rust is extremely opinionated at to how code should be structured and there is going to be considerable interface friction with a system that is built around aliasing data every time there is a callback.
- acdha 5y agoDo you have an example of that friction? Looking through the docs at e.g. https://gtk-rs.org/gtk4-rs/stable/latest/book/hello_world.html https://gtk-rs.org/gtk4-rs/stable/latest/book/hello_world.ht... it doesn't seem that bad but not having used it I would be curious how it works out once you're building a serious app.
- jandrese 5y agoThings are already getting quite hairy by page 4[1] of that link. And that example is showing data completely owned by the GObject. If you need to pass a mutable reference to third party data to a GObject it's not going to work in Rust. Imagine a button that you click to change the contents a GtkTreeModel connected to a GtkTreeView--you're going to need to work hard. You're going to write a fair bit Rust specific glue code to work around these issues. [1] https://gtk-rs.org/gtk4-rs/stable/latest/book/gobject_memory_management.html https://gtk-rs.org/gtk4-rs/stable/latest/book/gobject_memory...
- rollcat 5y agoAsking as someone who's never spent significant time/effort working with Gtk/GObject in C (only a bit in Python). Isn't it still generally desirable to have the compiler yell at you, if you can't convince it you know what you're doing? Rather than allowing the possibility of memory corruption. I do agree that the code in the example is far from beautiful. I wonder if we were to redesign GObject from scratch, if we could make interfacing with Python, Rust, JS, etc a bit less hairy.
- Someone 5y agoThe work you have to do to show your compiler that certain constraints hold (say that i and j point inside the same array and that i < j can be extremely cumbersome, even in cases where it’s obvious that they do hold. That makes it not seem worth the trouble. Of course, that obvious may turn out to be incorrect for some edge condition. Basically, that’s the same reason why mathematicians don’t put all proofs through a proof assistant.
- amarshall 5y agoThe answer seems to be that the applications [1] are written in Rust using gtk-rs [2] (Rust-bindings for the GTK libs). [1]: https://github.com/orgs/pop-os/repositories?q=&type=source&language=rust https://github.com/orgs/pop-os/repositories?q=&type=source&l... [2]: https://gtk-rs.org/ https://gtk-rs.org/
- mohanmcgeek 5y agoDoes this work similar to the python bindings that were ubiquitous a decade ago? My understanding is that you don't get any memory safety/performance advantage from using Rust because gtk can still be unsafe. Is this correct?
- ludston 5y agoEven Rust code can still be unsafe. It's a question of where it can be unsafe. You're reducing the scope of code that can be unsafe to specific areas.
- symlinkk 5y agoSo basically it’s not Rust.
- cowsandmilk 5y agoHow pure does your program have to be to be rust for you? How few libraries in C or C++ must it call? The developers are writing all their code in rust, so it is in rust…
- symlinkk 5y agoIt’s a UI library that’s showing UI controls that are written in C. It’s dishonest to call it Rust because it wraps those controls in a layer of Rust
- southerntofu 5y agoBy that standard no binary that links against glibc, whether originally written in rust or go, is in fact rust or go.
- sprash 5y agoAlso GTK4 means they are still at the mercy of GNOME which changes APIs often and without consideration for third parties. Wasn't the whole point of the project to emancipate themselves from GNOME? If they rely on GTK they will fail.
- cyber_kinetist 5y agoThen they would need to either 1) do the yak-shaving and create a whole new GUI stack in Rust (which would be an absolute boon to the Rust community but will be a tremendous effort), or 2) switch to Qt (and basically become KDE) Thinking about it, maybe Sciter (https://sciter.com/ https://sciter.com/) would be an okay foundation to build a DE in (lightweight stack, flexible theming, solid Rust bindings). But then it isn’t open source (only the interface is, you need to pay for source access), so maybe not.
- CameronNemo 5y agocreate a whole new GUI stack in Rust Is there a reason iced is not good enough (other than not being accessible)? https://iced.rs/ https://iced.rs/ https://github.com/iced-rs/iced/issues/552 https://github.com/iced-rs/iced/issues/552
- pure_simplicity 5y agoNo stable release yet, and you generally want your DE to be the most dependable bug-free part of your software, especially if you are selling hardware with your own software pre-installed. but looking good so far, gonna check this out for myself. I was rooting for azul, but iced seems to be further ahead
- gnud 5y agoI'm assuming Iced has no A11 support (these projects never do). Probably no RTL support. Possibly no reusable "system" widgets like open/save dialogs.
- 5y ago
- deleted 5y ago[deleted]
- mmstick76 5y agoDepends on what parts of the environment you're looking at. The compositor that's the basis of the entire environment will be written entirely in Rust, based on smithay. But applications written for COSMIC are currently based on GTK4. GTK is currently the best GUI toolkit for Rust application developers. It's the only toolkit that's fully functional with first class and official bindings. It's been pretty well endorsed by GNOME for most of their new applications lately. There are some Rust GUI toolkits out there that are shaping up, such as some former Qt developers actively developing sixtyfps, but it'll be a while before we have a GUI toolkit in the Rust space that's truly ready for complex application development.
- k_kalupe22 5y agoEasy, it's for advertising reasons. Devs, admins, enthusiasts etc. are the main target for Systems 76. Hackernews audience is very enthusiastic regarding Rust. I think it's indeed unfair to GTK.