Skip to content

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

Merged
merged 2 commits into from
May 12, 2019
Merged

Gir tutorial #108

merged 2 commits into from
May 12, 2019

Conversation

GuillaumeGomez
Copy link
Member

I'll need gtk-rs/gir#755 to be merged first.

cc @EPashkin @sdroege

@EPashkin
Copy link
Member

@GuillaumeGomez Thanks, this tutorial is very good.

@GuillaumeGomez
Copy link
Member Author

@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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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:
Copy link
Member

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.

Copy link
Member Author

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`:
Copy link
Member

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

Copy link
Member Author

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;
Copy link
Member

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

Copy link
Member Author

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.

> 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.
Copy link
Member

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

Copy link
Member

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 :)

Copy link
Member Author

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).

@sdroege
Copy link
Member

sdroege commented May 10, 2019

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

@GuillaumeGomez
Copy link
Member Author

Thanks everyone for your feedbacks and reviews!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants