-
-
Notifications
You must be signed in to change notification settings - Fork 80
Gir tutorial #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gir tutorial #108
Conversation
@GuillaumeGomez Thanks, this tutorial is very good. |
@EPashkin Thanks for you feedbacks! I'll see the error you spotted! |
In this tutorial, we'll see how to generate a GNOME library using the [gir] crate. A few things to note first: | ||
|
||
* It only works on GObject-based libraries. | ||
* You need `.gir` files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a link to https://gi.readthedocs.io/en/latest/ ?
|
||
We now have the list of all the non-yet generated items. Quite convenient! | ||
|
||
Let's start by generating one type. Let's update the "generate" array as follows: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we select the first type we want to generate? It's useful to know how the library works, you ideally select the most independent and basic type. Something that does not depend on any other things that you didn't generate yet as far as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and no. In my case, I just pick one completely randomly and here we go. If you want to "enforce" it, I can add it, but this isn't relevant enough from my point of view.
|
||
This macro comes from the `glib` crate. We didn't import it, therefore the Rust compiler can't find it. We'll also need its `sys` part (the case of `glib` is a bit special). | ||
|
||
Another issue that will arise is that we didn't import the `sourceview-sys` crate either. Alongside those two (three if we count `glib-sys`!), we'll need both `libc` and `bitflags`. Let's fix all of those issues at once! For that, we need to update the `Cargo.toml`: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need libc and bitflags yet though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True but we'll need them anyway sooooo. :p
|
||
```rust | ||
#[macro_use] | ||
extern crate glib; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to do this Rust 2018 edition style already? The macro imports and all that are 2015 edition currently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can update the tutorial later on. For now, we didn't made the upgrade so it wouldn't make sense.
docs-src/tutorial/gir_tutorial.md
Outdated
> cargo build | ||
``` | ||
|
||
It worked! We have generated the `Language` item! I'll let you take a look at the `src/auto/language.rs` file for the interested ones, then we can continue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mention that there can be commented out things and why that could happen and what to do then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also this could still fail to compile for a different library... if gir generates broken code or we simply don't support this case yet. And then people should talk to us :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I come back on the commented things later on. But I'll say something about broken generation here (again :p).
Looks great generally, thanks for working on this :) And feel free to ignore any comments of mine if you disagree, it's all minor stuff |
7323e55
to
f98c89b
Compare
Thanks everyone for your feedbacks and reviews! |
I'll need gtk-rs/gir#755 to be merged first.
cc @EPashkin @sdroege